summaryrefslogtreecommitdiffabout
authorJohan Herland <johan@herland.net>2010-06-09 23:09:36 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2010-06-19 08:40:24 (UTC)
commit7fdff2460440c09d13fc76af3b75e85434e6f563 (patch) (unidiff)
tree2285bf24286d5ec6046a13b18599e0e00e63111d
parent685872b770be2af643d00365d5358e46687f7385 (diff)
downloadcgit-7fdff2460440c09d13fc76af3b75e85434e6f563.zip
cgit-7fdff2460440c09d13fc76af3b75e85434e6f563.tar.gz
cgit-7fdff2460440c09d13fc76af3b75e85434e6f563.tar.bz2
ui-shared: Preserve path limit in "tab bar" links
When using the "tab bar" in the pageheader to navigate between pages, any path limit in effect on the current page is forgotten in the link to the target page, even if the target page can interpret and use the path limit constructively. Instead, preserve the current page's path limit in the "tab bar" links to other pages, where the path limit is useful to the target page. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 372b9e7..e991799 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -601,283 +601,284 @@ void cgit_print_docstart(struct cgit_context *ctx)
601 html_include(ctx->cfg.head_include); 601 html_include(ctx->cfg.head_include);
602 html("</head>\n"); 602 html("</head>\n");
603 html("<body>\n"); 603 html("<body>\n");
604 if (ctx->cfg.header) 604 if (ctx->cfg.header)
605 html_include(ctx->cfg.header); 605 html_include(ctx->cfg.header);
606} 606}
607 607
608void cgit_print_docend() 608void cgit_print_docend()
609{ 609{
610 html("</div> <!-- class=content -->\n"); 610 html("</div> <!-- class=content -->\n");
611 if (ctx.cfg.embedded) { 611 if (ctx.cfg.embedded) {
612 html("</div> <!-- id=cgit -->\n"); 612 html("</div> <!-- id=cgit -->\n");
613 if (ctx.cfg.footer) 613 if (ctx.cfg.footer)
614 html_include(ctx.cfg.footer); 614 html_include(ctx.cfg.footer);
615 return; 615 return;
616 } 616 }
617 if (ctx.cfg.footer) 617 if (ctx.cfg.footer)
618 html_include(ctx.cfg.footer); 618 html_include(ctx.cfg.footer);
619 else { 619 else {
620 htmlf("<div class='footer'>generated by cgit %s at ", 620 htmlf("<div class='footer'>generated by cgit %s at ",
621 cgit_version); 621 cgit_version);
622 cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); 622 cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
623 html("</div>\n"); 623 html("</div>\n");
624 } 624 }
625 html("</div> <!-- id=cgit -->\n"); 625 html("</div> <!-- id=cgit -->\n");
626 html("</body>\n</html>\n"); 626 html("</body>\n</html>\n");
627} 627}
628 628
629int print_branch_option(const char *refname, const unsigned char *sha1, 629int print_branch_option(const char *refname, const unsigned char *sha1,
630 int flags, void *cb_data) 630 int flags, void *cb_data)
631{ 631{
632 char *name = (char *)refname; 632 char *name = (char *)refname;
633 html_option(name, name, ctx.qry.head); 633 html_option(name, name, ctx.qry.head);
634 return 0; 634 return 0;
635} 635}
636 636
637int print_archive_ref(const char *refname, const unsigned char *sha1, 637int print_archive_ref(const char *refname, const unsigned char *sha1,
638 int flags, void *cb_data) 638 int flags, void *cb_data)
639{ 639{
640 struct tag *tag; 640 struct tag *tag;
641 struct taginfo *info; 641 struct taginfo *info;
642 struct object *obj; 642 struct object *obj;
643 char buf[256], *url; 643 char buf[256], *url;
644 unsigned char fileid[20]; 644 unsigned char fileid[20];
645 int *header = (int *)cb_data; 645 int *header = (int *)cb_data;
646 646
647 if (prefixcmp(refname, "refs/archives")) 647 if (prefixcmp(refname, "refs/archives"))
648 return 0; 648 return 0;
649 strncpy(buf, refname+14, sizeof(buf)); 649 strncpy(buf, refname+14, sizeof(buf));
650 obj = parse_object(sha1); 650 obj = parse_object(sha1);
651 if (!obj) 651 if (!obj)
652 return 1; 652 return 1;
653 if (obj->type == OBJ_TAG) { 653 if (obj->type == OBJ_TAG) {
654 tag = lookup_tag(sha1); 654 tag = lookup_tag(sha1);
655 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 655 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
656 return 0; 656 return 0;
657 hashcpy(fileid, tag->tagged->sha1); 657 hashcpy(fileid, tag->tagged->sha1);
658 } else if (obj->type != OBJ_BLOB) { 658 } else if (obj->type != OBJ_BLOB) {
659 return 0; 659 return 0;
660 } else { 660 } else {
661 hashcpy(fileid, sha1); 661 hashcpy(fileid, sha1);
662 } 662 }
663 if (!*header) { 663 if (!*header) {
664 html("<h1>download</h1>\n"); 664 html("<h1>download</h1>\n");
665 *header = 1; 665 *header = 1;
666 } 666 }
667 url = cgit_pageurl(ctx.qry.repo, "blob", 667 url = cgit_pageurl(ctx.qry.repo, "blob",
668 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 668 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
669 buf)); 669 buf));
670 html_link_open(url, NULL, "menu"); 670 html_link_open(url, NULL, "menu");
671 html_txt(strlpart(buf, 20)); 671 html_txt(strlpart(buf, 20));
672 html_link_close(); 672 html_link_close();
673 return 0; 673 return 0;
674} 674}
675 675
676void cgit_add_hidden_formfields(int incl_head, int incl_search, 676void cgit_add_hidden_formfields(int incl_head, int incl_search,
677 const char *page) 677 const char *page)
678{ 678{
679 char *url; 679 char *url;
680 680
681 if (!ctx.cfg.virtual_root) { 681 if (!ctx.cfg.virtual_root) {
682 url = fmt("%s/%s", ctx.qry.repo, page); 682 url = fmt("%s/%s", ctx.qry.repo, page);
683 if (ctx.qry.vpath) 683 if (ctx.qry.vpath)
684 url = fmt("%s/%s", url, ctx.qry.vpath); 684 url = fmt("%s/%s", url, ctx.qry.vpath);
685 html_hidden("url", url); 685 html_hidden("url", url);
686 } 686 }
687 687
688 if (incl_head && ctx.qry.head && ctx.repo->defbranch && 688 if (incl_head && ctx.qry.head && ctx.repo->defbranch &&
689 strcmp(ctx.qry.head, ctx.repo->defbranch)) 689 strcmp(ctx.qry.head, ctx.repo->defbranch))
690 html_hidden("h", ctx.qry.head); 690 html_hidden("h", ctx.qry.head);
691 691
692 if (ctx.qry.sha1) 692 if (ctx.qry.sha1)
693 html_hidden("id", ctx.qry.sha1); 693 html_hidden("id", ctx.qry.sha1);
694 if (ctx.qry.sha2) 694 if (ctx.qry.sha2)
695 html_hidden("id2", ctx.qry.sha2); 695 html_hidden("id2", ctx.qry.sha2);
696 if (ctx.qry.showmsg) 696 if (ctx.qry.showmsg)
697 html_hidden("showmsg", "1"); 697 html_hidden("showmsg", "1");
698 698
699 if (incl_search) { 699 if (incl_search) {
700 if (ctx.qry.grep) 700 if (ctx.qry.grep)
701 html_hidden("qt", ctx.qry.grep); 701 html_hidden("qt", ctx.qry.grep);
702 if (ctx.qry.search) 702 if (ctx.qry.search)
703 html_hidden("q", ctx.qry.search); 703 html_hidden("q", ctx.qry.search);
704 } 704 }
705} 705}
706 706
707static const char *hc(struct cgit_context *ctx, const char *page) 707static const char *hc(struct cgit_context *ctx, const char *page)
708{ 708{
709 return strcmp(ctx->qry.page, page) ? NULL : "active"; 709 return strcmp(ctx->qry.page, page) ? NULL : "active";
710} 710}
711 711
712static void cgit_print_path_crumbs(struct cgit_context *ctx, char *path) 712static void cgit_print_path_crumbs(struct cgit_context *ctx, char *path)
713{ 713{
714 char *old_path = ctx->qry.path; 714 char *old_path = ctx->qry.path;
715 char *p = path, *q, *end = path + strlen(path); 715 char *p = path, *q, *end = path + strlen(path);
716 716
717 ctx->qry.path = NULL; 717 ctx->qry.path = NULL;
718 cgit_self_link("root", NULL, NULL, ctx); 718 cgit_self_link("root", NULL, NULL, ctx);
719 ctx->qry.path = p = path; 719 ctx->qry.path = p = path;
720 while (p < end) { 720 while (p < end) {
721 if (!(q = strchr(p, '/'))) 721 if (!(q = strchr(p, '/')))
722 q = end; 722 q = end;
723 *q = '\0'; 723 *q = '\0';
724 html_txt("/"); 724 html_txt("/");
725 cgit_self_link(p, NULL, NULL, ctx); 725 cgit_self_link(p, NULL, NULL, ctx);
726 if (q < end) 726 if (q < end)
727 *q = '/'; 727 *q = '/';
728 p = q + 1; 728 p = q + 1;
729 } 729 }
730 ctx->qry.path = old_path; 730 ctx->qry.path = old_path;
731} 731}
732 732
733static void print_header(struct cgit_context *ctx) 733static void print_header(struct cgit_context *ctx)
734{ 734{
735 html("<table id='header'>\n"); 735 html("<table id='header'>\n");
736 html("<tr>\n"); 736 html("<tr>\n");
737 737
738 if (ctx->cfg.logo && ctx->cfg.logo[0] != 0) { 738 if (ctx->cfg.logo && ctx->cfg.logo[0] != 0) {
739 html("<td class='logo' rowspan='2'><a href='"); 739 html("<td class='logo' rowspan='2'><a href='");
740 if (ctx->cfg.logo_link) 740 if (ctx->cfg.logo_link)
741 html_attr(ctx->cfg.logo_link); 741 html_attr(ctx->cfg.logo_link);
742 else 742 else
743 html_attr(cgit_rooturl()); 743 html_attr(cgit_rooturl());
744 html("'><img src='"); 744 html("'><img src='");
745 html_attr(ctx->cfg.logo); 745 html_attr(ctx->cfg.logo);
746 html("' alt='cgit logo'/></a></td>\n"); 746 html("' alt='cgit logo'/></a></td>\n");
747 } 747 }
748 748
749 html("<td class='main'>"); 749 html("<td class='main'>");
750 if (ctx->repo) { 750 if (ctx->repo) {
751 cgit_index_link("index", NULL, NULL, NULL, 0); 751 cgit_index_link("index", NULL, NULL, NULL, 0);
752 html(" : "); 752 html(" : ");
753 cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); 753 cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL);
754 html("</td><td class='form'>"); 754 html("</td><td class='form'>");
755 html("<form method='get' action=''>\n"); 755 html("<form method='get' action=''>\n");
756 cgit_add_hidden_formfields(0, 1, ctx->qry.page); 756 cgit_add_hidden_formfields(0, 1, ctx->qry.page);
757 html("<select name='h' onchange='this.form.submit();'>\n"); 757 html("<select name='h' onchange='this.form.submit();'>\n");
758 for_each_branch_ref(print_branch_option, ctx->qry.head); 758 for_each_branch_ref(print_branch_option, ctx->qry.head);
759 html("</select> "); 759 html("</select> ");
760 html("<input type='submit' name='' value='switch'/>"); 760 html("<input type='submit' name='' value='switch'/>");
761 html("</form>"); 761 html("</form>");
762 } else 762 } else
763 html_txt(ctx->cfg.root_title); 763 html_txt(ctx->cfg.root_title);
764 html("</td></tr>\n"); 764 html("</td></tr>\n");
765 765
766 html("<tr><td class='sub'>"); 766 html("<tr><td class='sub'>");
767 if (ctx->repo) { 767 if (ctx->repo) {
768 html_txt(ctx->repo->desc); 768 html_txt(ctx->repo->desc);
769 html("</td><td class='sub right'>"); 769 html("</td><td class='sub right'>");
770 html_txt(ctx->repo->owner); 770 html_txt(ctx->repo->owner);
771 } else { 771 } else {
772 if (ctx->cfg.root_desc) 772 if (ctx->cfg.root_desc)
773 html_txt(ctx->cfg.root_desc); 773 html_txt(ctx->cfg.root_desc);
774 else if (ctx->cfg.index_info) 774 else if (ctx->cfg.index_info)
775 html_include(ctx->cfg.index_info); 775 html_include(ctx->cfg.index_info);
776 } 776 }
777 html("</td></tr></table>\n"); 777 html("</td></tr></table>\n");
778} 778}
779 779
780void cgit_print_pageheader(struct cgit_context *ctx) 780void cgit_print_pageheader(struct cgit_context *ctx)
781{ 781{
782 html("<div id='cgit'>"); 782 html("<div id='cgit'>");
783 if (!ctx->cfg.noheader) 783 if (!ctx->cfg.noheader)
784 print_header(ctx); 784 print_header(ctx);
785 785
786 html("<table class='tabs'><tr><td>\n"); 786 html("<table class='tabs'><tr><td>\n");
787 if (ctx->repo) { 787 if (ctx->repo) {
788 cgit_summary_link("summary", NULL, hc(ctx, "summary"), 788 cgit_summary_link("summary", NULL, hc(ctx, "summary"),
789 ctx->qry.head); 789 ctx->qry.head);
790 cgit_refs_link("refs", NULL, hc(ctx, "refs"), ctx->qry.head, 790 cgit_refs_link("refs", NULL, hc(ctx, "refs"), ctx->qry.head,
791 ctx->qry.sha1, NULL); 791 ctx->qry.sha1, NULL);
792 cgit_log_link("log", NULL, hc(ctx, "log"), ctx->qry.head, 792 cgit_log_link("log", NULL, hc(ctx, "log"), ctx->qry.head,
793 NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg); 793 NULL, ctx->qry.vpath, 0, NULL, NULL,
794 ctx->qry.showmsg);
794 cgit_tree_link("tree", NULL, hc(ctx, "tree"), ctx->qry.head, 795 cgit_tree_link("tree", NULL, hc(ctx, "tree"), ctx->qry.head,
795 ctx->qry.sha1, NULL); 796 ctx->qry.sha1, ctx->qry.vpath);
796 cgit_commit_link("commit", NULL, hc(ctx, "commit"), 797 cgit_commit_link("commit", NULL, hc(ctx, "commit"),
797 ctx->qry.head, ctx->qry.sha1, NULL, 0); 798 ctx->qry.head, ctx->qry.sha1, ctx->qry.vpath, 0);
798 cgit_diff_link("diff", NULL, hc(ctx, "diff"), ctx->qry.head, 799 cgit_diff_link("diff", NULL, hc(ctx, "diff"), ctx->qry.head,
799 ctx->qry.sha1, ctx->qry.sha2, NULL, 0); 800 ctx->qry.sha1, ctx->qry.sha2, ctx->qry.vpath, 0);
800 if (ctx->repo->max_stats) 801 if (ctx->repo->max_stats)
801 cgit_stats_link("stats", NULL, hc(ctx, "stats"), 802 cgit_stats_link("stats", NULL, hc(ctx, "stats"),
802 ctx->qry.head, NULL); 803 ctx->qry.head, ctx->qry.vpath);
803 if (ctx->repo->readme) 804 if (ctx->repo->readme)
804 reporevlink("about", "about", NULL, 805 reporevlink("about", "about", NULL,
805 hc(ctx, "about"), ctx->qry.head, NULL, 806 hc(ctx, "about"), ctx->qry.head, NULL,
806 NULL); 807 NULL);
807 html("</td><td class='form'>"); 808 html("</td><td class='form'>");
808 html("<form class='right' method='get' action='"); 809 html("<form class='right' method='get' action='");
809 if (ctx->cfg.virtual_root) 810 if (ctx->cfg.virtual_root)
810 html_url_path(cgit_fileurl(ctx->qry.repo, "log", 811 html_url_path(cgit_fileurl(ctx->qry.repo, "log",
811 ctx->qry.vpath, NULL)); 812 ctx->qry.vpath, NULL));
812 html("'>\n"); 813 html("'>\n");
813 cgit_add_hidden_formfields(1, 0, "log"); 814 cgit_add_hidden_formfields(1, 0, "log");
814 html("<select name='qt'>\n"); 815 html("<select name='qt'>\n");
815 html_option("grep", "log msg", ctx->qry.grep); 816 html_option("grep", "log msg", ctx->qry.grep);
816 html_option("author", "author", ctx->qry.grep); 817 html_option("author", "author", ctx->qry.grep);
817 html_option("committer", "committer", ctx->qry.grep); 818 html_option("committer", "committer", ctx->qry.grep);
818 html("</select>\n"); 819 html("</select>\n");
819 html("<input class='txt' type='text' size='10' name='q' value='"); 820 html("<input class='txt' type='text' size='10' name='q' value='");
820 html_attr(ctx->qry.search); 821 html_attr(ctx->qry.search);
821 html("'/>\n"); 822 html("'/>\n");
822 html("<input type='submit' value='search'/>\n"); 823 html("<input type='submit' value='search'/>\n");
823 html("</form>\n"); 824 html("</form>\n");
824 } else { 825 } else {
825 site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0); 826 site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0);
826 if (ctx->cfg.root_readme) 827 if (ctx->cfg.root_readme)
827 site_link("about", "about", NULL, hc(ctx, "about"), 828 site_link("about", "about", NULL, hc(ctx, "about"),
828 NULL, 0); 829 NULL, 0);
829 html("</td><td class='form'>"); 830 html("</td><td class='form'>");
830 html("<form method='get' action='"); 831 html("<form method='get' action='");
831 html_attr(cgit_rooturl()); 832 html_attr(cgit_rooturl());
832 html("'>\n"); 833 html("'>\n");
833 html("<input type='text' name='q' size='10' value='"); 834 html("<input type='text' name='q' size='10' value='");
834 html_attr(ctx->qry.search); 835 html_attr(ctx->qry.search);
835 html("'/>\n"); 836 html("'/>\n");
836 html("<input type='submit' value='search'/>\n"); 837 html("<input type='submit' value='search'/>\n");
837 html("</form>"); 838 html("</form>");
838 } 839 }
839 html("</td></tr></table>\n"); 840 html("</td></tr></table>\n");
840 if (ctx->qry.vpath) { 841 if (ctx->qry.vpath) {
841 html("<div class='path'>"); 842 html("<div class='path'>");
842 html("path: "); 843 html("path: ");
843 cgit_print_path_crumbs(ctx, ctx->qry.vpath); 844 cgit_print_path_crumbs(ctx, ctx->qry.vpath);
844 html("</div>"); 845 html("</div>");
845 } 846 }
846 html("<div class='content'>"); 847 html("<div class='content'>");
847} 848}
848 849
849void cgit_print_filemode(unsigned short mode) 850void cgit_print_filemode(unsigned short mode)
850{ 851{
851 if (S_ISDIR(mode)) 852 if (S_ISDIR(mode))
852 html("d"); 853 html("d");
853 else if (S_ISLNK(mode)) 854 else if (S_ISLNK(mode))
854 html("l"); 855 html("l");
855 else if (S_ISGITLINK(mode)) 856 else if (S_ISGITLINK(mode))
856 html("m"); 857 html("m");
857 else 858 else
858 html("-"); 859 html("-");
859 html_fileperm(mode >> 6); 860 html_fileperm(mode >> 6);
860 html_fileperm(mode >> 3); 861 html_fileperm(mode >> 3);
861 html_fileperm(mode); 862 html_fileperm(mode);
862} 863}
863 864
864void cgit_print_snapshot_links(const char *repo, const char *head, 865void cgit_print_snapshot_links(const char *repo, const char *head,
865 const char *hex, int snapshots) 866 const char *hex, int snapshots)
866{ 867{
867 const struct cgit_snapshot_format* f; 868 const struct cgit_snapshot_format* f;
868 char *prefix; 869 char *prefix;
869 char *filename; 870 char *filename;
870 unsigned char sha1[20]; 871 unsigned char sha1[20];
871 872
872 if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 && 873 if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 &&
873 (hex[0] == 'v' || hex[0] == 'V') && isdigit(hex[1])) 874 (hex[0] == 'v' || hex[0] == 'V') && isdigit(hex[1]))
874 hex++; 875 hex++;
875 prefix = xstrdup(fmt("%s-%s", cgit_repobasename(repo), hex)); 876 prefix = xstrdup(fmt("%s-%s", cgit_repobasename(repo), hex));
876 for (f = cgit_snapshot_formats; f->suffix; f++) { 877 for (f = cgit_snapshot_formats; f->suffix; f++) {
877 if (!(snapshots & f->bit)) 878 if (!(snapshots & f->bit))
878 continue; 879 continue;
879 filename = fmt("%s%s", prefix, f->suffix); 880 filename = fmt("%s%s", prefix, f->suffix);
880 cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); 881 cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename);
881 html("<br/>"); 882 html("<br/>");
882 } 883 }
883} 884}