]> gitweb.ps.run Git - ps-cgit/blobdiff - ui-summary.c
Move logic for age comparision from cmp_tag_age into cmp_age()
[ps-cgit] / ui-summary.c
index 43582da9a5ea92bda2574f0ee8aa457cf231312d..05170cc9fd50e51ced8d74a03193019a0b44ba98 100644 (file)
 
 static int header;
 
-static int cmp_tag_age(void *a, void *b)
+static int cmp_age(int age1, int age2)
 {
-       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 (age1 != 0 && age2 != 0)
+               return age2 - age1;
 
-       if (r1->tag->tagger_date == 0 && r2->tag->tagger_date == 0)
+       if (age1 == 0 && age2 == 0)
                return 0;
 
-       if (r1 == 0)
+       if (age1 == 0)
                return +1;
 
        return -1;
 }
 
+static int cmp_tag_age(const void *a, const void *b)
+{
+       struct refinfo *r1 = *(struct refinfo **)a;
+       struct refinfo *r2 = *(struct refinfo **)b;
+
+       return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date);
+}
+
 static void cgit_print_branch(struct refinfo *ref)
 {
        struct commit *commit;
@@ -162,7 +167,7 @@ static void cgit_print_branches()
                cgit_print_branch(list.refs[i]);
 }
 
-static void cgit_print_tags()
+static void cgit_print_tags(int maxcount)
 {
        struct reflist list;
        int i;
@@ -174,8 +179,12 @@ static void cgit_print_tags()
        if (list.count == 0)
                return;
        qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age);
+       if (!maxcount)
+               maxcount = list.count;
+       else if (maxcount > list.count)
+               maxcount = list.count;
        print_tag_header();
-       for(i=0; i<list.count; i++)
+       for(i=0; i<maxcount; i++)
                print_tag(list.refs[i]);
 }
 
@@ -206,6 +215,6 @@ void cgit_print_summary()
                html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
        cgit_print_branches();
        html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
-       cgit_print_tags();
+       cgit_print_tags(cgit_summary_tags);
        html("</table>");
 }