-rw-r--r-- | ui-summary.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/ui-summary.c b/ui-summary.c index 04a466a..ba90510 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -1,247 +1,253 @@ | |||
1 | /* ui-summary.c: functions for generating repo summary page | 1 | /* ui-summary.c: functions for generating repo summary page |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | static int header; | 11 | static int header; |
12 | 12 | ||
13 | static int cmp_age(int age1, int age2) | 13 | static int cmp_age(int age1, int age2) |
14 | { | 14 | { |
15 | if (age1 != 0 && age2 != 0) | 15 | if (age1 != 0 && age2 != 0) |
16 | return age2 - age1; | 16 | return age2 - age1; |
17 | 17 | ||
18 | if (age1 == 0 && age2 == 0) | 18 | if (age1 == 0 && age2 == 0) |
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) | 27 | static int cmp_ref_name(const void *a, const void *b) |
28 | { | 28 | { |
29 | struct refinfo *r1 = *(struct refinfo **)a; | 29 | struct refinfo *r1 = *(struct refinfo **)a; |
30 | struct refinfo *r2 = *(struct refinfo **)b; | 30 | struct refinfo *r2 = *(struct refinfo **)b; |
31 | 31 | ||
32 | return strcmp(r1->refname, r2->refname); | 32 | return strcmp(r1->refname, r2->refname); |
33 | } | 33 | } |
34 | 34 | ||
35 | static int cmp_branch_age(const void *a, const void *b) | 35 | static int cmp_branch_age(const void *a, const void *b) |
36 | { | 36 | { |
37 | struct refinfo *r1 = *(struct refinfo **)a; | 37 | struct refinfo *r1 = *(struct refinfo **)a; |
38 | struct refinfo *r2 = *(struct refinfo **)b; | 38 | struct refinfo *r2 = *(struct refinfo **)b; |
39 | 39 | ||
40 | return cmp_age(r1->commit->committer_date, r2->commit->committer_date); | 40 | return cmp_age(r1->commit->committer_date, r2->commit->committer_date); |
41 | } | 41 | } |
42 | 42 | ||
43 | static int cmp_tag_age(const void *a, const void *b) | 43 | static int cmp_tag_age(const void *a, const void *b) |
44 | { | 44 | { |
45 | struct refinfo *r1 = *(struct refinfo **)a; | 45 | struct refinfo *r1 = *(struct refinfo **)a; |
46 | struct refinfo *r2 = *(struct refinfo **)b; | 46 | struct refinfo *r2 = *(struct refinfo **)b; |
47 | 47 | ||
48 | return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); | 48 | return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); |
49 | } | 49 | } |
50 | 50 | ||
51 | static int print_branch(struct refinfo *ref) | 51 | static int print_branch(struct refinfo *ref) |
52 | { | 52 | { |
53 | struct commitinfo *info = ref->commit; | 53 | struct commitinfo *info = ref->commit; |
54 | char *name = (char *)ref->refname; | 54 | char *name = (char *)ref->refname; |
55 | 55 | ||
56 | if (!info) | 56 | if (!info) |
57 | return 1; | 57 | return 1; |
58 | html("<tr><td>"); | 58 | html("<tr><td>"); |
59 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); | 59 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); |
60 | html("</td><td>"); | 60 | html("</td><td>"); |
61 | cgit_print_age(info->commit->date, -1, NULL); | 61 | |
62 | html("</td><td>"); | 62 | if (ref->object->type == OBJ_COMMIT) { |
63 | html_txt(info->author); | 63 | cgit_print_age(info->commit->date, -1, NULL); |
64 | html("</td><td>"); | 64 | html("</td><td>"); |
65 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); | 65 | html_txt(info->author); |
66 | html("</td><td>"); | ||
67 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); | ||
68 | } else { | ||
69 | html("</td><td></td><td>"); | ||
70 | cgit_object_link(ref->object); | ||
71 | } | ||
66 | html("</td></tr>\n"); | 72 | html("</td></tr>\n"); |
67 | return 0; | 73 | return 0; |
68 | } | 74 | } |
69 | 75 | ||
70 | static void print_tag_header() | 76 | static void print_tag_header() |
71 | { | 77 | { |
72 | html("<tr class='nohover'><th class='left'>Tag</th>" | 78 | html("<tr class='nohover'><th class='left'>Tag</th>" |
73 | "<th class='left'>Age</th>" | 79 | "<th class='left'>Age</th>" |
74 | "<th class='left'>Author</th>" | 80 | "<th class='left'>Author</th>" |
75 | "<th class='left'>Reference</th></tr>\n"); | 81 | "<th class='left'>Reference</th></tr>\n"); |
76 | header = 1; | 82 | header = 1; |
77 | } | 83 | } |
78 | 84 | ||
79 | static int print_tag(struct refinfo *ref) | 85 | static int print_tag(struct refinfo *ref) |
80 | { | 86 | { |
81 | struct tag *tag; | 87 | struct tag *tag; |
82 | struct taginfo *info; | 88 | struct taginfo *info; |
83 | char *url, *name = (char *)ref->refname; | 89 | char *url, *name = (char *)ref->refname; |
84 | 90 | ||
85 | if (ref->object->type == OBJ_TAG) { | 91 | if (ref->object->type == OBJ_TAG) { |
86 | tag = (struct tag *)ref->object; | 92 | tag = (struct tag *)ref->object; |
87 | info = ref->tag; | 93 | info = ref->tag; |
88 | if (!tag || !info) | 94 | if (!tag || !info) |
89 | return 1; | 95 | return 1; |
90 | html("<tr><td>"); | 96 | html("<tr><td>"); |
91 | url = cgit_pageurl(cgit_query_repo, "tag", | 97 | url = cgit_pageurl(cgit_query_repo, "tag", |
92 | fmt("id=%s", name)); | 98 | fmt("id=%s", name)); |
93 | html_link_open(url, NULL, NULL); | 99 | html_link_open(url, NULL, NULL); |
94 | html_txt(name); | 100 | html_txt(name); |
95 | html_link_close(); | 101 | html_link_close(); |
96 | html("</td><td>"); | 102 | html("</td><td>"); |
97 | if (info->tagger_date > 0) | 103 | if (info->tagger_date > 0) |
98 | cgit_print_age(info->tagger_date, -1, NULL); | 104 | cgit_print_age(info->tagger_date, -1, NULL); |
99 | html("</td><td>"); | 105 | html("</td><td>"); |
100 | if (info->tagger) | 106 | if (info->tagger) |
101 | html(info->tagger); | 107 | html(info->tagger); |
102 | html("</td><td>"); | 108 | html("</td><td>"); |
103 | cgit_object_link(tag->tagged); | 109 | cgit_object_link(tag->tagged); |
104 | html("</td></tr>\n"); | 110 | html("</td></tr>\n"); |
105 | } else { | 111 | } else { |
106 | if (!header) | 112 | if (!header) |
107 | print_tag_header(); | 113 | print_tag_header(); |
108 | html("<tr><td>"); | 114 | html("<tr><td>"); |
109 | html_txt(name); | 115 | html_txt(name); |
110 | html("</td><td colspan='2'/><td>"); | 116 | html("</td><td colspan='2'/><td>"); |
111 | cgit_object_link(ref->object); | 117 | cgit_object_link(ref->object); |
112 | html("</td></tr>\n"); | 118 | html("</td></tr>\n"); |
113 | } | 119 | } |
114 | return 0; | 120 | return 0; |
115 | } | 121 | } |
116 | 122 | ||
117 | static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, | 123 | static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, |
118 | int flags, void *cb_data) | 124 | int flags, void *cb_data) |
119 | { | 125 | { |
120 | struct tag *tag; | 126 | struct tag *tag; |
121 | struct taginfo *info; | 127 | struct taginfo *info; |
122 | struct object *obj; | 128 | struct object *obj; |
123 | char buf[256], *url; | 129 | char buf[256], *url; |
124 | unsigned char fileid[20]; | 130 | unsigned char fileid[20]; |
125 | 131 | ||
126 | if (prefixcmp(refname, "refs/archives")) | 132 | if (prefixcmp(refname, "refs/archives")) |
127 | return 0; | 133 | return 0; |
128 | strncpy(buf, refname+14, sizeof(buf)); | 134 | strncpy(buf, refname+14, sizeof(buf)); |
129 | obj = parse_object(sha1); | 135 | obj = parse_object(sha1); |
130 | if (!obj) | 136 | if (!obj) |
131 | return 1; | 137 | return 1; |
132 | if (obj->type == OBJ_TAG) { | 138 | if (obj->type == OBJ_TAG) { |
133 | tag = lookup_tag(sha1); | 139 | tag = lookup_tag(sha1); |
134 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 140 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
135 | return 0; | 141 | return 0; |
136 | hashcpy(fileid, tag->tagged->sha1); | 142 | hashcpy(fileid, tag->tagged->sha1); |
137 | } else if (obj->type != OBJ_BLOB) { | 143 | } else if (obj->type != OBJ_BLOB) { |
138 | return 0; | 144 | return 0; |
139 | } else { | 145 | } else { |
140 | hashcpy(fileid, sha1); | 146 | hashcpy(fileid, sha1); |
141 | } | 147 | } |
142 | if (!header) { | 148 | if (!header) { |
143 | html("<table id='downloads'>"); | 149 | html("<table id='downloads'>"); |
144 | html("<tr><th>Downloads</th></tr>"); | 150 | html("<tr><th>Downloads</th></tr>"); |
145 | header = 1; | 151 | header = 1; |
146 | } | 152 | } |
147 | html("<tr><td>"); | 153 | html("<tr><td>"); |
148 | url = cgit_pageurl(cgit_query_repo, "blob", | 154 | url = cgit_pageurl(cgit_query_repo, "blob", |
149 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 155 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
150 | buf)); | 156 | buf)); |
151 | html_link_open(url, NULL, NULL); | 157 | html_link_open(url, NULL, NULL); |
152 | html_txt(buf); | 158 | html_txt(buf); |
153 | html_link_close(); | 159 | html_link_close(); |
154 | html("</td></tr>"); | 160 | html("</td></tr>"); |
155 | return 0; | 161 | return 0; |
156 | } | 162 | } |
157 | 163 | ||
158 | static void print_refs_link(char *path) | 164 | static void print_refs_link(char *path) |
159 | { | 165 | { |
160 | html("<tr class='nohover'><td colspan='4'>"); | 166 | html("<tr class='nohover'><td colspan='4'>"); |
161 | cgit_refs_link("[...]", NULL, NULL, cgit_query_head, NULL, path); | 167 | cgit_refs_link("[...]", NULL, NULL, cgit_query_head, NULL, path); |
162 | html("</td></tr>"); | 168 | html("</td></tr>"); |
163 | } | 169 | } |
164 | 170 | ||
165 | void cgit_print_branches(int maxcount) | 171 | void cgit_print_branches(int maxcount) |
166 | { | 172 | { |
167 | struct reflist list; | 173 | struct reflist list; |
168 | int i; | 174 | int i; |
169 | 175 | ||
170 | html("<tr class='nohover'><th class='left'>Branch</th>" | 176 | html("<tr class='nohover'><th class='left'>Branch</th>" |
171 | "<th class='left'>Idle</th>" | 177 | "<th class='left'>Idle</th>" |
172 | "<th class='left'>Author</th>" | 178 | "<th class='left'>Author</th>" |
173 | "<th class='left'>Head commit</th></tr>\n"); | 179 | "<th class='left'>Head commit</th></tr>\n"); |
174 | 180 | ||
175 | list.refs = NULL; | 181 | list.refs = NULL; |
176 | list.alloc = list.count = 0; | 182 | list.alloc = list.count = 0; |
177 | for_each_branch_ref(cgit_refs_cb, &list); | 183 | for_each_branch_ref(cgit_refs_cb, &list); |
178 | 184 | ||
179 | if (maxcount == 0 || maxcount > list.count) | 185 | if (maxcount == 0 || maxcount > list.count) |
180 | maxcount = list.count; | 186 | maxcount = list.count; |
181 | 187 | ||
182 | if (maxcount < list.count) { | 188 | if (maxcount < list.count) { |
183 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); | 189 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); |
184 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); | 190 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); |
185 | } | 191 | } |
186 | 192 | ||
187 | for(i=0; i<maxcount; i++) | 193 | for(i=0; i<maxcount; i++) |
188 | print_branch(list.refs[i]); | 194 | print_branch(list.refs[i]); |
189 | 195 | ||
190 | if (maxcount < list.count) | 196 | if (maxcount < list.count) |
191 | print_refs_link("heads"); | 197 | print_refs_link("heads"); |
192 | } | 198 | } |
193 | 199 | ||
194 | void cgit_print_tags(int maxcount) | 200 | void cgit_print_tags(int maxcount) |
195 | { | 201 | { |
196 | struct reflist list; | 202 | struct reflist list; |
197 | int i; | 203 | int i; |
198 | 204 | ||
199 | header = 0; | 205 | header = 0; |
200 | list.refs = NULL; | 206 | list.refs = NULL; |
201 | list.alloc = list.count = 0; | 207 | list.alloc = list.count = 0; |
202 | for_each_tag_ref(cgit_refs_cb, &list); | 208 | for_each_tag_ref(cgit_refs_cb, &list); |
203 | if (list.count == 0) | 209 | if (list.count == 0) |
204 | return; | 210 | return; |
205 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); | 211 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); |
206 | if (!maxcount) | 212 | if (!maxcount) |
207 | maxcount = list.count; | 213 | maxcount = list.count; |
208 | else if (maxcount > list.count) | 214 | else if (maxcount > list.count) |
209 | maxcount = list.count; | 215 | maxcount = list.count; |
210 | print_tag_header(); | 216 | print_tag_header(); |
211 | for(i=0; i<maxcount; i++) | 217 | for(i=0; i<maxcount; i++) |
212 | print_tag(list.refs[i]); | 218 | print_tag(list.refs[i]); |
213 | 219 | ||
214 | if (maxcount < list.count) | 220 | if (maxcount < list.count) |
215 | print_refs_link("tags"); | 221 | print_refs_link("tags"); |
216 | } | 222 | } |
217 | 223 | ||
218 | static void cgit_print_archives() | 224 | static void cgit_print_archives() |
219 | { | 225 | { |
220 | header = 0; | 226 | header = 0; |
221 | for_each_ref(cgit_print_archive_cb, NULL); | 227 | for_each_ref(cgit_print_archive_cb, NULL); |
222 | if (header) | 228 | if (header) |
223 | html("</table>"); | 229 | html("</table>"); |
224 | } | 230 | } |
225 | 231 | ||
226 | void cgit_print_summary() | 232 | void cgit_print_summary() |
227 | { | 233 | { |
228 | html("<div id='summary'>"); | 234 | html("<div id='summary'>"); |
229 | cgit_print_archives(); | 235 | cgit_print_archives(); |
230 | html("<h2>"); | 236 | html("<h2>"); |
231 | html_txt(cgit_repo->name); | 237 | html_txt(cgit_repo->name); |
232 | html(" - "); | 238 | html(" - "); |
233 | html_txt(cgit_repo->desc); | 239 | html_txt(cgit_repo->desc); |
234 | html("</h2>"); | 240 | html("</h2>"); |
235 | if (cgit_repo->readme) | 241 | if (cgit_repo->readme) |
236 | html_include(cgit_repo->readme); | 242 | html_include(cgit_repo->readme); |
237 | html("</div>"); | 243 | html("</div>"); |
238 | if (cgit_summary_log > 0) | 244 | if (cgit_summary_log > 0) |
239 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, NULL, 0); | 245 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, NULL, 0); |
240 | html("<table class='list nowrap'>"); | 246 | html("<table class='list nowrap'>"); |
241 | if (cgit_summary_log > 0) | 247 | if (cgit_summary_log > 0) |
242 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 248 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
243 | cgit_print_branches(cgit_summary_branches); | 249 | cgit_print_branches(cgit_summary_branches); |
244 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 250 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
245 | cgit_print_tags(cgit_summary_tags); | 251 | cgit_print_tags(cgit_summary_tags); |
246 | html("</table>"); | 252 | html("</table>"); |
247 | } | 253 | } |