summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
Unidiff
Diffstat (limited to 'ui-shared.c') (more/less context) (show whitespace changes)
-rw-r--r--ui-shared.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 76cd00d..4f28512 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -272,48 +272,54 @@ 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
277void cgit_plain_link(char *name, char *title, char *class, char *head, 277void 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
283void cgit_log_link(char *name, char *title, char *class, char *head, 283void 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
314void cgit_commit_link(char *name, char *title, char *class, char *head, 320void 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] = '.';
@@ -354,41 +360,49 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
354 } 360 }
355 html("'>"); 361 html("'>");
356 html_txt(name); 362 html_txt(name);
357 html("</a>"); 363 html("</a>");
358} 364}
359 365
360void cgit_patch_link(char *name, char *title, char *class, char *head, 366void 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
372void cgit_stats_link(char *name, char *title, char *class, char *head,
373 char *path)
374{
375 reporevlink("stats", name, title, class, head, NULL, path);
376}
377
366void cgit_object_link(struct object *obj) 378void cgit_object_link(struct object *obj)
367{ 379{
368 char *page, *rev, *name; 380 char *page, *shortrev, *fullrev, *name;
369 381
382 fullrev = sha1_to_hex(obj->sha1);
383 shortrev = xstrdup(fullrev);
384 shortrev[10] = '\0';
370 if (obj->type == OBJ_COMMIT) { 385 if (obj->type == OBJ_COMMIT) {
371 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, 386 cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
372 ctx.qry.head, sha1_to_hex(obj->sha1)); 387 ctx.qry.head, fullrev);
373 return; 388 return;
374 } else if (obj->type == OBJ_TREE) 389 } else if (obj->type == OBJ_TREE)
375 page = "tree"; 390 page = "tree";
376 else if (obj->type == OBJ_TAG) 391 else if (obj->type == OBJ_TAG)
377 page = "tag"; 392 page = "tag";
378 else 393 else
379 page = "blob"; 394 page = "blob";
380 rev = sha1_to_hex(obj->sha1); 395 name = fmt("%s %s...", typename(obj->type), shortrev);
381 name = fmt("%s %s", typename(obj->type), rev); 396 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
382 reporevlink(page, name, NULL, NULL, ctx.qry.head, rev, NULL);
383} 397}
384 398
385void cgit_print_date(time_t secs, char *format, int local_time) 399void cgit_print_date(time_t secs, char *format, int local_time)
386{ 400{
387 char buf[64]; 401 char buf[64];
388 struct tm *time; 402 struct tm *time;
389 403
390 if (!secs) 404 if (!secs)
391 return; 405 return;
392 if(local_time) 406 if(local_time)
393 time = localtime(&secs); 407 time = localtime(&secs);
394 else 408 else
@@ -540,43 +554,45 @@ int print_archive_ref(const char *refname, const unsigned char *sha1,
540 html("<h1>download</h1>\n"); 554 html("<h1>download</h1>\n");
541 *header = 1; 555 *header = 1;
542 } 556 }
543 url = cgit_pageurl(ctx.qry.repo, "blob", 557 url = cgit_pageurl(ctx.qry.repo, "blob",
544 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 558 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
545 buf)); 559 buf));
546 html_link_open(url, NULL, "menu"); 560 html_link_open(url, NULL, "menu");
547 html_txt(strlpart(buf, 20)); 561 html_txt(strlpart(buf, 20));
548 html_link_close(); 562 html_link_close();
549 return 0; 563 return 0;
550} 564}
551 565
552void add_hidden_formfields(int incl_head, int incl_search, char *page) 566void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page)
553{ 567{
554 char *url; 568 char *url;
555 569
556 if (!ctx.cfg.virtual_root) { 570 if (!ctx.cfg.virtual_root) {
557 url = fmt("%s/%s", ctx.qry.repo, page); 571 url = fmt("%s/%s", ctx.qry.repo, page);
558 if (ctx.qry.path) 572 if (ctx.qry.path)
559 url = fmt("%s/%s", url, ctx.qry.path); 573 url = fmt("%s/%s", url, ctx.qry.path);
560 html_hidden("url", url); 574 html_hidden("url", url);
561 } 575 }
562 576
563 if (incl_head && ctx.qry.head && ctx.repo->defbranch && 577 if (incl_head && ctx.qry.head && ctx.repo->defbranch &&
564 strcmp(ctx.qry.head, ctx.repo->defbranch)) 578 strcmp(ctx.qry.head, ctx.repo->defbranch))
565 html_hidden("h", ctx.qry.head); 579 html_hidden("h", ctx.qry.head);
566 580
567 if (ctx.qry.sha1) 581 if (ctx.qry.sha1)
568 html_hidden("id", ctx.qry.sha1); 582 html_hidden("id", ctx.qry.sha1);
569 if (ctx.qry.sha2) 583 if (ctx.qry.sha2)
570 html_hidden("id2", ctx.qry.sha2); 584 html_hidden("id2", ctx.qry.sha2);
585 if (ctx.qry.showmsg)
586 html_hidden("showmsg", "1");
571 587
572 if (incl_search) { 588 if (incl_search) {
573 if (ctx.qry.grep) 589 if (ctx.qry.grep)
574 html_hidden("qt", ctx.qry.grep); 590 html_hidden("qt", ctx.qry.grep);
575 if (ctx.qry.search) 591 if (ctx.qry.search)
576 html_hidden("q", ctx.qry.search); 592 html_hidden("q", ctx.qry.search);
577 } 593 }
578} 594}
579 595
580const char *fallback_cmd = "repolist"; 596const char *fallback_cmd = "repolist";
581 597
582char *hc(struct cgit_cmd *cmd, const char *page) 598char *hc(struct cgit_cmd *cmd, const char *page)
@@ -600,25 +616,25 @@ void cgit_print_pageheader(struct cgit_context *ctx)
600 html_attr(cgit_rooturl()); 616 html_attr(cgit_rooturl());
601 html("'><img src='"); 617 html("'><img src='");
602 html_attr(ctx->cfg.logo); 618 html_attr(ctx->cfg.logo);
603 html("' alt='cgit logo'/></a></td>\n"); 619 html("' alt='cgit logo'/></a></td>\n");
604 620
605 html("<td class='main'>"); 621 html("<td class='main'>");
606 if (ctx->repo) { 622 if (ctx->repo) {
607 cgit_index_link("index", NULL, NULL, NULL, 0); 623 cgit_index_link("index", NULL, NULL, NULL, 0);
608 html(" : "); 624 html(" : ");
609 cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); 625 cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL);
610 html("</td><td class='form'>"); 626 html("</td><td class='form'>");
611 html("<form method='get' action=''>\n"); 627 html("<form method='get' action=''>\n");
612 add_hidden_formfields(0, 1, ctx->qry.page); 628 cgit_add_hidden_formfields(0, 1, ctx->qry.page);
613 html("<select name='h' onchange='this.form.submit();'>\n"); 629 html("<select name='h' onchange='this.form.submit();'>\n");
614 for_each_branch_ref(print_branch_option, ctx->qry.head); 630 for_each_branch_ref(print_branch_option, ctx->qry.head);
615 html("</select> "); 631 html("</select> ");
616 html("<input type='submit' name='' value='switch'/>"); 632 html("<input type='submit' name='' value='switch'/>");
617 html("</form>"); 633 html("</form>");
618 } else 634 } else
619 html_txt(ctx->cfg.root_title); 635 html_txt(ctx->cfg.root_title);
620 html("</td></tr>\n"); 636 html("</td></tr>\n");
621 637
622 html("<tr><td class='sub'>"); 638 html("<tr><td class='sub'>");
623 if (ctx->repo) { 639 if (ctx->repo) {
624 html_txt(ctx->repo->desc); 640 html_txt(ctx->repo->desc);
@@ -630,42 +646,45 @@ void cgit_print_pageheader(struct cgit_context *ctx)
630 else if (ctx->cfg.index_info) 646 else if (ctx->cfg.index_info)
631 html_include(ctx->cfg.index_info); 647 html_include(ctx->cfg.index_info);
632 } 648 }
633 html("</td></tr></table>\n"); 649 html("</td></tr></table>\n");
634 650
635 html("<table class='tabs'><tr><td>\n"); 651 html("<table class='tabs'><tr><td>\n");
636 if (ctx->repo) { 652 if (ctx->repo) {
637 cgit_summary_link("summary", NULL, hc(cmd, "summary"), 653 cgit_summary_link("summary", NULL, hc(cmd, "summary"),
638 ctx->qry.head); 654 ctx->qry.head);
639 cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, 655 cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head,
640 ctx->qry.sha1, NULL); 656 ctx->qry.sha1, NULL);
641 cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, 657 cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head,
642 NULL, NULL, 0, NULL, NULL); 658 NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg);
643 cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, 659 cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head,
644 ctx->qry.sha1, NULL); 660 ctx->qry.sha1, NULL);
645 cgit_commit_link("commit", NULL, hc(cmd, "commit"), 661 cgit_commit_link("commit", NULL, hc(cmd, "commit"),
646 ctx->qry.head, ctx->qry.sha1); 662 ctx->qry.head, ctx->qry.sha1);
647 cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, 663 cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head,
648 ctx->qry.sha1, ctx->qry.sha2, NULL); 664 ctx->qry.sha1, ctx->qry.sha2, NULL);
665 if (ctx->repo->max_stats)
666 cgit_stats_link("stats", NULL, hc(cmd, "stats"),
667 ctx->qry.head, NULL);
649 if (ctx->repo->readme) 668 if (ctx->repo->readme)
650 reporevlink("about", "about", NULL, 669 reporevlink("about", "about", NULL,
651 hc(cmd, "about"), ctx->qry.head, NULL, 670 hc(cmd, "about"), ctx->qry.head, NULL,
652 NULL); 671 NULL);
653 html("</td><td class='form'>"); 672 html("</td><td class='form'>");
654 html("<form class='right' method='get' action='"); 673 html("<form class='right' method='get' action='");
655 if (ctx->cfg.virtual_root) 674 if (ctx->cfg.virtual_root)
656 html_url_path(cgit_fileurl(ctx->qry.repo, "log", 675 html_url_path(cgit_fileurl(ctx->qry.repo, "log",
657 ctx->qry.path, NULL)); 676 ctx->qry.path, NULL));
658 html("'>\n"); 677 html("'>\n");
659 add_hidden_formfields(1, 0, "log"); 678 cgit_add_hidden_formfields(1, 0, "log");
660 html("<select name='qt'>\n"); 679 html("<select name='qt'>\n");
661 html_option("grep", "log msg", ctx->qry.grep); 680 html_option("grep", "log msg", ctx->qry.grep);
662 html_option("author", "author", ctx->qry.grep); 681 html_option("author", "author", ctx->qry.grep);
663 html_option("committer", "committer", ctx->qry.grep); 682 html_option("committer", "committer", ctx->qry.grep);
664 html("</select>\n"); 683 html("</select>\n");
665 html("<input class='txt' type='text' size='10' name='q' value='"); 684 html("<input class='txt' type='text' size='10' name='q' value='");
666 html_attr(ctx->qry.search); 685 html_attr(ctx->qry.search);
667 html("'/>\n"); 686 html("'/>\n");
668 html("<input type='submit' value='search'/>\n"); 687 html("<input type='submit' value='search'/>\n");
669 html("</form>\n"); 688 html("</form>\n");
670 } else { 689 } else {
671 site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0); 690 site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0);
@@ -703,17 +722,16 @@ void cgit_print_filemode(unsigned short mode)
703 722
704void cgit_print_snapshot_links(const char *repo, const char *head, 723void cgit_print_snapshot_links(const char *repo, const char *head,
705 const char *hex, int snapshots) 724 const char *hex, int snapshots)
706{ 725{
707 const struct cgit_snapshot_format* f; 726 const struct cgit_snapshot_format* f;
708 char *filename; 727 char *filename;
709 728
710 for (f = cgit_snapshot_formats; f->suffix; f++) { 729 for (f = cgit_snapshot_formats; f->suffix; f++) {
711 if (!(snapshots & f->bit)) 730 if (!(snapshots & f->bit))
712 continue; 731 continue;
713 filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, 732 filename = fmt("%s-%s%s", cgit_repobasename(repo), hex,
714 f->suffix); 733 f->suffix);
715 cgit_snapshot_link(filename, NULL, NULL, (char *)head, 734 cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename);
716 (char *)hex, filename);
717 html("<br/>"); 735 html("<br/>");
718 } 736 }
719} 737}