-rw-r--r-- | ui-summary.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/ui-summary.c b/ui-summary.c index 05170cc..df79d01 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -19,16 +19,32 @@ static int cmp_age(int age1, int age2) | |||
19 | return 0; | 19 | return 0; |
20 | 20 | ||
21 | if (age1 == 0) | 21 | if (age1 == 0) |
22 | return +1; | 22 | return +1; |
23 | 23 | ||
24 | return -1; | 24 | return -1; |
25 | } | 25 | } |
26 | 26 | ||
27 | static 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 | |||
35 | static 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 | |||
27 | static int cmp_tag_age(const void *a, const void *b) | 43 | static 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; |
30 | struct refinfo *r2 = *(struct refinfo **)b; | 46 | struct refinfo *r2 = *(struct refinfo **)b; |
31 | 47 | ||
32 | return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); | 48 | return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); |
33 | } | 49 | } |
34 | 50 | ||
@@ -145,30 +161,39 @@ static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, | |||
145 | buf)); | 161 | buf)); |
146 | html_link_open(url, NULL, NULL); | 162 | html_link_open(url, NULL, NULL); |
147 | html_txt(buf); | 163 | html_txt(buf); |
148 | html_link_close(); | 164 | html_link_close(); |
149 | html("</td></tr>"); | 165 | html("</td></tr>"); |
150 | return 0; | 166 | return 0; |
151 | } | 167 | } |
152 | 168 | ||
153 | static void cgit_print_branches() | 169 | static void cgit_print_branches(int maxcount) |
154 | { | 170 | { |
155 | struct reflist list; | 171 | struct reflist list; |
156 | int i; | 172 | int i; |
157 | 173 | ||
158 | html("<tr class='nohover'><th class='left'>Branch</th>" | 174 | html("<tr class='nohover'><th class='left'>Branch</th>" |
159 | "<th class='left'>Idle</th>" | 175 | "<th class='left'>Idle</th>" |
160 | "<th class='left'>Author</th>" | 176 | "<th class='left'>Author</th>" |
161 | "<th class='left'>Head commit</th></tr>\n"); | 177 | "<th class='left'>Head commit</th></tr>\n"); |
162 | 178 | ||
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 | ||
170 | static void cgit_print_tags(int maxcount) | 195 | static void cgit_print_tags(int maxcount) |
171 | { | 196 | { |
172 | struct reflist list; | 197 | struct reflist list; |
173 | int i; | 198 | int i; |
174 | 199 | ||
@@ -208,13 +233,13 @@ void cgit_print_summary() | |||
208 | if (cgit_repo->readme) | 233 | if (cgit_repo->readme) |
209 | html_include(cgit_repo->readme); | 234 | html_include(cgit_repo->readme); |
210 | html("</div>"); | 235 | html("</div>"); |
211 | if (cgit_summary_log > 0) | 236 | if (cgit_summary_log > 0) |
212 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0); | 237 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0); |
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'> </td></tr>"); | 240 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
216 | cgit_print_branches(); | 241 | cgit_print_branches(cgit_summary_branches); |
217 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 242 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
218 | cgit_print_tags(cgit_summary_tags); | 243 | cgit_print_tags(cgit_summary_tags); |
219 | html("</table>"); | 244 | html("</table>"); |
220 | } | 245 | } |