This adds a function to compare timestamps and then uses it as callback for qsort() before printing out tags.
Unified · Split
| @@ -10,6 +10,23 @@ · 9 unmodified lines | ||
| 10 | 10 | |
| 11 | 11 | static int header; |
| 12 | 12 | |
| 13 | +static int cmp_tag_age(void *a, void *b) | |
| 14 | +{ | |
| 15 | + struct refinfo *r1 = *(struct refinfo **)a; | |
| 16 | + struct refinfo *r2 = *(struct refinfo **)b; | |
| 17 | + | |
| 18 | + if (r1->tag->tagger_date != 0 && r2->tag->tagger_date != 0) | |
| 19 | + return r2->tag->tagger_date - r1->tag->tagger_date; | |
| 20 | + | |
| 21 | + if (r1->tag->tagger_date == 0 && r2->tag->tagger_date == 0) | |
| 22 | + return 0; | |
| 23 | + | |
| 24 | + if (r1 == 0) | |
| 25 | + return +1; | |
| 26 | + | |
| 27 | + return -1; | |
| 28 | +} | |
| 29 | + | |
| 13 | 30 | static void cgit_print_branch(struct refinfo *ref) |
| 14 | 31 | { |
| 15 | 32 | struct commit *commit; |
| @@ -156,6 +173,7 @@ static void cgit_print_tags() · 140 unmodified lines | ||
| 156 | 173 | for_each_tag_ref(cgit_refs_cb, &list); |
| 157 | 174 | if (list.count == 0) |
| 158 | 175 | return; |
| 176 | + qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); | |
| 159 | 177 | print_tag_header(); |
| 160 | 178 | for(i=0; i<list.count; i++) |
| 161 | 179 | print_tag(list.refs[i]); |