-rw-r--r-- | ui-shared.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/ui-shared.c b/ui-shared.c index 224e5f3..95dfeb4 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -260,72 +260,78 @@ static void reporevlink(char *page, char *name, char *title, char *class, | |||
260 | void cgit_summary_link(char *name, char *title, char *class, char *head) | 260 | void cgit_summary_link(char *name, char *title, char *class, char *head) |
261 | { | 261 | { |
262 | reporevlink(NULL, name, title, class, head, NULL, NULL); | 262 | reporevlink(NULL, name, title, class, head, NULL, NULL); |
263 | } | 263 | } |
264 | 264 | ||
265 | void cgit_tag_link(char *name, char *title, char *class, char *head, | 265 | void cgit_tag_link(char *name, char *title, char *class, char *head, |
266 | char *rev) | 266 | char *rev) |
267 | { | 267 | { |
268 | reporevlink("tag", name, title, class, head, rev, NULL); | 268 | reporevlink("tag", name, title, class, head, rev, NULL); |
269 | } | 269 | } |
270 | 270 | ||
271 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 271 | void cgit_tree_link(char *name, char *title, char *class, char *head, |
272 | char *rev, char *path) | 272 | char *rev, char *path) |
273 | { | 273 | { |
274 | reporevlink("tree", name, title, class, head, rev, path); | 274 | reporevlink("tree", name, title, class, head, rev, path); |
275 | } | 275 | } |
276 | 276 | ||
277 | void cgit_plain_link(char *name, char *title, char *class, char *head, | 277 | void cgit_plain_link(char *name, char *title, char *class, char *head, |
278 | char *rev, char *path) | 278 | char *rev, char *path) |
279 | { | 279 | { |
280 | reporevlink("plain", name, title, class, head, rev, path); | 280 | reporevlink("plain", name, title, class, head, rev, path); |
281 | } | 281 | } |
282 | 282 | ||
283 | void cgit_log_link(char *name, char *title, char *class, char *head, | 283 | void cgit_log_link(char *name, char *title, char *class, char *head, |
284 | char *rev, char *path, int ofs, char *grep, char *pattern) | 284 | char *rev, char *path, int ofs, char *grep, char *pattern, |
285 | int showmsg) | ||
285 | { | 286 | { |
286 | char *delim; | 287 | char *delim; |
287 | 288 | ||
288 | delim = repolink(title, class, "log", head, path); | 289 | delim = repolink(title, class, "log", head, path); |
289 | if (rev && strcmp(rev, ctx.qry.head)) { | 290 | if (rev && strcmp(rev, ctx.qry.head)) { |
290 | html(delim); | 291 | html(delim); |
291 | html("id="); | 292 | html("id="); |
292 | html_url_arg(rev); | 293 | html_url_arg(rev); |
293 | delim = "&"; | 294 | delim = "&"; |
294 | } | 295 | } |
295 | if (grep && pattern) { | 296 | if (grep && pattern) { |
296 | html(delim); | 297 | html(delim); |
297 | html("qt="); | 298 | html("qt="); |
298 | html_url_arg(grep); | 299 | html_url_arg(grep); |
299 | delim = "&"; | 300 | delim = "&"; |
300 | html(delim); | 301 | html(delim); |
301 | html("q="); | 302 | html("q="); |
302 | html_url_arg(pattern); | 303 | html_url_arg(pattern); |
303 | } | 304 | } |
304 | if (ofs > 0) { | 305 | if (ofs > 0) { |
305 | html(delim); | 306 | html(delim); |
306 | html("ofs="); | 307 | html("ofs="); |
307 | htmlf("%d", ofs); | 308 | htmlf("%d", ofs); |
309 | delim = "&"; | ||
310 | } | ||
311 | if (showmsg) { | ||
312 | html(delim); | ||
313 | html("showmsg=1"); | ||
308 | } | 314 | } |
309 | html("'>"); | 315 | html("'>"); |
310 | html_txt(name); | 316 | html_txt(name); |
311 | html("</a>"); | 317 | html("</a>"); |
312 | } | 318 | } |
313 | 319 | ||
314 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 320 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
315 | char *rev) | 321 | char *rev) |
316 | { | 322 | { |
317 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { | 323 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { |
318 | name[ctx.cfg.max_msg_len] = '\0'; | 324 | name[ctx.cfg.max_msg_len] = '\0'; |
319 | name[ctx.cfg.max_msg_len - 1] = '.'; | 325 | name[ctx.cfg.max_msg_len - 1] = '.'; |
320 | name[ctx.cfg.max_msg_len - 2] = '.'; | 326 | name[ctx.cfg.max_msg_len - 2] = '.'; |
321 | name[ctx.cfg.max_msg_len - 3] = '.'; | 327 | name[ctx.cfg.max_msg_len - 3] = '.'; |
322 | } | 328 | } |
323 | reporevlink("commit", name, title, class, head, rev, NULL); | 329 | reporevlink("commit", name, title, class, head, rev, NULL); |
324 | } | 330 | } |
325 | 331 | ||
326 | void cgit_refs_link(char *name, char *title, char *class, char *head, | 332 | void cgit_refs_link(char *name, char *title, char *class, char *head, |
327 | char *rev, char *path) | 333 | char *rev, char *path) |
328 | { | 334 | { |
329 | reporevlink("refs", name, title, class, head, rev, path); | 335 | reporevlink("refs", name, title, class, head, rev, path); |
330 | } | 336 | } |
331 | 337 | ||
@@ -344,63 +350,65 @@ void cgit_diff_link(char *name, char *title, char *class, char *head, | |||
344 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { | 350 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { |
345 | html(delim); | 351 | html(delim); |
346 | html("id="); | 352 | html("id="); |
347 | html_url_arg(new_rev); | 353 | html_url_arg(new_rev); |
348 | delim = "&"; | 354 | delim = "&"; |
349 | } | 355 | } |
350 | if (old_rev) { | 356 | if (old_rev) { |
351 | html(delim); | 357 | html(delim); |
352 | html("id2="); | 358 | html("id2="); |
353 | html_url_arg(old_rev); | 359 | html_url_arg(old_rev); |
354 | } | 360 | } |
355 | html("'>"); | 361 | html("'>"); |
356 | html_txt(name); | 362 | html_txt(name); |
357 | html("</a>"); | 363 | html("</a>"); |
358 | } | 364 | } |
359 | 365 | ||
360 | void cgit_patch_link(char *name, char *title, char *class, char *head, | 366 | void cgit_patch_link(char *name, char *title, char *class, char *head, |
361 | char *rev) | 367 | char *rev) |
362 | { | 368 | { |
363 | reporevlink("patch", name, title, class, head, rev, NULL); | 369 | reporevlink("patch", name, title, class, head, rev, NULL); |
364 | } | 370 | } |
365 | 371 | ||
366 | void cgit_object_link(struct object *obj) | 372 | void cgit_object_link(struct object *obj) |
367 | { | 373 | { |
368 | char *page, *rev, *name; | 374 | char *page, *shortrev, *fullrev, *name; |
369 | 375 | ||
376 | fullrev = sha1_to_hex(obj->sha1); | ||
377 | shortrev = xstrdup(fullrev); | ||
378 | shortrev[10] = '\0'; | ||
370 | if (obj->type == OBJ_COMMIT) { | 379 | if (obj->type == OBJ_COMMIT) { |
371 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 380 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, |
372 | ctx.qry.head, sha1_to_hex(obj->sha1)); | 381 | ctx.qry.head, fullrev); |
373 | return; | 382 | return; |
374 | } else if (obj->type == OBJ_TREE) | 383 | } else if (obj->type == OBJ_TREE) |
375 | page = "tree"; | 384 | page = "tree"; |
376 | else if (obj->type == OBJ_TAG) | 385 | else if (obj->type == OBJ_TAG) |
377 | page = "tag"; | 386 | page = "tag"; |
378 | else | 387 | else |
379 | page = "blob"; | 388 | page = "blob"; |
380 | rev = sha1_to_hex(obj->sha1); | 389 | name = fmt("%s %s...", typename(obj->type), shortrev); |
381 | name = fmt("%s %s", typename(obj->type), rev); | 390 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); |
382 | reporevlink(page, name, NULL, NULL, ctx.qry.head, rev, NULL); | ||
383 | } | 391 | } |
384 | 392 | ||
385 | void cgit_print_date(time_t secs, char *format, int local_time) | 393 | void cgit_print_date(time_t secs, char *format, int local_time) |
386 | { | 394 | { |
387 | char buf[64]; | 395 | char buf[64]; |
388 | struct tm *time; | 396 | struct tm *time; |
389 | 397 | ||
390 | if (!secs) | 398 | if (!secs) |
391 | return; | 399 | return; |
392 | if(local_time) | 400 | if(local_time) |
393 | time = localtime(&secs); | 401 | time = localtime(&secs); |
394 | else | 402 | else |
395 | time = gmtime(&secs); | 403 | time = gmtime(&secs); |
396 | strftime(buf, sizeof(buf)-1, format, time); | 404 | strftime(buf, sizeof(buf)-1, format, time); |
397 | html_txt(buf); | 405 | html_txt(buf); |
398 | } | 406 | } |
399 | 407 | ||
400 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 408 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
401 | { | 409 | { |
402 | time_t now, secs; | 410 | time_t now, secs; |
403 | 411 | ||
404 | if (!t) | 412 | if (!t) |
405 | return; | 413 | return; |
406 | time(&now); | 414 | time(&now); |
@@ -547,48 +555,50 @@ int print_archive_ref(const char *refname, const unsigned char *sha1, | |||
547 | html_txt(strlpart(buf, 20)); | 555 | html_txt(strlpart(buf, 20)); |
548 | html_link_close(); | 556 | html_link_close(); |
549 | return 0; | 557 | return 0; |
550 | } | 558 | } |
551 | 559 | ||
552 | void add_hidden_formfields(int incl_head, int incl_search, char *page) | 560 | void add_hidden_formfields(int incl_head, int incl_search, char *page) |
553 | { | 561 | { |
554 | char *url; | 562 | char *url; |
555 | 563 | ||
556 | if (!ctx.cfg.virtual_root) { | 564 | if (!ctx.cfg.virtual_root) { |
557 | url = fmt("%s/%s", ctx.qry.repo, page); | 565 | url = fmt("%s/%s", ctx.qry.repo, page); |
558 | if (ctx.qry.path) | 566 | if (ctx.qry.path) |
559 | url = fmt("%s/%s", url, ctx.qry.path); | 567 | url = fmt("%s/%s", url, ctx.qry.path); |
560 | html_hidden("url", url); | 568 | html_hidden("url", url); |
561 | } | 569 | } |
562 | 570 | ||
563 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && | 571 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && |
564 | strcmp(ctx.qry.head, ctx.repo->defbranch)) | 572 | strcmp(ctx.qry.head, ctx.repo->defbranch)) |
565 | html_hidden("h", ctx.qry.head); | 573 | html_hidden("h", ctx.qry.head); |
566 | 574 | ||
567 | if (ctx.qry.sha1) | 575 | if (ctx.qry.sha1) |
568 | html_hidden("id", ctx.qry.sha1); | 576 | html_hidden("id", ctx.qry.sha1); |
569 | if (ctx.qry.sha2) | 577 | if (ctx.qry.sha2) |
570 | html_hidden("id2", ctx.qry.sha2); | 578 | html_hidden("id2", ctx.qry.sha2); |
579 | if (ctx.qry.showmsg) | ||
580 | html_hidden("showmsg", "1"); | ||
571 | 581 | ||
572 | if (incl_search) { | 582 | if (incl_search) { |
573 | if (ctx.qry.grep) | 583 | if (ctx.qry.grep) |
574 | html_hidden("qt", ctx.qry.grep); | 584 | html_hidden("qt", ctx.qry.grep); |
575 | if (ctx.qry.search) | 585 | if (ctx.qry.search) |
576 | html_hidden("q", ctx.qry.search); | 586 | html_hidden("q", ctx.qry.search); |
577 | } | 587 | } |
578 | } | 588 | } |
579 | 589 | ||
580 | char *hc(struct cgit_cmd *cmd, const char *page) | 590 | char *hc(struct cgit_cmd *cmd, const char *page) |
581 | { | 591 | { |
582 | return (strcmp(cmd->name, page) ? NULL : "active"); | 592 | return (strcmp(cmd->name, page) ? NULL : "active"); |
583 | } | 593 | } |
584 | 594 | ||
585 | void cgit_print_pageheader(struct cgit_context *ctx) | 595 | void cgit_print_pageheader(struct cgit_context *ctx) |
586 | { | 596 | { |
587 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); | 597 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); |
588 | 598 | ||
589 | html("<table id='header'>\n"); | 599 | html("<table id='header'>\n"); |
590 | html("<tr>\n"); | 600 | html("<tr>\n"); |
591 | html("<td class='logo' rowspan='2'><a href='"); | 601 | html("<td class='logo' rowspan='2'><a href='"); |
592 | if (ctx->cfg.logo_link) | 602 | if (ctx->cfg.logo_link) |
593 | html_attr(ctx->cfg.logo_link); | 603 | html_attr(ctx->cfg.logo_link); |
594 | else | 604 | else |
@@ -613,49 +623,49 @@ void cgit_print_pageheader(struct cgit_context *ctx) | |||
613 | } else | 623 | } else |
614 | html_txt(ctx->cfg.root_title); | 624 | html_txt(ctx->cfg.root_title); |
615 | html("</td></tr>\n"); | 625 | html("</td></tr>\n"); |
616 | 626 | ||
617 | html("<tr><td class='sub'>"); | 627 | html("<tr><td class='sub'>"); |
618 | if (ctx->repo) { | 628 | if (ctx->repo) { |
619 | html_txt(ctx->repo->desc); | 629 | html_txt(ctx->repo->desc); |
620 | html("</td><td class='sub right'>"); | 630 | html("</td><td class='sub right'>"); |
621 | html_txt(ctx->repo->owner); | 631 | html_txt(ctx->repo->owner); |
622 | } else { | 632 | } else { |
623 | if (ctx->cfg.root_desc) | 633 | if (ctx->cfg.root_desc) |
624 | html_txt(ctx->cfg.root_desc); | 634 | html_txt(ctx->cfg.root_desc); |
625 | else if (ctx->cfg.index_info) | 635 | else if (ctx->cfg.index_info) |
626 | html_include(ctx->cfg.index_info); | 636 | html_include(ctx->cfg.index_info); |
627 | } | 637 | } |
628 | html("</td></tr></table>\n"); | 638 | html("</td></tr></table>\n"); |
629 | 639 | ||
630 | html("<table class='tabs'><tr><td>\n"); | 640 | html("<table class='tabs'><tr><td>\n"); |
631 | if (ctx->repo) { | 641 | if (ctx->repo) { |
632 | cgit_summary_link("summary", NULL, hc(cmd, "summary"), | 642 | cgit_summary_link("summary", NULL, hc(cmd, "summary"), |
633 | ctx->qry.head); | 643 | ctx->qry.head); |
634 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, | 644 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, |
635 | ctx->qry.sha1, NULL); | 645 | ctx->qry.sha1, NULL); |
636 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, | 646 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, |
637 | NULL, NULL, 0, NULL, NULL); | 647 | NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg); |
638 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, | 648 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, |
639 | ctx->qry.sha1, NULL); | 649 | ctx->qry.sha1, NULL); |
640 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), | 650 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), |
641 | ctx->qry.head, ctx->qry.sha1); | 651 | ctx->qry.head, ctx->qry.sha1); |
642 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, | 652 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, |
643 | ctx->qry.sha1, ctx->qry.sha2, NULL); | 653 | ctx->qry.sha1, ctx->qry.sha2, NULL); |
644 | if (ctx->repo->readme) | 654 | if (ctx->repo->readme) |
645 | reporevlink("about", "about", NULL, | 655 | reporevlink("about", "about", NULL, |
646 | hc(cmd, "about"), ctx->qry.head, NULL, | 656 | hc(cmd, "about"), ctx->qry.head, NULL, |
647 | NULL); | 657 | NULL); |
648 | html("</td><td class='form'>"); | 658 | html("</td><td class='form'>"); |
649 | html("<form class='right' method='get' action='"); | 659 | html("<form class='right' method='get' action='"); |
650 | if (ctx->cfg.virtual_root) | 660 | if (ctx->cfg.virtual_root) |
651 | html_url_path(cgit_fileurl(ctx->qry.repo, "log", | 661 | html_url_path(cgit_fileurl(ctx->qry.repo, "log", |
652 | ctx->qry.path, NULL)); | 662 | ctx->qry.path, NULL)); |
653 | html("'>\n"); | 663 | html("'>\n"); |
654 | add_hidden_formfields(1, 0, "log"); | 664 | add_hidden_formfields(1, 0, "log"); |
655 | html("<select name='qt'>\n"); | 665 | html("<select name='qt'>\n"); |
656 | html_option("grep", "log msg", ctx->qry.grep); | 666 | html_option("grep", "log msg", ctx->qry.grep); |
657 | html_option("author", "author", ctx->qry.grep); | 667 | html_option("author", "author", ctx->qry.grep); |
658 | html_option("committer", "committer", ctx->qry.grep); | 668 | html_option("committer", "committer", ctx->qry.grep); |
659 | html("</select>\n"); | 669 | html("</select>\n"); |
660 | html("<input class='txt' type='text' size='10' name='q' value='"); | 670 | html("<input class='txt' type='text' size='10' name='q' value='"); |
661 | html_attr(ctx->qry.search); | 671 | html_attr(ctx->qry.search); |
@@ -686,29 +696,28 @@ void cgit_print_filemode(unsigned short mode) | |||
686 | if (S_ISDIR(mode)) | 696 | if (S_ISDIR(mode)) |
687 | html("d"); | 697 | html("d"); |
688 | else if (S_ISLNK(mode)) | 698 | else if (S_ISLNK(mode)) |
689 | html("l"); | 699 | html("l"); |
690 | else if (S_ISGITLINK(mode)) | 700 | else if (S_ISGITLINK(mode)) |
691 | html("m"); | 701 | html("m"); |
692 | else | 702 | else |
693 | html("-"); | 703 | html("-"); |
694 | html_fileperm(mode >> 6); | 704 | html_fileperm(mode >> 6); |
695 | html_fileperm(mode >> 3); | 705 | html_fileperm(mode >> 3); |
696 | html_fileperm(mode); | 706 | html_fileperm(mode); |
697 | } | 707 | } |
698 | 708 | ||
699 | void cgit_print_snapshot_links(const char *repo, const char *head, | 709 | void cgit_print_snapshot_links(const char *repo, const char *head, |
700 | const char *hex, int snapshots) | 710 | const char *hex, int snapshots) |
701 | { | 711 | { |
702 | const struct cgit_snapshot_format* f; | 712 | const struct cgit_snapshot_format* f; |
703 | char *filename; | 713 | char *filename; |
704 | 714 | ||
705 | for (f = cgit_snapshot_formats; f->suffix; f++) { | 715 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
706 | if (!(snapshots & f->bit)) | 716 | if (!(snapshots & f->bit)) |
707 | continue; | 717 | continue; |
708 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, | 718 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, |
709 | f->suffix); | 719 | f->suffix); |
710 | cgit_snapshot_link(filename, NULL, NULL, (char *)head, | 720 | cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); |
711 | (char *)hex, filename); | ||
712 | html("<br/>"); | 721 | html("<br/>"); |
713 | } | 722 | } |
714 | } | 723 | } |