]> gitweb.ps.run Git - ps-cgit/blobdiff - ui-summary.c
Merge branch 'filter-refs'
[ps-cgit] / ui-summary.c
index 3d5eda84f1261841606fe12f1430495c77f31b55..016fea2107668b507dfbfb0a3f5366c96f2dd3cb 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_ref_name(const void *a, const void *b)
+{
+       struct refinfo *r1 = *(struct refinfo **)a;
+       struct refinfo *r2 = *(struct refinfo **)b;
+
+       return strcmp(r1->refname, r2->refname);
+}
+
+static int cmp_branch_age(const void *a, const void *b)
+{
+       struct refinfo *r1 = *(struct refinfo **)a;
+       struct refinfo *r2 = *(struct refinfo **)b;
+
+       return cmp_age(r1->commit->committer_date, r2->commit->committer_date);
+}
+
+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;
@@ -145,7 +166,14 @@ static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
        return 0;
 }
 
-static void cgit_print_branches()
+static void print_refs_link(char *path)
+{
+       html("<tr class='nohover'><td colspan='4'>");
+       cgit_refs_link("[...]", NULL, NULL, cgit_query_head, NULL, path);
+       html("</td></tr>");
+}
+
+void cgit_print_branches(int maxcount)
 {
        struct reflist list;
        int i;
@@ -158,11 +186,23 @@ static void cgit_print_branches()
        list.refs = NULL;
        list.alloc = list.count = 0;
        for_each_branch_ref(cgit_refs_cb, &list);
-       for(i=0; i<list.count; i++)
+
+       if (maxcount == 0 || maxcount > list.count)
+               maxcount = list.count;
+
+       if (maxcount < list.count) {
+               qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age);
+               qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name);
+       }
+
+       for(i=0; i<maxcount; i++)
                cgit_print_branch(list.refs[i]);
+
+       if (maxcount < list.count)
+               print_refs_link("heads");
 }
 
-static void cgit_print_tags(int maxcount)
+void cgit_print_tags(int maxcount)
 {
        struct reflist list;
        int i;
@@ -181,6 +221,9 @@ static void cgit_print_tags(int maxcount)
        print_tag_header();
        for(i=0; i<maxcount; i++)
                print_tag(list.refs[i]);
+
+       if (maxcount < list.count)
+               print_refs_link("tags");
 }
 
 static void cgit_print_archives()
@@ -208,7 +251,7 @@ void cgit_print_summary()
        html("<table class='list nowrap'>");
        if (cgit_summary_log > 0)
                html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
-       cgit_print_branches();
+       cgit_print_branches(cgit_summary_branches);
        html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
        cgit_print_tags(cgit_summary_tags);
        html("</table>");