summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
Unidiff
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 2596023..aa65988 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -448,129 +448,144 @@ void add_hidden_formfields(int incl_head, int incl_search, char *page)
448 url = fmt("%s/%s", url, ctx.qry.path); 448 url = fmt("%s/%s", url, ctx.qry.path);
449 html_hidden("url", url); 449 html_hidden("url", url);
450 } 450 }
451 451
452 if (incl_head && strcmp(ctx.qry.head, ctx.repo->defbranch)) 452 if (incl_head && strcmp(ctx.qry.head, ctx.repo->defbranch))
453 html_hidden("h", ctx.qry.head); 453 html_hidden("h", ctx.qry.head);
454 454
455 if (ctx.qry.sha1) 455 if (ctx.qry.sha1)
456 html_hidden("id", ctx.qry.sha1); 456 html_hidden("id", ctx.qry.sha1);
457 if (ctx.qry.sha2) 457 if (ctx.qry.sha2)
458 html_hidden("id2", ctx.qry.sha2); 458 html_hidden("id2", ctx.qry.sha2);
459 459
460 if (incl_search) { 460 if (incl_search) {
461 if (ctx.qry.grep) 461 if (ctx.qry.grep)
462 html_hidden("qt", ctx.qry.grep); 462 html_hidden("qt", ctx.qry.grep);
463 if (ctx.qry.search) 463 if (ctx.qry.search)
464 html_hidden("q", ctx.qry.search); 464 html_hidden("q", ctx.qry.search);
465 } 465 }
466} 466}
467 467
468void cgit_print_pageheader(struct cgit_context *ctx) 468void cgit_print_pageheader(struct cgit_context *ctx)
469{ 469{
470 static const char *default_info = "This is cgit, a fast webinterface for git repositories"; 470 static const char *default_info = "This is cgit, a fast webinterface for git repositories";
471 int header = 0; 471 int header = 0;
472 char *url; 472 char *url;
473 473
474 html("<table id='layout' summary=''>\n"); 474 html("<table id='layout' summary=''>\n");
475 html("<tr><td id='sidebar'>\n"); 475 html("<tr><td id='sidebar'>\n");
476 html("<table class='sidebar' cellspacing='0' summary=''>\n"); 476 html("<table class='sidebar' cellspacing='0' summary=''>\n");
477 html("<tr><td class='sidebar'>\n<a href='"); 477 html("<tr><td class='sidebar'>\n<a href='");
478 html_attr(cgit_rooturl()); 478 html_attr(cgit_rooturl());
479 htmlf("'><img src='%s' alt='cgit'/></a>\n", 479 htmlf("'><img src='%s' alt='cgit'/></a>\n",
480 ctx->cfg.logo); 480 ctx->cfg.logo);
481 html("</td></tr>\n<tr><td class='sidebar'>\n"); 481 html("</td></tr>\n<tr><td class='sidebar'>\n");
482 if (ctx->repo) { 482 if (ctx->repo) {
483 html("<h1 class='first'>"); 483 html("<h1 class='first'>");
484 html_txt(strrpart(ctx->repo->name, 20)); 484 html_txt(strrpart(ctx->repo->name, 20));
485 html("</h1>\n"); 485 html("</h1>\n");
486 html_txt(ctx->repo->desc); 486 html_txt(ctx->repo->desc);
487 if (ctx->repo->owner) { 487 if (ctx->repo->owner) {
488 html("<h1>owner</h1>\n"); 488 html("<h1>owner</h1>\n");
489 html_txt(ctx->repo->owner); 489 html_txt(ctx->repo->owner);
490 } 490 }
491 html("<h1>navigate</h1>\n"); 491 html("<h1>navigate</h1>\n");
492 reporevlink(NULL, "summary", NULL, "menu", ctx->qry.head, 492 reporevlink(NULL, "summary", NULL, "menu", ctx->qry.head,
493 NULL, NULL); 493 NULL, NULL);
494 cgit_log_link("log", NULL, "menu", ctx->qry.head, NULL, NULL, 494 cgit_log_link("log", NULL, "menu", ctx->qry.head, NULL, NULL,
495 0, NULL, NULL); 495 0, NULL, NULL);
496 cgit_tree_link("tree", NULL, "menu", ctx->qry.head, 496 cgit_tree_link("tree", NULL, "menu", ctx->qry.head,
497 ctx->qry.sha1, NULL); 497 ctx->qry.sha1, NULL);
498 cgit_commit_link("commit", NULL, "menu", ctx->qry.head, 498 cgit_commit_link("commit", NULL, "menu", ctx->qry.head,
499 ctx->qry.sha1); 499 ctx->qry.sha1);
500 cgit_diff_link("diff", NULL, "menu", ctx->qry.head, 500 cgit_diff_link("diff", NULL, "menu", ctx->qry.head,
501 ctx->qry.sha1, ctx->qry.sha2, NULL); 501 ctx->qry.sha1, ctx->qry.sha2, NULL);
502 cgit_patch_link("patch", NULL, "menu", ctx->qry.head, 502 cgit_patch_link("patch", NULL, "menu", ctx->qry.head,
503 ctx->qry.sha1); 503 ctx->qry.sha1);
504 504
505 for_each_ref(print_archive_ref, &header); 505 for_each_ref(print_archive_ref, &header);
506 506
507 if (ctx->repo->clone_url || ctx->cfg.clone_prefix) { 507 if (ctx->repo->clone_url || ctx->cfg.clone_prefix) {
508 html("<h1>clone</h1>\n"); 508 html("<h1>clone</h1>\n");
509 if (ctx->repo->clone_url) 509 if (ctx->repo->clone_url)
510 url = ctx->repo->clone_url; 510 url = ctx->repo->clone_url;
511 else 511 else
512 url = fmt("%s%s", ctx->cfg.clone_prefix, 512 url = fmt("%s%s", ctx->cfg.clone_prefix,
513 ctx->repo->url); 513 ctx->repo->url);
514 html("<a class='menu' href='"); 514 html("<a class='menu' href='");
515 html_attr(url); 515 html_attr(url);
516 html("' title='"); 516 html("' title='");
517 html_attr(url); 517 html_attr(url);
518 html("'>\n"); 518 html("'>\n");
519 html_txt(strrpart(url, 20)); 519 html_txt(strrpart(url, 20));
520 html("</a>\n"); 520 html("</a>\n");
521 } 521 }
522 522
523 html("<h1>branch</h1>\n"); 523 html("<h1>branch</h1>\n");
524 html("<form method='get' action=''>\n"); 524 html("<form method='get' action=''>\n");
525 add_hidden_formfields(0, 1, ctx->qry.page); 525 add_hidden_formfields(0, 1, ctx->qry.page);
526 // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); 526 // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>");
527 html("<select name='h' onchange='this.form.submit();'>\n"); 527 html("<select name='h' onchange='this.form.submit();'>\n");
528 for_each_branch_ref(print_branch_option, ctx->qry.head); 528 for_each_branch_ref(print_branch_option, ctx->qry.head);
529 html("</select>\n"); 529 html("</select>\n");
530 // html("</td><td>"); 530 // html("</td><td>");
531 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); 531 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n");
532 // html("</td></tr></table>"); 532 // html("</td></tr></table>");
533 html("</form>\n"); 533 html("</form>\n");
534 534
535 html("<h1>search</h1>\n"); 535 html("<h1>search</h1>\n");
536 html("<form method='get' action='"); 536 html("<form method='get' action='");
537 if (ctx->cfg.virtual_root) 537 if (ctx->cfg.virtual_root)
538 html_attr(cgit_fileurl(ctx->qry.repo, "log", 538 html_attr(cgit_fileurl(ctx->qry.repo, "log",
539 ctx->qry.path, NULL)); 539 ctx->qry.path, NULL));
540 html("'>\n"); 540 html("'>\n");
541 add_hidden_formfields(1, 0, "log"); 541 add_hidden_formfields(1, 0, "log");
542 html("<select name='qt'>\n"); 542 html("<select name='qt'>\n");
543 html_option("grep", "log msg", ctx->qry.grep); 543 html_option("grep", "log msg", ctx->qry.grep);
544 html_option("author", "author", ctx->qry.grep); 544 html_option("author", "author", ctx->qry.grep);
545 html_option("committer", "committer", ctx->qry.grep); 545 html_option("committer", "committer", ctx->qry.grep);
546 html("</select>\n"); 546 html("</select>\n");
547 html("<input class='txt' type='text' name='q' value='"); 547 html("<input class='txt' type='text' name='q' value='");
548 html_attr(ctx->qry.search); 548 html_attr(ctx->qry.search);
549 html("'/>\n"); 549 html("'/>\n");
550 html("</form>\n"); 550 html("</form>\n");
551 } else { 551 } else {
552 if (!ctx->cfg.index_info || html_include(ctx->cfg.index_info)) 552 if (!ctx->cfg.index_info || html_include(ctx->cfg.index_info))
553 html(default_info); 553 html(default_info);
554 } 554 }
555 555
556 html("</td></tr></table></td>\n"); 556 html("</td></tr></table></td>\n");
557 557
558 html("<td id='content'>\n"); 558 html("<td id='content'>\n");
559} 559}
560 560
561void cgit_print_filemode(unsigned short mode) 561void cgit_print_filemode(unsigned short mode)
562{ 562{
563 if (S_ISDIR(mode)) 563 if (S_ISDIR(mode))
564 html("d"); 564 html("d");
565 else if (S_ISLNK(mode)) 565 else if (S_ISLNK(mode))
566 html("l"); 566 html("l");
567 else if (S_ISGITLINK(mode)) 567 else if (S_ISGITLINK(mode))
568 html("m"); 568 html("m");
569 else 569 else
570 html("-"); 570 html("-");
571 html_fileperm(mode >> 6); 571 html_fileperm(mode >> 6);
572 html_fileperm(mode >> 3); 572 html_fileperm(mode >> 3);
573 html_fileperm(mode); 573 html_fileperm(mode);
574} 574}
575 575
576/* vim:set sw=8: */ 576void cgit_print_snapshot_links(const char *repo, const char *head,
577 const char *hex, int snapshots)
578{
579 const struct cgit_snapshot_format* f;
580 char *filename;
581
582 for (f = cgit_snapshot_formats; f->suffix; f++) {
583 if (!(snapshots & f->bit))
584 continue;
585 filename = fmt("%s-%s%s", cgit_repobasename(repo), hex,
586 f->suffix);
587 cgit_snapshot_link(filename, NULL, NULL, (char *)head,
588 (char *)hex, filename);
589 html("<br/>");
590 }
591}