summaryrefslogtreecommitdiffabout
path: root/ui-summary.c
authorLars Hjemli <hjemli@gmail.com>2007-10-25 18:33:04 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-10-27 08:53:19 (UTC)
commitef1cc6ef941cedf2e34fa1ed34ca8cd8a0cfdacc (patch) (side-by-side diff)
tree5c9d40e556a5787e9338bc506dec37360f54d8f5 /ui-summary.c
parent502d71072a813e6fadb2e59fb47c2782b542674a (diff)
downloadcgit-ef1cc6ef941cedf2e34fa1ed34ca8cd8a0cfdacc.zip
cgit-ef1cc6ef941cedf2e34fa1ed34ca8cd8a0cfdacc.tar.gz
cgit-ef1cc6ef941cedf2e34fa1ed34ca8cd8a0cfdacc.tar.bz2
Sort tags by age
This adds a function to compare timestamps and then uses it as callback for qsort() before printing out tags. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-summary.c') (more/less context) (show whitespace changes)
-rw-r--r--ui-summary.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/ui-summary.c b/ui-summary.c
index c684628..43582da 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -7,12 +7,29 @@
*/
#include "cgit.h"
static int header;
+static int cmp_tag_age(void *a, void *b)
+{
+ struct refinfo *r1 = *(struct refinfo **)a;
+ struct refinfo *r2 = *(struct refinfo **)b;
+
+ if (r1->tag->tagger_date != 0 && r2->tag->tagger_date != 0)
+ return r2->tag->tagger_date - r1->tag->tagger_date;
+
+ if (r1->tag->tagger_date == 0 && r2->tag->tagger_date == 0)
+ return 0;
+
+ if (r1 == 0)
+ return +1;
+
+ return -1;
+}
+
static void cgit_print_branch(struct refinfo *ref)
{
struct commit *commit;
struct commitinfo *info;
char *name = (char *)ref->refname;
@@ -153,12 +170,13 @@ static void cgit_print_tags()
header = 0;
list.refs = NULL;
list.alloc = list.count = 0;
for_each_tag_ref(cgit_refs_cb, &list);
if (list.count == 0)
return;
+ qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age);
print_tag_header();
for(i=0; i<list.count; i++)
print_tag(list.refs[i]);
}
static void cgit_print_archives()