cgit

commit 763a6a09deec7290365a0072d25630daa7b417e2

Author: Lars Hjemli <hjemli@gmail.com>

Add support for config param summary-branches

This parameter can be used to specify max number of branches to show
on the summary page (if not all branches will be displayed, the "most
idle" branches are the ones to be pruned). The default value for this
parameter is 0, which disables the pruning.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>

 cgit.h | 1 +
 shared.c | 3 +++
 ui-summary.c | 31 ++++++++++++++++++++++++++++---


diff --git a/cgit.h b/cgit.h
index 53e1336d846ea1759fd756013d312b602e93a666..bb0e64ca002e852e8fc8097fd9d8cc3447939786 100644
--- a/cgit.h
+++ b/cgit.h
@@ -144,6 +144,7 @@ extern int cgit_cache_static_ttl;
 extern int cgit_cache_max_create_time;
 extern int cgit_summary_log;
 extern int cgit_summary_tags;
+extern int cgit_summary_branches;
 
 extern int cgit_max_msg_len;
 extern int cgit_max_repodesc_len;




diff --git a/shared.c b/shared.c
index 7e5eabaf986ef15dfc2f22f922c0989f126aace0..ff600db498a77664e1effa628bf7272e39c385e9 100644
--- a/shared.c
+++ b/shared.c
@@ -39,6 +39,7 @@ int cgit_cache_static_ttl      = -1;
 int cgit_cache_max_create_time =  5;
 int cgit_summary_log           =  0;
 int cgit_summary_tags          =  0;
+int cgit_summary_branches      =  0;
 int cgit_renamelimit           = -1;
 
 int cgit_max_msg_len = 60;
@@ -182,6 +183,8 @@ 	else if (!strcmp(name, "max-commit-count"))
 		cgit_max_commit_count = atoi(value);
 	else if (!strcmp(name, "summary-log"))
 		cgit_summary_log = atoi(value);
+	else if (!strcmp(name, "summary-branches"))
+		cgit_summary_branches = atoi(value);
 	else if (!strcmp(name, "summary-tags"))
 		cgit_summary_tags = atoi(value);
 	else if (!strcmp(name, "agefile"))




diff --git a/ui-summary.c b/ui-summary.c
index 05170cc9fd50e51ced8d74a03193019a0b44ba98..df79d01c06f90014baa3e8d4b132ae039e32815c 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -24,6 +24,22 @@
 	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;
@@ -150,7 +166,7 @@ 	html("");
 	return 0;
 }
 
-static void cgit_print_branches()
+static void cgit_print_branches(int maxcount)
 {
 	struct reflist list;
 	int i;
@@ -163,7 +179,16 @@
 	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]);
 }
 
@@ -213,7 +238,7 @@ 		cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0);
 	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>");