about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorLars Hjemli2007-10-27 10:13:42 +0200
committerLars Hjemli2007-10-27 10:53:27 +0200
commit763a6a09deec7290365a0072d25630daa7b417e2 (patch)
treed882b72c05ef2b798883e637cba3f53ece12d78c
parentMove logic for age comparision from cmp_tag_age into cmp_age() (diff)
downloadcgit-763a6a09deec7290365a0072d25630daa7b417e2.tar.gz
cgit-763a6a09deec7290365a0072d25630daa7b417e2.zip
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>
-rw-r--r--cgit.h1
-rw-r--r--shared.c3
-rw-r--r--ui-summary.c31
3 files changed, 32 insertions, 3 deletions
diff --git a/cgit.h b/cgit.h index 53e1336..bb0e64c 100644 --- a/cgit.h +++ b/cgit.h
@@ -144,6 +144,7 @@ extern int cgit_cache_static_ttl;
144extern int cgit_cache_max_create_time; 144extern int cgit_cache_max_create_time;
145extern int cgit_summary_log; 145extern int cgit_summary_log;
146extern int cgit_summary_tags; 146extern int cgit_summary_tags;
147extern int cgit_summary_branches;
147 148
148extern int cgit_max_msg_len; 149extern int cgit_max_msg_len;
149extern int cgit_max_repodesc_len; 150extern int cgit_max_repodesc_len;
diff --git a/shared.c b/shared.c index 7e5eaba..ff600db 100644 --- a/shared.c +++ b/shared.c
@@ -39,6 +39,7 @@ int cgit_cache_static_ttl = -1;
39int cgit_cache_max_create_time = 5; 39int cgit_cache_max_create_time = 5;
40int cgit_summary_log = 0; 40int cgit_summary_log = 0;
41int cgit_summary_tags = 0; 41int cgit_summary_tags = 0;
42int cgit_summary_branches = 0;
42int cgit_renamelimit = -1; 43int cgit_renamelimit = -1;
43 44
44int cgit_max_msg_len = 60; 45int cgit_max_msg_len = 60;
@@ -182,6 +183,8 @@ void cgit_global_config_cb(const char *name, const char *value)
182 cgit_max_commit_count = atoi(value); 183 cgit_max_commit_count = atoi(value);
183 else if (!strcmp(name, "summary-log")) 184 else if (!strcmp(name, "summary-log"))
184 cgit_summary_log = atoi(value); 185 cgit_summary_log = atoi(value);
186 else if (!strcmp(name, "summary-branches"))
187 cgit_summary_branches = atoi(value);
185 else if (!strcmp(name, "summary-tags")) 188 else if (!strcmp(name, "summary-tags"))
186 cgit_summary_tags = atoi(value); 189 cgit_summary_tags = atoi(value);
187 else if (!strcmp(name, "agefile")) 190 else if (!strcmp(name, "agefile"))
diff --git a/ui-summary.c b/ui-summary.c index 05170cc..df79d01 100644 --- a/ui-summary.c +++ b/ui-summary.c
@@ -24,6 +24,22 @@ static int cmp_age(int age1, int age2)
24 return -1; 24 return -1;
25} 25}
26 26
27static int cmp_ref_name(const void *a, const void *b)
28{
29 struct refinfo *r1 = *(struct refinfo **)a;
30 struct refinfo *r2 = *(struct refinfo **)b;
31
32 return strcmp(r1->refname, r2->refname);
33}
34
35static int cmp_branch_age(const void *a, const void *b)
36{
37 struct refinfo *r1 = *(struct refinfo **)a;
38 struct refinfo *r2 = *(struct refinfo **)b;
39
40 return cmp_age(r1->commit->committer_date, r2->commit->committer_date);
41}
42
27static int cmp_tag_age(const void *a, const void *b) 43static int cmp_tag_age(const void *a, const void *b)
28{ 44{
29 struct refinfo *r1 = *(struct refinfo **)a; 45 struct refinfo *r1 = *(struct refinfo **)a;
@@ -150,7 +166,7 @@ static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
150 return 0; 166 return 0;
151} 167}
152 168
153static void cgit_print_branches() 169static void cgit_print_branches(int maxcount)
154{ 170{
155 struct reflist list; 171 struct reflist list;
156 int i; 172 int i;
@@ -163,7 +179,16 @@ static void cgit_print_branches()
163 list.refs = NULL; 179 list.refs = NULL;
164 list.alloc = list.count = 0; 180 list.alloc = list.count = 0;
165 for_each_branch_ref(cgit_refs_cb, &list); 181 for_each_branch_ref(cgit_refs_cb, &list);
166 for(i=0; i<list.count; i++) 182
183 if (maxcount == 0 || maxcount > list.count)
184 maxcount = list.count;
185
186 if (maxcount < list.count) {
187 qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age);
188 qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name);
189 }
190
191 for(i=0; i<maxcount; i++)
167 cgit_print_branch(list.refs[i]); 192 cgit_print_branch(list.refs[i]);
168} 193}
169 194
@@ -213,7 +238,7 @@ void cgit_print_summary()
213 html("<table class='list nowrap'>"); 238 html("<table class='list nowrap'>");
214 if (cgit_summary_log > 0) 239 if (cgit_summary_log > 0)
215 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 240 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
216 cgit_print_branches(); 241 cgit_print_branches(cgit_summary_branches);
217 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>"); 242 html("<tr class='nohover'><td colspan='4'>&nbsp;</td></tr>");
218 cgit_print_tags(cgit_summary_tags); 243 cgit_print_tags(cgit_summary_tags);
219 html("</table>"); 244 html("</table>");