diff options
Diffstat (limited to 'ui-summary.c')
-rw-r--r-- | ui-summary.c | 172 |
1 files changed, 115 insertions, 57 deletions
diff --git a/ui-summary.c b/ui-summary.c index de8a180..178e959 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -10,40 +10,60 @@ | |||
10 | 10 | ||
11 | static int header; | 11 | static int header; |
12 | 12 | ||
13 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | 13 | static int cmp_age(int age1, int age2) |
14 | int flags, void *cb_data) | ||
15 | { | 14 | { |
16 | struct commit *commit; | 15 | if (age1 != 0 && age2 != 0) |
17 | struct commitinfo *info; | 16 | return age2 - age1; |
18 | char buf[256]; | 17 | |
19 | char *ref; | 18 | if (age1 == 0 && age2 == 0) |
20 | 19 | return 0; | |
21 | ref = xstrdup(refname); | 20 | |
22 | strncpy(buf, refname, sizeof(buf)); | 21 | if (age1 == 0) |
23 | commit = lookup_commit(sha1); | 22 | return +1; |
24 | // object is not really parsed at this point, because of some fallout | 23 | |
25 | // from previous calls to git functions in cgit_print_log() | 24 | return -1; |
26 | commit->object.parsed = 0; | 25 | } |
27 | if (commit && !parse_commit(commit)){ | 26 | |
28 | info = cgit_parse_commit(commit); | 27 | static int cmp_ref_name(const void *a, const void *b) |
29 | html("<tr><td>"); | 28 | { |
30 | cgit_log_link(ref, NULL, NULL, ref, NULL, NULL, 0); | 29 | struct refinfo *r1 = *(struct refinfo **)a; |
31 | html("</td><td>"); | 30 | struct refinfo *r2 = *(struct refinfo **)b; |
32 | cgit_print_age(commit->date, -1, NULL); | 31 | |
33 | html("</td><td>"); | 32 | return strcmp(r1->refname, r2->refname); |
34 | html_txt(info->author); | 33 | } |
35 | html("</td><td>"); | 34 | |
36 | cgit_commit_link(info->subject, NULL, NULL, ref, NULL); | 35 | static int cmp_branch_age(const void *a, const void *b) |
37 | html("</td></tr>\n"); | 36 | { |
38 | cgit_free_commitinfo(info); | 37 | struct refinfo *r1 = *(struct refinfo **)a; |
39 | } else { | 38 | struct refinfo *r2 = *(struct refinfo **)b; |
40 | html("<tr><td>"); | 39 | |
41 | html_txt(buf); | 40 | return cmp_age(r1->commit->committer_date, r2->commit->committer_date); |
42 | html("</td><td colspan='3'>"); | 41 | } |
43 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); | 42 | |
44 | html("</td></tr>\n"); | 43 | static int cmp_tag_age(const void *a, const void *b) |
45 | } | 44 | { |
46 | free(ref); | 45 | struct refinfo *r1 = *(struct refinfo **)a; |
46 | struct refinfo *r2 = *(struct refinfo **)b; | ||
47 | |||
48 | return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); | ||
49 | } | ||
50 | |||
51 | static int print_branch(struct refinfo *ref) | ||
52 | { | ||
53 | struct commitinfo *info = ref->commit; | ||
54 | char *name = (char *)ref->refname; | ||
55 | |||
56 | if (!info) | ||
57 | return 1; | ||
58 | html("<tr><td>"); | ||
59 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); | ||
60 | html("</td><td>"); | ||
61 | cgit_print_age(info->commit->date, -1, NULL); | ||
62 | html("</td><td>"); | ||
63 | html_txt(info->author); | ||
64 | html("</td><td>"); | ||
65 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); | ||
66 | html("</td></tr>\n"); | ||
47 | return 0; | 67 | return 0; |
48 | } | 68 | } |
49 | 69 | ||
@@ -56,29 +76,22 @@ static void print_tag_header() | |||
56 | header = 1; | 76 | header = 1; |
57 | } | 77 | } |
58 | 78 | ||
59 | static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, | 79 | static int print_tag(struct refinfo *ref) |
60 | int flags, void *cb_data) | ||
61 | { | 80 | { |
62 | struct tag *tag; | 81 | struct tag *tag; |
63 | struct taginfo *info; | 82 | struct taginfo *info; |
64 | struct object *obj; | 83 | char *url, *name = (char *)ref->refname; |
65 | char buf[256], *url; | ||
66 | 84 | ||
67 | strncpy(buf, refname, sizeof(buf)); | 85 | if (ref->object->type == OBJ_TAG) { |
68 | obj = parse_object(sha1); | 86 | tag = (struct tag *)ref->object; |
69 | if (!obj) | 87 | info = ref->tag; |
70 | return 1; | 88 | if (!tag || !info) |
71 | if (obj->type == OBJ_TAG) { | 89 | return 1; |
72 | tag = lookup_tag(sha1); | ||
73 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | ||
74 | return 2; | ||
75 | if (!header) | ||
76 | print_tag_header(); | ||
77 | html("<tr><td>"); | 90 | html("<tr><td>"); |
78 | url = cgit_pageurl(cgit_query_repo, "tag", | 91 | url = cgit_pageurl(cgit_query_repo, "tag", |
79 | fmt("id=%s", refname)); | 92 | fmt("id=%s", name)); |
80 | html_link_open(url, NULL, NULL); | 93 | html_link_open(url, NULL, NULL); |
81 | html_txt(buf); | 94 | html_txt(name); |
82 | html_link_close(); | 95 | html_link_close(); |
83 | html("</td><td>"); | 96 | html("</td><td>"); |
84 | if (info->tagger_date > 0) | 97 | if (info->tagger_date > 0) |
@@ -93,9 +106,9 @@ static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, | |||
93 | if (!header) | 106 | if (!header) |
94 | print_tag_header(); | 107 | print_tag_header(); |
95 | html("<tr><td>"); | 108 | html("<tr><td>"); |
96 | html_txt(buf); | 109 | html_txt(name); |
97 | html("</td><td colspan='2'/><td>"); | 110 | html("</td><td colspan='2'/><td>"); |
98 | cgit_object_link(obj); | 111 | cgit_object_link(ref->object); |
99 | html("</td></tr>\n"); | 112 | html("</td></tr>\n"); |
100 | } | 113 | } |
101 | return 0; | 114 | return 0; |
@@ -142,19 +155,64 @@ static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, | |||
142 | return 0; | 155 | return 0; |
143 | } | 156 | } |
144 | 157 | ||
145 | static void cgit_print_branches() | 158 | static void print_refs_link(char *path) |
146 | { | 159 | { |
160 | html("<tr class='nohover'><td colspan='4'>"); | ||
161 | cgit_refs_link("[...]", NULL, NULL, cgit_query_head, NULL, path); | ||
162 | html("</td></tr>"); | ||
163 | } | ||
164 | |||
165 | void cgit_print_branches(int maxcount) | ||
166 | { | ||
167 | struct reflist list; | ||
168 | int i; | ||
169 | |||
147 | html("<tr class='nohover'><th class='left'>Branch</th>" | 170 | html("<tr class='nohover'><th class='left'>Branch</th>" |
148 | "<th class='left'>Idle</th>" | 171 | "<th class='left'>Idle</th>" |
149 | "<th class='left'>Author</th>" | 172 | "<th class='left'>Author</th>" |
150 | "<th class='left'>Head commit</th></tr>\n"); | 173 | "<th class='left'>Head commit</th></tr>\n"); |
151 | for_each_branch_ref(cgit_print_branch_cb, NULL); | 174 | |
175 | list.refs = NULL; | ||
176 | list.alloc = list.count = 0; | ||
177 | for_each_branch_ref(cgit_refs_cb, &list); | ||
178 | |||
179 | if (maxcount == 0 || maxcount > list.count) | ||
180 | maxcount = list.count; | ||
181 | |||
182 | if (maxcount < list.count) { | ||
183 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); | ||
184 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); | ||
185 | } | ||
186 | |||
187 | for(i=0; i<maxcount; i++) | ||
188 | print_branch(list.refs[i]); | ||
189 | |||
190 | if (maxcount < list.count) | ||
191 | print_refs_link("heads"); | ||
152 | } | 192 | } |
153 | 193 | ||
154 | static void cgit_print_tags() | 194 | void cgit_print_tags(int maxcount) |
155 | { | 195 | { |
196 | struct reflist list; | ||
197 | int i; | ||
198 | |||
156 | header = 0; | 199 | header = 0; |
157 | for_each_tag_ref(cgit_print_tag_cb, NULL); | 200 | list.refs = NULL; |
201 | list.alloc = list.count = 0; | ||
202 | for_each_tag_ref(cgit_refs_cb, &list); | ||
203 | if (list.count == 0) | ||
204 | return; | ||
205 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); | ||
206 | if (!maxcount) | ||
207 | maxcount = list.count; | ||
208 | else if (maxcount > list.count) | ||
209 | maxcount = list.count; | ||
210 | print_tag_header(); | ||
211 | for(i=0; i<maxcount; i++) | ||
212 | print_tag(list.refs[i]); | ||
213 | |||
214 | if (maxcount < list.count) | ||
215 | print_refs_link("tags"); | ||
158 | } | 216 | } |
159 | 217 | ||
160 | static void cgit_print_archives() | 218 | static void cgit_print_archives() |
@@ -182,8 +240,8 @@ void cgit_print_summary() | |||
182 | html("<table class='list nowrap'>"); | 240 | html("<table class='list nowrap'>"); |
183 | if (cgit_summary_log > 0) | 241 | if (cgit_summary_log > 0) |
184 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 242 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
185 | cgit_print_branches(); | 243 | cgit_print_branches(cgit_summary_branches); |
186 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 244 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
187 | cgit_print_tags(); | 245 | cgit_print_tags(cgit_summary_tags); |
188 | html("</table>"); | 246 | html("</table>"); |
189 | } | 247 | } |