author | Lars Hjemli <hjemli@gmail.com> | 2010-06-22 14:15:48 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2010-06-22 14:15:48 (UTC) |
commit | 37a24e4e39737edaa5cdde501346a65eeb280e63 (patch) (unidiff) | |
tree | ff23eb0d57edf108edd1aa3e64a8d6cf70062954 /ui-shared.c | |
parent | 47187b33be1c3de43fbed6f350ab05bc978aacd0 (diff) | |
parent | a2cbd3c30b64a26b52b2003ba6569f3c083f4092 (diff) | |
download | cgit-37a24e4e39737edaa5cdde501346a65eeb280e63.zip cgit-37a24e4e39737edaa5cdde501346a65eeb280e63.tar.gz cgit-37a24e4e39737edaa5cdde501346a65eeb280e63.tar.bz2 |
Merge branch 'jh/path-limit'
Conflicts:
cgit.h
ui-commit.c
-rw-r--r-- | ui-shared.c | 216 |
1 files changed, 150 insertions, 66 deletions
diff --git a/ui-shared.c b/ui-shared.c index 8827fff..e991799 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -14,33 +14,33 @@ const char cgit_doctype[] = | |||
14 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" | 14 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" |
15 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | 15 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
16 | 16 | ||
17 | static char *http_date(time_t t) | 17 | static char *http_date(time_t t) |
18 | { | 18 | { |
19 | static char day[][4] = | 19 | static char day[][4] = |
20 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; | 20 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; |
21 | static char month[][4] = | 21 | static char month[][4] = |
22 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | 22 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
23 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; | 23 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
24 | struct tm *tm = gmtime(&t); | 24 | struct tm *tm = gmtime(&t); |
25 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], | 25 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], |
26 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, | 26 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, |
27 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 27 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
28 | } | 28 | } |
29 | 29 | ||
30 | void cgit_print_error(char *msg) | 30 | void cgit_print_error(const char *msg) |
31 | { | 31 | { |
32 | html("<div class='error'>"); | 32 | html("<div class='error'>"); |
33 | html_txt(msg); | 33 | html_txt(msg); |
34 | html("</div>\n"); | 34 | html("</div>\n"); |
35 | } | 35 | } |
36 | 36 | ||
37 | char *cgit_httpscheme() | 37 | char *cgit_httpscheme() |
38 | { | 38 | { |
39 | if (ctx.env.https && !strcmp(ctx.env.https, "on")) | 39 | if (ctx.env.https && !strcmp(ctx.env.https, "on")) |
40 | return "https://"; | 40 | return "https://"; |
41 | else | 41 | else |
42 | return "http://"; | 42 | return "http://"; |
43 | } | 43 | } |
44 | 44 | ||
45 | char *cgit_hosturl() | 45 | char *cgit_hosturl() |
46 | { | 46 | { |
@@ -120,88 +120,88 @@ const char *cgit_repobasename(const char *reponame) | |||
120 | return ++rv; | 120 | return ++rv; |
121 | return rvbuf; | 121 | return rvbuf; |
122 | } | 122 | } |
123 | 123 | ||
124 | char *cgit_currurl() | 124 | char *cgit_currurl() |
125 | { | 125 | { |
126 | if (!ctx.cfg.virtual_root) | 126 | if (!ctx.cfg.virtual_root) |
127 | return ctx.cfg.script_name; | 127 | return ctx.cfg.script_name; |
128 | else if (ctx.qry.page) | 128 | else if (ctx.qry.page) |
129 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); | 129 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); |
130 | else if (ctx.qry.repo) | 130 | else if (ctx.qry.repo) |
131 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); | 131 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); |
132 | else | 132 | else |
133 | return fmt("%s/", ctx.cfg.virtual_root); | 133 | return fmt("%s/", ctx.cfg.virtual_root); |
134 | } | 134 | } |
135 | 135 | ||
136 | static void site_url(char *page, char *search, int ofs) | 136 | static void site_url(const char *page, const char *search, int ofs) |
137 | { | 137 | { |
138 | char *delim = "?"; | 138 | char *delim = "?"; |
139 | 139 | ||
140 | if (ctx.cfg.virtual_root) { | 140 | if (ctx.cfg.virtual_root) { |
141 | html_attr(ctx.cfg.virtual_root); | 141 | html_attr(ctx.cfg.virtual_root); |
142 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') | 142 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
143 | html("/"); | 143 | html("/"); |
144 | } else | 144 | } else |
145 | html(ctx.cfg.script_name); | 145 | html(ctx.cfg.script_name); |
146 | 146 | ||
147 | if (page) { | 147 | if (page) { |
148 | htmlf("?p=%s", page); | 148 | htmlf("?p=%s", page); |
149 | delim = "&"; | 149 | delim = "&"; |
150 | } | 150 | } |
151 | if (search) { | 151 | if (search) { |
152 | html(delim); | 152 | html(delim); |
153 | html("q="); | 153 | html("q="); |
154 | html_attr(search); | 154 | html_attr(search); |
155 | delim = "&"; | 155 | delim = "&"; |
156 | } | 156 | } |
157 | if (ofs) { | 157 | if (ofs) { |
158 | html(delim); | 158 | html(delim); |
159 | htmlf("ofs=%d", ofs); | 159 | htmlf("ofs=%d", ofs); |
160 | } | 160 | } |
161 | } | 161 | } |
162 | 162 | ||
163 | static void site_link(char *page, char *name, char *title, char *class, | 163 | static void site_link(const char *page, const char *name, const char *title, |
164 | char *search, int ofs) | 164 | const char *class, const char *search, int ofs) |
165 | { | 165 | { |
166 | html("<a"); | 166 | html("<a"); |
167 | if (title) { | 167 | if (title) { |
168 | html(" title='"); | 168 | html(" title='"); |
169 | html_attr(title); | 169 | html_attr(title); |
170 | html("'"); | 170 | html("'"); |
171 | } | 171 | } |
172 | if (class) { | 172 | if (class) { |
173 | html(" class='"); | 173 | html(" class='"); |
174 | html_attr(class); | 174 | html_attr(class); |
175 | html("'"); | 175 | html("'"); |
176 | } | 176 | } |
177 | html(" href='"); | 177 | html(" href='"); |
178 | site_url(page, search, ofs); | 178 | site_url(page, search, ofs); |
179 | html("'>"); | 179 | html("'>"); |
180 | html_txt(name); | 180 | html_txt(name); |
181 | html("</a>"); | 181 | html("</a>"); |
182 | } | 182 | } |
183 | 183 | ||
184 | void cgit_index_link(char *name, char *title, char *class, char *pattern, | 184 | void cgit_index_link(const char *name, const char *title, const char *class, |
185 | int ofs) | 185 | const char *pattern, int ofs) |
186 | { | 186 | { |
187 | site_link(NULL, name, title, class, pattern, ofs); | 187 | site_link(NULL, name, title, class, pattern, ofs); |
188 | } | 188 | } |
189 | 189 | ||
190 | static char *repolink(char *title, char *class, char *page, char *head, | 190 | static char *repolink(const char *title, const char *class, const char *page, |
191 | char *path) | 191 | const char *head, const char *path) |
192 | { | 192 | { |
193 | char *delim = "?"; | 193 | char *delim = "?"; |
194 | 194 | ||
195 | html("<a"); | 195 | html("<a"); |
196 | if (title) { | 196 | if (title) { |
197 | html(" title='"); | 197 | html(" title='"); |
198 | html_attr(title); | 198 | html_attr(title); |
199 | html("'"); | 199 | html("'"); |
200 | } | 200 | } |
201 | if (class) { | 201 | if (class) { |
202 | html(" class='"); | 202 | html(" class='"); |
203 | html_attr(class); | 203 | html_attr(class); |
204 | html("'"); | 204 | html("'"); |
205 | } | 205 | } |
206 | html(" href='"); | 206 | html(" href='"); |
207 | if (ctx.cfg.virtual_root) { | 207 | if (ctx.cfg.virtual_root) { |
@@ -227,74 +227,76 @@ static char *repolink(char *title, char *class, char *page, char *head, | |||
227 | html_url_arg(page); | 227 | html_url_arg(page); |
228 | html("/"); | 228 | html("/"); |
229 | if (path) | 229 | if (path) |
230 | html_url_arg(path); | 230 | html_url_arg(path); |
231 | } | 231 | } |
232 | delim = "&"; | 232 | delim = "&"; |
233 | } | 233 | } |
234 | if (head && strcmp(head, ctx.repo->defbranch)) { | 234 | if (head && strcmp(head, ctx.repo->defbranch)) { |
235 | html(delim); | 235 | html(delim); |
236 | html("h="); | 236 | html("h="); |
237 | html_url_arg(head); | 237 | html_url_arg(head); |
238 | delim = "&"; | 238 | delim = "&"; |
239 | } | 239 | } |
240 | return fmt("%s", delim); | 240 | return fmt("%s", delim); |
241 | } | 241 | } |
242 | 242 | ||
243 | static void reporevlink(char *page, char *name, char *title, char *class, | 243 | static void reporevlink(const char *page, const char *name, const char *title, |
244 | char *head, char *rev, char *path) | 244 | const char *class, const char *head, const char *rev, |
245 | const char *path) | ||
245 | { | 246 | { |
246 | char *delim; | 247 | char *delim; |
247 | 248 | ||
248 | delim = repolink(title, class, page, head, path); | 249 | delim = repolink(title, class, page, head, path); |
249 | if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) { | 250 | if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) { |
250 | html(delim); | 251 | html(delim); |
251 | html("id="); | 252 | html("id="); |
252 | html_url_arg(rev); | 253 | html_url_arg(rev); |
253 | } | 254 | } |
254 | html("'>"); | 255 | html("'>"); |
255 | html_txt(name); | 256 | html_txt(name); |
256 | html("</a>"); | 257 | html("</a>"); |
257 | } | 258 | } |
258 | 259 | ||
259 | void cgit_summary_link(char *name, char *title, char *class, char *head) | 260 | void cgit_summary_link(const char *name, const char *title, const char *class, |
261 | const char *head) | ||
260 | { | 262 | { |
261 | reporevlink(NULL, name, title, class, head, NULL, NULL); | 263 | reporevlink(NULL, name, title, class, head, NULL, NULL); |
262 | } | 264 | } |
263 | 265 | ||
264 | void cgit_tag_link(char *name, char *title, char *class, char *head, | 266 | void cgit_tag_link(const char *name, const char *title, const char *class, |
265 | char *rev) | 267 | const char *head, const char *rev) |
266 | { | 268 | { |
267 | reporevlink("tag", name, title, class, head, rev, NULL); | 269 | reporevlink("tag", name, title, class, head, rev, NULL); |
268 | } | 270 | } |
269 | 271 | ||
270 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 272 | void cgit_tree_link(const char *name, const char *title, const char *class, |
271 | char *rev, char *path) | 273 | const char *head, const char *rev, const char *path) |
272 | { | 274 | { |
273 | reporevlink("tree", name, title, class, head, rev, path); | 275 | reporevlink("tree", name, title, class, head, rev, path); |
274 | } | 276 | } |
275 | 277 | ||
276 | void cgit_plain_link(char *name, char *title, char *class, char *head, | 278 | void cgit_plain_link(const char *name, const char *title, const char *class, |
277 | char *rev, char *path) | 279 | const char *head, const char *rev, const char *path) |
278 | { | 280 | { |
279 | reporevlink("plain", name, title, class, head, rev, path); | 281 | reporevlink("plain", name, title, class, head, rev, path); |
280 | } | 282 | } |
281 | 283 | ||
282 | void cgit_log_link(char *name, char *title, char *class, char *head, | 284 | void cgit_log_link(const char *name, const char *title, const char *class, |
283 | char *rev, char *path, int ofs, char *grep, char *pattern, | 285 | const char *head, const char *rev, const char *path, |
284 | int showmsg) | 286 | int ofs, const char *grep, const char *pattern, int showmsg) |
285 | { | 287 | { |
286 | char *delim; | 288 | char *delim; |
287 | 289 | ||
288 | delim = repolink(title, class, "log", head, path); | 290 | delim = repolink(title, class, "log", head, path); |
289 | if (rev && strcmp(rev, ctx.qry.head)) { | 291 | if (rev && strcmp(rev, ctx.qry.head)) { |
290 | html(delim); | 292 | html(delim); |
291 | html("id="); | 293 | html("id="); |
292 | html_url_arg(rev); | 294 | html_url_arg(rev); |
293 | delim = "&"; | 295 | delim = "&"; |
294 | } | 296 | } |
295 | if (grep && pattern) { | 297 | if (grep && pattern) { |
296 | html(delim); | 298 | html(delim); |
297 | html("qt="); | 299 | html("qt="); |
298 | html_url_arg(grep); | 300 | html_url_arg(grep); |
299 | delim = "&"; | 301 | delim = "&"; |
300 | html(delim); | 302 | html(delim); |
@@ -303,149 +305,209 @@ void cgit_log_link(char *name, char *title, char *class, char *head, | |||
303 | } | 305 | } |
304 | if (ofs > 0) { | 306 | if (ofs > 0) { |
305 | html(delim); | 307 | html(delim); |
306 | html("ofs="); | 308 | html("ofs="); |
307 | htmlf("%d", ofs); | 309 | htmlf("%d", ofs); |
308 | delim = "&"; | 310 | delim = "&"; |
309 | } | 311 | } |
310 | if (showmsg) { | 312 | if (showmsg) { |
311 | html(delim); | 313 | html(delim); |
312 | html("showmsg=1"); | 314 | html("showmsg=1"); |
313 | } | 315 | } |
314 | html("'>"); | 316 | html("'>"); |
315 | html_txt(name); | 317 | html_txt(name); |
316 | html("</a>"); | 318 | html("</a>"); |
317 | } | 319 | } |
318 | 320 | ||
319 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 321 | void cgit_commit_link(char *name, const char *title, const char *class, |
320 | char *rev, int toggle_ssdiff) | 322 | const char *head, const char *rev, const char *path, |
323 | int toggle_ssdiff) | ||
321 | { | 324 | { |
322 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { | 325 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { |
323 | name[ctx.cfg.max_msg_len] = '\0'; | 326 | name[ctx.cfg.max_msg_len] = '\0'; |
324 | name[ctx.cfg.max_msg_len - 1] = '.'; | 327 | name[ctx.cfg.max_msg_len - 1] = '.'; |
325 | name[ctx.cfg.max_msg_len - 2] = '.'; | 328 | name[ctx.cfg.max_msg_len - 2] = '.'; |
326 | name[ctx.cfg.max_msg_len - 3] = '.'; | 329 | name[ctx.cfg.max_msg_len - 3] = '.'; |
327 | } | 330 | } |
328 | 331 | ||
329 | char *delim; | 332 | char *delim; |
330 | 333 | ||
331 | delim = repolink(title, class, "commit", head, NULL); | 334 | delim = repolink(title, class, "commit", head, path); |
332 | if (rev && strcmp(rev, ctx.qry.head)) { | 335 | if (rev && strcmp(rev, ctx.qry.head)) { |
333 | html(delim); | 336 | html(delim); |
334 | html("id="); | 337 | html("id="); |
335 | html_url_arg(rev); | 338 | html_url_arg(rev); |
336 | delim = "&"; | 339 | delim = "&"; |
337 | } | 340 | } |
338 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { | 341 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { |
339 | html(delim); | 342 | html(delim); |
340 | html("ss=1"); | 343 | html("ss=1"); |
341 | } | 344 | } |
342 | html("'>"); | 345 | html("'>"); |
343 | html_txt(name); | 346 | html_txt(name); |
344 | html("</a>"); | 347 | html("</a>"); |
345 | } | 348 | } |
346 | 349 | ||
347 | void cgit_refs_link(char *name, char *title, char *class, char *head, | 350 | void cgit_refs_link(const char *name, const char *title, const char *class, |
348 | char *rev, char *path) | 351 | const char *head, const char *rev, const char *path) |
349 | { | 352 | { |
350 | reporevlink("refs", name, title, class, head, rev, path); | 353 | reporevlink("refs", name, title, class, head, rev, path); |
351 | } | 354 | } |
352 | 355 | ||
353 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, | 356 | void cgit_snapshot_link(const char *name, const char *title, const char *class, |
354 | char *rev, char *archivename) | 357 | const char *head, const char *rev, |
358 | const char *archivename) | ||
355 | { | 359 | { |
356 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 360 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
357 | } | 361 | } |
358 | 362 | ||
359 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 363 | void cgit_diff_link(const char *name, const char *title, const char *class, |
360 | char *new_rev, char *old_rev, char *path, | 364 | const char *head, const char *new_rev, const char *old_rev, |
361 | int toggle_ssdiff) | 365 | const char *path, int toggle_ssdiff) |
362 | { | 366 | { |
363 | char *delim; | 367 | char *delim; |
364 | 368 | ||
365 | delim = repolink(title, class, "diff", head, path); | 369 | delim = repolink(title, class, "diff", head, path); |
366 | if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) { | 370 | if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) { |
367 | html(delim); | 371 | html(delim); |
368 | html("id="); | 372 | html("id="); |
369 | html_url_arg(new_rev); | 373 | html_url_arg(new_rev); |
370 | delim = "&"; | 374 | delim = "&"; |
371 | } | 375 | } |
372 | if (old_rev) { | 376 | if (old_rev) { |
373 | html(delim); | 377 | html(delim); |
374 | html("id2="); | 378 | html("id2="); |
375 | html_url_arg(old_rev); | 379 | html_url_arg(old_rev); |
376 | delim = "&"; | 380 | delim = "&"; |
377 | } | 381 | } |
378 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { | 382 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { |
379 | html(delim); | 383 | html(delim); |
380 | html("ss=1"); | 384 | html("ss=1"); |
381 | } | 385 | } |
382 | html("'>"); | 386 | html("'>"); |
383 | html_txt(name); | 387 | html_txt(name); |
384 | html("</a>"); | 388 | html("</a>"); |
385 | } | 389 | } |
386 | 390 | ||
387 | void cgit_patch_link(char *name, char *title, char *class, char *head, | 391 | void cgit_patch_link(const char *name, const char *title, const char *class, |
388 | char *rev) | 392 | const char *head, const char *rev, const char *path) |
389 | { | 393 | { |
390 | reporevlink("patch", name, title, class, head, rev, NULL); | 394 | reporevlink("patch", name, title, class, head, rev, path); |
391 | } | 395 | } |
392 | 396 | ||
393 | void cgit_stats_link(char *name, char *title, char *class, char *head, | 397 | void cgit_stats_link(const char *name, const char *title, const char *class, |
394 | char *path) | 398 | const char *head, const char *path) |
395 | { | 399 | { |
396 | reporevlink("stats", name, title, class, head, NULL, path); | 400 | reporevlink("stats", name, title, class, head, NULL, path); |
397 | } | 401 | } |
398 | 402 | ||
403 | void cgit_self_link(char *name, const char *title, const char *class, | ||
404 | struct cgit_context *ctx) | ||
405 | { | ||
406 | if (!strcmp(ctx->qry.page, "repolist")) | ||
407 | return cgit_index_link(name, title, class, ctx->qry.search, | ||
408 | ctx->qry.ofs); | ||
409 | else if (!strcmp(ctx->qry.page, "summary")) | ||
410 | return cgit_summary_link(name, title, class, ctx->qry.head); | ||
411 | else if (!strcmp(ctx->qry.page, "tag")) | ||
412 | return cgit_tag_link(name, title, class, ctx->qry.head, | ||
413 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL); | ||
414 | else if (!strcmp(ctx->qry.page, "tree")) | ||
415 | return cgit_tree_link(name, title, class, ctx->qry.head, | ||
416 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
417 | ctx->qry.path); | ||
418 | else if (!strcmp(ctx->qry.page, "plain")) | ||
419 | return cgit_plain_link(name, title, class, ctx->qry.head, | ||
420 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
421 | ctx->qry.path); | ||
422 | else if (!strcmp(ctx->qry.page, "log")) | ||
423 | return cgit_log_link(name, title, class, ctx->qry.head, | ||
424 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
425 | ctx->qry.path, ctx->qry.ofs, | ||
426 | ctx->qry.grep, ctx->qry.search, | ||
427 | ctx->qry.showmsg); | ||
428 | else if (!strcmp(ctx->qry.page, "commit")) | ||
429 | return cgit_commit_link(name, title, class, ctx->qry.head, | ||
430 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
431 | ctx->qry.path, 0); | ||
432 | else if (!strcmp(ctx->qry.page, "patch")) | ||
433 | return cgit_patch_link(name, title, class, ctx->qry.head, | ||
434 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
435 | ctx->qry.path); | ||
436 | else if (!strcmp(ctx->qry.page, "refs")) | ||
437 | return cgit_refs_link(name, title, class, ctx->qry.head, | ||
438 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
439 | ctx->qry.path); | ||
440 | else if (!strcmp(ctx->qry.page, "snapshot")) | ||
441 | return cgit_snapshot_link(name, title, class, ctx->qry.head, | ||
442 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
443 | ctx->qry.path); | ||
444 | else if (!strcmp(ctx->qry.page, "diff")) | ||
445 | return cgit_diff_link(name, title, class, ctx->qry.head, | ||
446 | ctx->qry.sha1, ctx->qry.sha2, | ||
447 | ctx->qry.path, 0); | ||
448 | else if (!strcmp(ctx->qry.page, "stats")) | ||
449 | return cgit_stats_link(name, title, class, ctx->qry.head, | ||
450 | ctx->qry.path); | ||
451 | |||
452 | /* Don't known how to make link for this page */ | ||
453 | repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path); | ||
454 | html("><!-- cgit_self_link() doesn't know how to make link for page '"); | ||
455 | html_txt(ctx->qry.page); | ||
456 | html("' -->"); | ||
457 | html_txt(name); | ||
458 | html("</a>"); | ||
459 | } | ||
460 | |||
399 | void cgit_object_link(struct object *obj) | 461 | void cgit_object_link(struct object *obj) |
400 | { | 462 | { |
401 | char *page, *shortrev, *fullrev, *name; | 463 | char *page, *shortrev, *fullrev, *name; |
402 | 464 | ||
403 | fullrev = sha1_to_hex(obj->sha1); | 465 | fullrev = sha1_to_hex(obj->sha1); |
404 | shortrev = xstrdup(fullrev); | 466 | shortrev = xstrdup(fullrev); |
405 | shortrev[10] = '\0'; | 467 | shortrev[10] = '\0'; |
406 | if (obj->type == OBJ_COMMIT) { | 468 | if (obj->type == OBJ_COMMIT) { |
407 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, | 469 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, |
408 | ctx.qry.head, fullrev, 0); | 470 | ctx.qry.head, fullrev, NULL, 0); |
409 | return; | 471 | return; |
410 | } else if (obj->type == OBJ_TREE) | 472 | } else if (obj->type == OBJ_TREE) |
411 | page = "tree"; | 473 | page = "tree"; |
412 | else if (obj->type == OBJ_TAG) | 474 | else if (obj->type == OBJ_TAG) |
413 | page = "tag"; | 475 | page = "tag"; |
414 | else | 476 | else |
415 | page = "blob"; | 477 | page = "blob"; |
416 | name = fmt("%s %s...", typename(obj->type), shortrev); | 478 | name = fmt("%s %s...", typename(obj->type), shortrev); |
417 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); | 479 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); |
418 | } | 480 | } |
419 | 481 | ||
420 | void cgit_print_date(time_t secs, char *format, int local_time) | 482 | void cgit_print_date(time_t secs, const char *format, int local_time) |
421 | { | 483 | { |
422 | char buf[64]; | 484 | char buf[64]; |
423 | struct tm *time; | 485 | struct tm *time; |
424 | 486 | ||
425 | if (!secs) | 487 | if (!secs) |
426 | return; | 488 | return; |
427 | if(local_time) | 489 | if(local_time) |
428 | time = localtime(&secs); | 490 | time = localtime(&secs); |
429 | else | 491 | else |
430 | time = gmtime(&secs); | 492 | time = gmtime(&secs); |
431 | strftime(buf, sizeof(buf)-1, format, time); | 493 | strftime(buf, sizeof(buf)-1, format, time); |
432 | html_txt(buf); | 494 | html_txt(buf); |
433 | } | 495 | } |
434 | 496 | ||
435 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 497 | void cgit_print_age(time_t t, time_t max_relative, const char *format) |
436 | { | 498 | { |
437 | time_t now, secs; | 499 | time_t now, secs; |
438 | 500 | ||
439 | if (!t) | 501 | if (!t) |
440 | return; | 502 | return; |
441 | time(&now); | 503 | time(&now); |
442 | secs = now - t; | 504 | secs = now - t; |
443 | 505 | ||
444 | if (secs > max_relative && max_relative >= 0) { | 506 | if (secs > max_relative && max_relative >= 0) { |
445 | cgit_print_date(t, format, ctx.cfg.local_time); | 507 | cgit_print_date(t, format, ctx.cfg.local_time); |
446 | return; | 508 | return; |
447 | } | 509 | } |
448 | 510 | ||
449 | if (secs < TM_HOUR * 2) { | 511 | if (secs < TM_HOUR * 2) { |
450 | htmlf("<span class='age-mins'>%.0f min.</span>", | 512 | htmlf("<span class='age-mins'>%.0f min.</span>", |
451 | secs * 1.0 / TM_MIN); | 513 | secs * 1.0 / TM_MIN); |
@@ -518,33 +580,33 @@ void cgit_print_docstart(struct cgit_context *ctx) | |||
518 | html("</title>\n"); | 580 | html("</title>\n"); |
519 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 581 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
520 | if (ctx->cfg.robots && *ctx->cfg.robots) | 582 | if (ctx->cfg.robots && *ctx->cfg.robots) |
521 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); | 583 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
522 | html("<link rel='stylesheet' type='text/css' href='"); | 584 | html("<link rel='stylesheet' type='text/css' href='"); |
523 | html_attr(ctx->cfg.css); | 585 | html_attr(ctx->cfg.css); |
524 | html("'/>\n"); | 586 | html("'/>\n"); |
525 | if (ctx->cfg.favicon) { | 587 | if (ctx->cfg.favicon) { |
526 | html("<link rel='shortcut icon' href='"); | 588 | html("<link rel='shortcut icon' href='"); |
527 | html_attr(ctx->cfg.favicon); | 589 | html_attr(ctx->cfg.favicon); |
528 | html("'/>\n"); | 590 | html("'/>\n"); |
529 | } | 591 | } |
530 | if (host && ctx->repo) { | 592 | if (host && ctx->repo) { |
531 | html("<link rel='alternate' title='Atom feed' href='"); | 593 | html("<link rel='alternate' title='Atom feed' href='"); |
532 | html(cgit_httpscheme()); | 594 | html(cgit_httpscheme()); |
533 | html_attr(cgit_hosturl()); | 595 | html_attr(cgit_hosturl()); |
534 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, | 596 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.vpath, |
535 | fmt("h=%s", ctx->qry.head))); | 597 | fmt("h=%s", ctx->qry.head))); |
536 | html("' type='application/atom+xml'/>\n"); | 598 | html("' type='application/atom+xml'/>\n"); |
537 | } | 599 | } |
538 | if (ctx->cfg.head_include) | 600 | if (ctx->cfg.head_include) |
539 | html_include(ctx->cfg.head_include); | 601 | html_include(ctx->cfg.head_include); |
540 | html("</head>\n"); | 602 | html("</head>\n"); |
541 | html("<body>\n"); | 603 | html("<body>\n"); |
542 | if (ctx->cfg.header) | 604 | if (ctx->cfg.header) |
543 | html_include(ctx->cfg.header); | 605 | html_include(ctx->cfg.header); |
544 | } | 606 | } |
545 | 607 | ||
546 | void cgit_print_docend() | 608 | void cgit_print_docend() |
547 | { | 609 | { |
548 | html("</div> <!-- class=content -->\n"); | 610 | html("</div> <!-- class=content -->\n"); |
549 | if (ctx.cfg.embedded) { | 611 | if (ctx.cfg.embedded) { |
550 | html("</div> <!-- id=cgit -->\n"); | 612 | html("</div> <!-- id=cgit -->\n"); |
@@ -598,67 +660,87 @@ int print_archive_ref(const char *refname, const unsigned char *sha1, | |||
598 | } else { | 660 | } else { |
599 | hashcpy(fileid, sha1); | 661 | hashcpy(fileid, sha1); |
600 | } | 662 | } |
601 | if (!*header) { | 663 | if (!*header) { |
602 | html("<h1>download</h1>\n"); | 664 | html("<h1>download</h1>\n"); |
603 | *header = 1; | 665 | *header = 1; |
604 | } | 666 | } |
605 | url = cgit_pageurl(ctx.qry.repo, "blob", | 667 | url = cgit_pageurl(ctx.qry.repo, "blob", |
606 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 668 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
607 | buf)); | 669 | buf)); |
608 | html_link_open(url, NULL, "menu"); | 670 | html_link_open(url, NULL, "menu"); |
609 | html_txt(strlpart(buf, 20)); | 671 | html_txt(strlpart(buf, 20)); |
610 | html_link_close(); | 672 | html_link_close(); |
611 | return 0; | 673 | return 0; |
612 | } | 674 | } |
613 | 675 | ||
614 | void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page) | 676 | void cgit_add_hidden_formfields(int incl_head, int incl_search, |
677 | const char *page) | ||
615 | { | 678 | { |
616 | char *url; | 679 | char *url; |
617 | 680 | ||
618 | if (!ctx.cfg.virtual_root) { | 681 | if (!ctx.cfg.virtual_root) { |
619 | url = fmt("%s/%s", ctx.qry.repo, page); | 682 | url = fmt("%s/%s", ctx.qry.repo, page); |
620 | if (ctx.qry.path) | 683 | if (ctx.qry.vpath) |
621 | url = fmt("%s/%s", url, ctx.qry.path); | 684 | url = fmt("%s/%s", url, ctx.qry.vpath); |
622 | html_hidden("url", url); | 685 | html_hidden("url", url); |
623 | } | 686 | } |
624 | 687 | ||
625 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && | 688 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && |
626 | strcmp(ctx.qry.head, ctx.repo->defbranch)) | 689 | strcmp(ctx.qry.head, ctx.repo->defbranch)) |
627 | html_hidden("h", ctx.qry.head); | 690 | html_hidden("h", ctx.qry.head); |
628 | 691 | ||
629 | if (ctx.qry.sha1) | 692 | if (ctx.qry.sha1) |
630 | html_hidden("id", ctx.qry.sha1); | 693 | html_hidden("id", ctx.qry.sha1); |
631 | if (ctx.qry.sha2) | 694 | if (ctx.qry.sha2) |
632 | html_hidden("id2", ctx.qry.sha2); | 695 | html_hidden("id2", ctx.qry.sha2); |
633 | if (ctx.qry.showmsg) | 696 | if (ctx.qry.showmsg) |
634 | html_hidden("showmsg", "1"); | 697 | html_hidden("showmsg", "1"); |
635 | 698 | ||
636 | if (incl_search) { | 699 | if (incl_search) { |
637 | if (ctx.qry.grep) | 700 | if (ctx.qry.grep) |
638 | html_hidden("qt", ctx.qry.grep); | 701 | html_hidden("qt", ctx.qry.grep); |
639 | if (ctx.qry.search) | 702 | if (ctx.qry.search) |
640 | html_hidden("q", ctx.qry.search); | 703 | html_hidden("q", ctx.qry.search); |
641 | } | 704 | } |
642 | } | 705 | } |
643 | 706 | ||
644 | const char *fallback_cmd = "repolist"; | 707 | static const char *hc(struct cgit_context *ctx, const char *page) |
708 | { | ||
709 | return strcmp(ctx->qry.page, page) ? NULL : "active"; | ||
710 | } | ||
645 | 711 | ||
646 | char *hc(struct cgit_cmd *cmd, const char *page) | 712 | static void cgit_print_path_crumbs(struct cgit_context *ctx, char *path) |
647 | { | 713 | { |
648 | return (strcmp(cmd ? cmd->name : fallback_cmd, page) ? NULL : "active"); | 714 | char *old_path = ctx->qry.path; |
715 | char *p = path, *q, *end = path + strlen(path); | ||
716 | |||
717 | ctx->qry.path = NULL; | ||
718 | cgit_self_link("root", NULL, NULL, ctx); | ||
719 | ctx->qry.path = p = path; | ||
720 | while (p < end) { | ||
721 | if (!(q = strchr(p, '/'))) | ||
722 | q = end; | ||
723 | *q = '\0'; | ||
724 | html_txt("/"); | ||
725 | cgit_self_link(p, NULL, NULL, ctx); | ||
726 | if (q < end) | ||
727 | *q = '/'; | ||
728 | p = q + 1; | ||
729 | } | ||
730 | ctx->qry.path = old_path; | ||
649 | } | 731 | } |
650 | 732 | ||
651 | static void print_header(struct cgit_context *ctx) | 733 | static void print_header(struct cgit_context *ctx) |
652 | { | 734 | { |
653 | html("<table id='header'>\n"); | 735 | html("<table id='header'>\n"); |
654 | html("<tr>\n"); | 736 | html("<tr>\n"); |
655 | 737 | ||
656 | if (ctx->cfg.logo && ctx->cfg.logo[0] != 0) { | 738 | if (ctx->cfg.logo && ctx->cfg.logo[0] != 0) { |
657 | html("<td class='logo' rowspan='2'><a href='"); | 739 | html("<td class='logo' rowspan='2'><a href='"); |
658 | if (ctx->cfg.logo_link) | 740 | if (ctx->cfg.logo_link) |
659 | html_attr(ctx->cfg.logo_link); | 741 | html_attr(ctx->cfg.logo_link); |
660 | else | 742 | else |
661 | html_attr(cgit_rooturl()); | 743 | html_attr(cgit_rooturl()); |
662 | html("'><img src='"); | 744 | html("'><img src='"); |
663 | html_attr(ctx->cfg.logo); | 745 | html_attr(ctx->cfg.logo); |
664 | html("' alt='cgit logo'/></a></td>\n"); | 746 | html("' alt='cgit logo'/></a></td>\n"); |
@@ -684,95 +766,97 @@ static void print_header(struct cgit_context *ctx) | |||
684 | html("<tr><td class='sub'>"); | 766 | html("<tr><td class='sub'>"); |
685 | if (ctx->repo) { | 767 | if (ctx->repo) { |
686 | html_txt(ctx->repo->desc); | 768 | html_txt(ctx->repo->desc); |
687 | html("</td><td class='sub right'>"); | 769 | html("</td><td class='sub right'>"); |
688 | html_txt(ctx->repo->owner); | 770 | html_txt(ctx->repo->owner); |
689 | } else { | 771 | } else { |
690 | if (ctx->cfg.root_desc) | 772 | if (ctx->cfg.root_desc) |
691 | html_txt(ctx->cfg.root_desc); | 773 | html_txt(ctx->cfg.root_desc); |
692 | else if (ctx->cfg.index_info) | 774 | else if (ctx->cfg.index_info) |
693 | html_include(ctx->cfg.index_info); | 775 | html_include(ctx->cfg.index_info); |
694 | } | 776 | } |
695 | html("</td></tr></table>\n"); | 777 | html("</td></tr></table>\n"); |
696 | } | 778 | } |
697 | 779 | ||
698 | void cgit_print_pageheader(struct cgit_context *ctx) | 780 | void cgit_print_pageheader(struct cgit_context *ctx) |
699 | { | 781 | { |
700 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); | ||
701 | |||
702 | if (!cmd && ctx->repo) | ||
703 | fallback_cmd = "summary"; | ||
704 | |||
705 | html("<div id='cgit'>"); | 782 | html("<div id='cgit'>"); |
706 | if (!ctx->cfg.noheader) | 783 | if (!ctx->cfg.noheader) |
707 | print_header(ctx); | 784 | print_header(ctx); |
708 | 785 | ||
709 | html("<table class='tabs'><tr><td>\n"); | 786 | html("<table class='tabs'><tr><td>\n"); |
710 | if (ctx->repo) { | 787 | if (ctx->repo) { |
711 | cgit_summary_link("summary", NULL, hc(cmd, "summary"), | 788 | cgit_summary_link("summary", NULL, hc(ctx, "summary"), |
712 | ctx->qry.head); | 789 | ctx->qry.head); |
713 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, | 790 | cgit_refs_link("refs", NULL, hc(ctx, "refs"), ctx->qry.head, |
714 | ctx->qry.sha1, NULL); | ||
715 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, | ||
716 | NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg); | ||
717 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, | ||
718 | ctx->qry.sha1, NULL); | 791 | ctx->qry.sha1, NULL); |
719 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), | 792 | cgit_log_link("log", NULL, hc(ctx, "log"), ctx->qry.head, |
720 | ctx->qry.head, ctx->qry.sha1, 0); | 793 | NULL, ctx->qry.vpath, 0, NULL, NULL, |
721 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, | 794 | ctx->qry.showmsg); |
722 | ctx->qry.sha1, ctx->qry.sha2, NULL, 0); | 795 | cgit_tree_link("tree", NULL, hc(ctx, "tree"), ctx->qry.head, |
796 | ctx->qry.sha1, ctx->qry.vpath); | ||
797 | cgit_commit_link("commit", NULL, hc(ctx, "commit"), | ||
798 | ctx->qry.head, ctx->qry.sha1, ctx->qry.vpath, 0); | ||
799 | cgit_diff_link("diff", NULL, hc(ctx, "diff"), ctx->qry.head, | ||
800 | ctx->qry.sha1, ctx->qry.sha2, ctx->qry.vpath, 0); | ||
723 | if (ctx->repo->max_stats) | 801 | if (ctx->repo->max_stats) |
724 | cgit_stats_link("stats", NULL, hc(cmd, "stats"), | 802 | cgit_stats_link("stats", NULL, hc(ctx, "stats"), |
725 | ctx->qry.head, NULL); | 803 | ctx->qry.head, ctx->qry.vpath); |
726 | if (ctx->repo->readme) | 804 | if (ctx->repo->readme) |
727 | reporevlink("about", "about", NULL, | 805 | reporevlink("about", "about", NULL, |
728 | hc(cmd, "about"), ctx->qry.head, NULL, | 806 | hc(ctx, "about"), ctx->qry.head, NULL, |
729 | NULL); | 807 | NULL); |
730 | html("</td><td class='form'>"); | 808 | html("</td><td class='form'>"); |
731 | html("<form class='right' method='get' action='"); | 809 | html("<form class='right' method='get' action='"); |
732 | if (ctx->cfg.virtual_root) | 810 | if (ctx->cfg.virtual_root) |
733 | html_url_path(cgit_fileurl(ctx->qry.repo, "log", | 811 | html_url_path(cgit_fileurl(ctx->qry.repo, "log", |
734 | ctx->qry.path, NULL)); | 812 | ctx->qry.vpath, NULL)); |
735 | html("'>\n"); | 813 | html("'>\n"); |
736 | cgit_add_hidden_formfields(1, 0, "log"); | 814 | cgit_add_hidden_formfields(1, 0, "log"); |
737 | html("<select name='qt'>\n"); | 815 | html("<select name='qt'>\n"); |
738 | html_option("grep", "log msg", ctx->qry.grep); | 816 | html_option("grep", "log msg", ctx->qry.grep); |
739 | html_option("author", "author", ctx->qry.grep); | 817 | html_option("author", "author", ctx->qry.grep); |
740 | html_option("committer", "committer", ctx->qry.grep); | 818 | html_option("committer", "committer", ctx->qry.grep); |
741 | html("</select>\n"); | 819 | html("</select>\n"); |
742 | html("<input class='txt' type='text' size='10' name='q' value='"); | 820 | html("<input class='txt' type='text' size='10' name='q' value='"); |
743 | html_attr(ctx->qry.search); | 821 | html_attr(ctx->qry.search); |
744 | html("'/>\n"); | 822 | html("'/>\n"); |
745 | html("<input type='submit' value='search'/>\n"); | 823 | html("<input type='submit' value='search'/>\n"); |
746 | html("</form>\n"); | 824 | html("</form>\n"); |
747 | } else { | 825 | } else { |
748 | site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0); | 826 | site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0); |
749 | if (ctx->cfg.root_readme) | 827 | if (ctx->cfg.root_readme) |
750 | site_link("about", "about", NULL, hc(cmd, "about"), | 828 | site_link("about", "about", NULL, hc(ctx, "about"), |
751 | NULL, 0); | 829 | NULL, 0); |
752 | html("</td><td class='form'>"); | 830 | html("</td><td class='form'>"); |
753 | html("<form method='get' action='"); | 831 | html("<form method='get' action='"); |
754 | html_attr(cgit_rooturl()); | 832 | html_attr(cgit_rooturl()); |
755 | html("'>\n"); | 833 | html("'>\n"); |
756 | html("<input type='text' name='q' size='10' value='"); | 834 | html("<input type='text' name='q' size='10' value='"); |
757 | html_attr(ctx->qry.search); | 835 | html_attr(ctx->qry.search); |
758 | html("'/>\n"); | 836 | html("'/>\n"); |
759 | html("<input type='submit' value='search'/>\n"); | 837 | html("<input type='submit' value='search'/>\n"); |
760 | html("</form>"); | 838 | html("</form>"); |
761 | } | 839 | } |
762 | html("</td></tr></table>\n"); | 840 | html("</td></tr></table>\n"); |
841 | if (ctx->qry.vpath) { | ||
842 | html("<div class='path'>"); | ||
843 | html("path: "); | ||
844 | cgit_print_path_crumbs(ctx, ctx->qry.vpath); | ||
845 | html("</div>"); | ||
846 | } | ||
763 | html("<div class='content'>"); | 847 | html("<div class='content'>"); |
764 | } | 848 | } |
765 | 849 | ||
766 | void cgit_print_filemode(unsigned short mode) | 850 | void cgit_print_filemode(unsigned short mode) |
767 | { | 851 | { |
768 | if (S_ISDIR(mode)) | 852 | if (S_ISDIR(mode)) |
769 | html("d"); | 853 | html("d"); |
770 | else if (S_ISLNK(mode)) | 854 | else if (S_ISLNK(mode)) |
771 | html("l"); | 855 | html("l"); |
772 | else if (S_ISGITLINK(mode)) | 856 | else if (S_ISGITLINK(mode)) |
773 | html("m"); | 857 | html("m"); |
774 | else | 858 | else |
775 | html("-"); | 859 | html("-"); |
776 | html_fileperm(mode >> 6); | 860 | html_fileperm(mode >> 6); |
777 | html_fileperm(mode >> 3); | 861 | html_fileperm(mode >> 3); |
778 | html_fileperm(mode); | 862 | html_fileperm(mode); |