summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
Unidiff
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c21
1 files changed, 4 insertions, 17 deletions
diff --git a/ui-shared.c b/ui-shared.c
index bb08c4a..8a804c2 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -391,219 +391,206 @@ void cgit_print_docend()
391{ 391{
392 html("</div>\n</body>\n</html>\n"); 392 html("</div>\n</body>\n</html>\n");
393} 393}
394 394
395int print_branch_option(const char *refname, const unsigned char *sha1, 395int print_branch_option(const char *refname, const unsigned char *sha1,
396 int flags, void *cb_data) 396 int flags, void *cb_data)
397{ 397{
398 char *name = (char *)refname; 398 char *name = (char *)refname;
399 html_option(name, name, ctx.qry.head); 399 html_option(name, name, ctx.qry.head);
400 return 0; 400 return 0;
401} 401}
402 402
403int print_archive_ref(const char *refname, const unsigned char *sha1, 403int print_archive_ref(const char *refname, const unsigned char *sha1,
404 int flags, void *cb_data) 404 int flags, void *cb_data)
405{ 405{
406 struct tag *tag; 406 struct tag *tag;
407 struct taginfo *info; 407 struct taginfo *info;
408 struct object *obj; 408 struct object *obj;
409 char buf[256], *url; 409 char buf[256], *url;
410 unsigned char fileid[20]; 410 unsigned char fileid[20];
411 int *header = (int *)cb_data; 411 int *header = (int *)cb_data;
412 412
413 if (prefixcmp(refname, "refs/archives")) 413 if (prefixcmp(refname, "refs/archives"))
414 return 0; 414 return 0;
415 strncpy(buf, refname+14, sizeof(buf)); 415 strncpy(buf, refname+14, sizeof(buf));
416 obj = parse_object(sha1); 416 obj = parse_object(sha1);
417 if (!obj) 417 if (!obj)
418 return 1; 418 return 1;
419 if (obj->type == OBJ_TAG) { 419 if (obj->type == OBJ_TAG) {
420 tag = lookup_tag(sha1); 420 tag = lookup_tag(sha1);
421 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 421 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
422 return 0; 422 return 0;
423 hashcpy(fileid, tag->tagged->sha1); 423 hashcpy(fileid, tag->tagged->sha1);
424 } else if (obj->type != OBJ_BLOB) { 424 } else if (obj->type != OBJ_BLOB) {
425 return 0; 425 return 0;
426 } else { 426 } else {
427 hashcpy(fileid, sha1); 427 hashcpy(fileid, sha1);
428 } 428 }
429 if (!*header) { 429 if (!*header) {
430 html("<h1>download</h1>\n"); 430 html("<h1>download</h1>\n");
431 *header = 1; 431 *header = 1;
432 } 432 }
433 url = cgit_pageurl(ctx.qry.repo, "blob", 433 url = cgit_pageurl(ctx.qry.repo, "blob",
434 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 434 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
435 buf)); 435 buf));
436 html_link_open(url, NULL, "menu"); 436 html_link_open(url, NULL, "menu");
437 html_txt(strlpart(buf, 20)); 437 html_txt(strlpart(buf, 20));
438 html_link_close(); 438 html_link_close();
439 return 0; 439 return 0;
440} 440}
441 441
442void add_hidden_formfields(int incl_head, int incl_search, char *page) 442void add_hidden_formfields(int incl_head, int incl_search, char *page)
443{ 443{
444 char *url; 444 char *url;
445 445
446 if (!ctx.cfg.virtual_root) { 446 if (!ctx.cfg.virtual_root) {
447 url = fmt("%s/%s", ctx.qry.repo, page); 447 url = fmt("%s/%s", ctx.qry.repo, page);
448 if (ctx.qry.path) 448 if (ctx.qry.path)
449 url = fmt("%s/%s", url, ctx.qry.path); 449 url = fmt("%s/%s", url, ctx.qry.path);
450 html_hidden("url", url); 450 html_hidden("url", url);
451 } 451 }
452 452
453 if (incl_head && strcmp(ctx.qry.head, ctx.repo->defbranch)) 453 if (incl_head && strcmp(ctx.qry.head, ctx.repo->defbranch))
454 html_hidden("h", ctx.qry.head); 454 html_hidden("h", ctx.qry.head);
455 455
456 if (ctx.qry.sha1) 456 if (ctx.qry.sha1)
457 html_hidden("id", ctx.qry.sha1); 457 html_hidden("id", ctx.qry.sha1);
458 if (ctx.qry.sha2) 458 if (ctx.qry.sha2)
459 html_hidden("id2", ctx.qry.sha2); 459 html_hidden("id2", ctx.qry.sha2);
460 460
461 if (incl_search) { 461 if (incl_search) {
462 if (ctx.qry.grep) 462 if (ctx.qry.grep)
463 html_hidden("qt", ctx.qry.grep); 463 html_hidden("qt", ctx.qry.grep);
464 if (ctx.qry.search) 464 if (ctx.qry.search)
465 html_hidden("q", ctx.qry.search); 465 html_hidden("q", ctx.qry.search);
466 } 466 }
467} 467}
468 468
469char *hc(struct cgit_cmd *cmd, const char *page) 469char *hc(struct cgit_cmd *cmd, const char *page)
470{ 470{
471 return (strcmp(cmd->name, page) ? NULL : "active"); 471 return (strcmp(cmd->name, page) ? NULL : "active");
472} 472}
473 473
474void cgit_print_pageheader(struct cgit_context *ctx) 474void cgit_print_pageheader(struct cgit_context *ctx)
475{ 475{
476 struct cgit_cmd *cmd = cgit_get_cmd(ctx); 476 struct cgit_cmd *cmd = cgit_get_cmd(ctx);
477 477
478 html("<table id='header'>\n"); 478 html("<table id='header'>\n");
479 html("<tr>\n"); 479 html("<tr>\n");
480 html("<td class='logo' rowspan='2'><a href='"); 480 html("<td class='logo' rowspan='2'><a href='");
481 if (ctx->cfg.logo_link) 481 if (ctx->cfg.logo_link)
482 html_attr(ctx->cfg.logo_link); 482 html_attr(ctx->cfg.logo_link);
483 else 483 else
484 html_attr(cgit_rooturl()); 484 html_attr(cgit_rooturl());
485 html("'><img src='"); 485 html("'><img src='");
486 html_attr(ctx->cfg.logo); 486 html_attr(ctx->cfg.logo);
487 html("'/></a></td>\n"); 487 html("' alt='cgit logo'/></a></td>\n");
488 488
489 html("<td class='main'>"); 489 html("<td class='main'>");
490 if (ctx->repo) { 490 if (ctx->repo) {
491/*
492 html("<a href='");
493 html_attr(cgit_rooturl());
494 html("'>index</a> : ");
495*/
496 reporevlink(NULL, ctx->repo->name, NULL, hc(cmd, "summary"), 491 reporevlink(NULL, ctx->repo->name, NULL, hc(cmd, "summary"),
497 ctx->qry.head, NULL, NULL); 492 ctx->qry.head, NULL, NULL);
498 html(" : "); 493 html(" : ");
499 html_txt(ctx->qry.page); 494 html_txt(ctx->qry.page);
500 html("</td><td class='form'>"); 495 html("</td><td class='form'>");
501 html("<form method='get' action=''>\n"); 496 html("<form method='get' action=''>\n");
502 add_hidden_formfields(0, 1, ctx->qry.page); 497 add_hidden_formfields(0, 1, ctx->qry.page);
503 html("<select name='h' onchange='this.form.submit();'>\n"); 498 html("<select name='h' onchange='this.form.submit();'>\n");
504 for_each_branch_ref(print_branch_option, ctx->qry.head); 499 for_each_branch_ref(print_branch_option, ctx->qry.head);
505 html("</select> "); 500 html("</select> ");
506 html("<input type='submit' name='' value='switch'/>"); 501 html("<input type='submit' name='' value='switch'/>");
507 html("</form>"); 502 html("</form>");
508 } else 503 } else
509 html_txt(ctx->cfg.root_title); 504 html_txt(ctx->cfg.root_title);
510 html("</td>\n"); 505 html("</td></tr>\n");
511 506
512 html("<tr><td class='sub'"); 507 html("<tr><td class='sub'");
513 if (ctx->repo) { 508 if (ctx->repo) {
514 html(" colspan='2'>"); 509 html(" colspan='2'>");
515 html_txt(ctx->repo->desc); 510 html_txt(ctx->repo->desc);
516 } 511 } else {
517/*
518 else if (ctx->cfg.root_subtitle)
519 html_txt(ctx->cfg.root_subtitle);
520*/
521 else {
522 html(">"); 512 html(">");
523 html_txt("a fast webinterface for the git dscm"); 513 html_txt("a fast webinterface for the git dscm");
524 } 514 }
525 html("</td></tr>\n"); 515 html("</td></tr></table>\n");
526
527 html("</tr>\n");
528 html("</table>\n");
529 516
530 html("<table class='tabs'><tr><td>\n"); 517 html("<table class='tabs'><tr><td>\n");
531 if (ctx->repo) { 518 if (ctx->repo) {
532 reporevlink(NULL, "summary", NULL, hc(cmd, "summary"), 519 reporevlink(NULL, "summary", NULL, hc(cmd, "summary"),
533 ctx->qry.head, NULL, NULL); 520 ctx->qry.head, NULL, NULL);
534 cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, 521 cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head,
535 ctx->qry.sha1, NULL); 522 ctx->qry.sha1, NULL);
536 cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, 523 cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head,
537 NULL, NULL, 0, NULL, NULL); 524 NULL, NULL, 0, NULL, NULL);
538 cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, 525 cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head,
539 ctx->qry.sha1, NULL); 526 ctx->qry.sha1, NULL);
540 cgit_commit_link("commit", NULL, hc(cmd, "commit"), 527 cgit_commit_link("commit", NULL, hc(cmd, "commit"),
541 ctx->qry.head, ctx->qry.sha1); 528 ctx->qry.head, ctx->qry.sha1);
542 cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, 529 cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head,
543 ctx->qry.sha1, ctx->qry.sha2, NULL); 530 ctx->qry.sha1, ctx->qry.sha2, NULL);
544 html("</td><td class='form'>"); 531 html("</td><td class='form'>");
545 html("<form class='right' method='get' action='"); 532 html("<form class='right' method='get' action='");
546 if (ctx->cfg.virtual_root) 533 if (ctx->cfg.virtual_root)
547 html_attr(cgit_fileurl(ctx->qry.repo, "log", 534 html_attr(cgit_fileurl(ctx->qry.repo, "log",
548 ctx->qry.path, NULL)); 535 ctx->qry.path, NULL));
549 html("'>\n"); 536 html("'>\n");
550 add_hidden_formfields(1, 0, "log"); 537 add_hidden_formfields(1, 0, "log");
551 html("<select name='qt'>\n"); 538 html("<select name='qt'>\n");
552 html_option("grep", "log msg", ctx->qry.grep); 539 html_option("grep", "log msg", ctx->qry.grep);
553 html_option("author", "author", ctx->qry.grep); 540 html_option("author", "author", ctx->qry.grep);
554 html_option("committer", "committer", ctx->qry.grep); 541 html_option("committer", "committer", ctx->qry.grep);
555 html("</select>\n"); 542 html("</select>\n");
556 html("<input class='txt' type='text' size='10' name='q' value='"); 543 html("<input class='txt' type='text' size='10' name='q' value='");
557 html_attr(ctx->qry.search); 544 html_attr(ctx->qry.search);
558 html("'/>\n"); 545 html("'/>\n");
559 html("<input type='submit' value='search'/>\n"); 546 html("<input type='submit' value='search'/>\n");
560 html("</form>\n"); 547 html("</form>\n");
561 } else { 548 } else {
562 html("<a class='active' href='"); 549 html("<a class='active' href='");
563 html_attr(cgit_rooturl()); 550 html_attr(cgit_rooturl());
564 html("'>index</a>\n"); 551 html("'>index</a>\n");
565 html("</td><td class='form'>"); 552 html("</td><td class='form'>");
566 html("<form method='get' action='"); 553 html("<form method='get' action='");
567 html_attr(cgit_rooturl()); 554 html_attr(cgit_rooturl());
568 html("'>\n"); 555 html("'>\n");
569 html("<input type='text' name='q' size='10' value='"); 556 html("<input type='text' name='q' size='10' value='");
570 html_attr(ctx->qry.search); 557 html_attr(ctx->qry.search);
571 html("'/>\n"); 558 html("'/>\n");
572 html("<input type='submit' value='search'/>\n"); 559 html("<input type='submit' value='search'/>\n");
573 html("</form>"); 560 html("</form>");
574 } 561 }
575 html("</td></tr></table>\n"); 562 html("</td></tr></table>\n");
576 html("<div class='content'>"); 563 html("<div class='content'>");
577} 564}
578 565
579void cgit_print_filemode(unsigned short mode) 566void cgit_print_filemode(unsigned short mode)
580{ 567{
581 if (S_ISDIR(mode)) 568 if (S_ISDIR(mode))
582 html("d"); 569 html("d");
583 else if (S_ISLNK(mode)) 570 else if (S_ISLNK(mode))
584 html("l"); 571 html("l");
585 else if (S_ISGITLINK(mode)) 572 else if (S_ISGITLINK(mode))
586 html("m"); 573 html("m");
587 else 574 else
588 html("-"); 575 html("-");
589 html_fileperm(mode >> 6); 576 html_fileperm(mode >> 6);
590 html_fileperm(mode >> 3); 577 html_fileperm(mode >> 3);
591 html_fileperm(mode); 578 html_fileperm(mode);
592} 579}
593 580
594void cgit_print_snapshot_links(const char *repo, const char *head, 581void cgit_print_snapshot_links(const char *repo, const char *head,
595 const char *hex, int snapshots) 582 const char *hex, int snapshots)
596{ 583{
597 const struct cgit_snapshot_format* f; 584 const struct cgit_snapshot_format* f;
598 char *filename; 585 char *filename;
599 586
600 for (f = cgit_snapshot_formats; f->suffix; f++) { 587 for (f = cgit_snapshot_formats; f->suffix; f++) {
601 if (!(snapshots & f->bit)) 588 if (!(snapshots & f->bit))
602 continue; 589 continue;
603 filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, 590 filename = fmt("%s-%s%s", cgit_repobasename(repo), hex,
604 f->suffix); 591 f->suffix);
605 cgit_snapshot_link(filename, NULL, NULL, (char *)head, 592 cgit_snapshot_link(filename, NULL, NULL, (char *)head,
606 (char *)hex, filename); 593 (char *)hex, filename);
607 html("<br/>"); 594 html("<br/>");
608 } 595 }
609} 596}