-rw-r--r-- | ui-shared.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/ui-shared.c b/ui-shared.c index d08ede9..f366354 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -69,139 +69,150 @@ char *cgit_fileurl(const char *reponame, const char *pagename, | |||
69 | if (query) | 69 | if (query) |
70 | tmp = fmt("%s%s%s", tmp, delim, query); | 70 | tmp = fmt("%s%s%s", tmp, delim, query); |
71 | return tmp; | 71 | return tmp; |
72 | } | 72 | } |
73 | 73 | ||
74 | char *cgit_pageurl(const char *reponame, const char *pagename, | 74 | char *cgit_pageurl(const char *reponame, const char *pagename, |
75 | const char *query) | 75 | const char *query) |
76 | { | 76 | { |
77 | return cgit_fileurl(reponame,pagename,0,query); | 77 | return cgit_fileurl(reponame,pagename,0,query); |
78 | } | 78 | } |
79 | 79 | ||
80 | const char *cgit_repobasename(const char *reponame) | 80 | const char *cgit_repobasename(const char *reponame) |
81 | { | 81 | { |
82 | /* I assume we don't need to store more than one repo basename */ | 82 | /* I assume we don't need to store more than one repo basename */ |
83 | static char rvbuf[1024]; | 83 | static char rvbuf[1024]; |
84 | int p; | 84 | int p; |
85 | const char *rv; | 85 | const char *rv; |
86 | strncpy(rvbuf,reponame,sizeof(rvbuf)); | 86 | strncpy(rvbuf,reponame,sizeof(rvbuf)); |
87 | if(rvbuf[sizeof(rvbuf)-1]) | 87 | if(rvbuf[sizeof(rvbuf)-1]) |
88 | die("cgit_repobasename: truncated repository name '%s'", reponame); | 88 | die("cgit_repobasename: truncated repository name '%s'", reponame); |
89 | p = strlen(rvbuf)-1; | 89 | p = strlen(rvbuf)-1; |
90 | /* strip trailing slashes */ | 90 | /* strip trailing slashes */ |
91 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; | 91 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; |
92 | /* strip trailing .git */ | 92 | /* strip trailing .git */ |
93 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { | 93 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { |
94 | p -= 3; rvbuf[p--] = 0; | 94 | p -= 3; rvbuf[p--] = 0; |
95 | } | 95 | } |
96 | /* strip more trailing slashes if any */ | 96 | /* strip more trailing slashes if any */ |
97 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; | 97 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; |
98 | /* find last slash in the remaining string */ | 98 | /* find last slash in the remaining string */ |
99 | rv = strrchr(rvbuf,'/'); | 99 | rv = strrchr(rvbuf,'/'); |
100 | if(rv) | 100 | if(rv) |
101 | return ++rv; | 101 | return ++rv; |
102 | return rvbuf; | 102 | return rvbuf; |
103 | } | 103 | } |
104 | 104 | ||
105 | char *cgit_currurl() | 105 | char *cgit_currurl() |
106 | { | 106 | { |
107 | if (!ctx.cfg.virtual_root) | 107 | if (!ctx.cfg.virtual_root) |
108 | return ctx.cfg.script_name; | 108 | return ctx.cfg.script_name; |
109 | else if (ctx.qry.page) | 109 | else if (ctx.qry.page) |
110 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); | 110 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); |
111 | else if (ctx.qry.repo) | 111 | else if (ctx.qry.repo) |
112 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); | 112 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); |
113 | else | 113 | else |
114 | return fmt("%s/", ctx.cfg.virtual_root); | 114 | return fmt("%s/", ctx.cfg.virtual_root); |
115 | } | 115 | } |
116 | 116 | ||
117 | static void site_url(char *page, char *search) | 117 | static void site_url(char *page, char *search, int ofs) |
118 | { | 118 | { |
119 | char *delim = "?"; | 119 | char *delim = "?"; |
120 | 120 | ||
121 | if (ctx.cfg.virtual_root) { | 121 | if (ctx.cfg.virtual_root) { |
122 | html_attr(ctx.cfg.virtual_root); | 122 | html_attr(ctx.cfg.virtual_root); |
123 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') | 123 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
124 | html("/"); | 124 | html("/"); |
125 | } else | 125 | } else |
126 | html(ctx.cfg.script_name); | 126 | html(ctx.cfg.script_name); |
127 | 127 | ||
128 | if (page) { | 128 | if (page) { |
129 | htmlf("?p=%s", page); | 129 | htmlf("?p=%s", page); |
130 | delim = "&"; | 130 | delim = "&"; |
131 | } | 131 | } |
132 | if (search) { | 132 | if (search) { |
133 | html(delim); | 133 | html(delim); |
134 | html("q="); | 134 | html("q="); |
135 | html_attr(search); | 135 | html_attr(search); |
136 | delim = "&"; | ||
137 | } | ||
138 | if (ofs) { | ||
139 | html(delim); | ||
140 | htmlf("ofs=%d", ofs); | ||
136 | } | 141 | } |
137 | } | 142 | } |
138 | 143 | ||
139 | static void site_link(char *page, char *name, char *title, char *class, | 144 | static void site_link(char *page, char *name, char *title, char *class, |
140 | char *search) | 145 | char *search, int ofs) |
141 | { | 146 | { |
142 | html("<a"); | 147 | html("<a"); |
143 | if (title) { | 148 | if (title) { |
144 | html(" title='"); | 149 | html(" title='"); |
145 | html_attr(title); | 150 | html_attr(title); |
146 | html("'"); | 151 | html("'"); |
147 | } | 152 | } |
148 | if (class) { | 153 | if (class) { |
149 | html(" class='"); | 154 | html(" class='"); |
150 | html_attr(class); | 155 | html_attr(class); |
151 | html("'"); | 156 | html("'"); |
152 | } | 157 | } |
153 | html(" href='"); | 158 | html(" href='"); |
154 | site_url(page, search); | 159 | site_url(page, search, ofs); |
155 | html("'>"); | 160 | html("'>"); |
156 | html_txt(name); | 161 | html_txt(name); |
157 | html("</a>"); | 162 | html("</a>"); |
158 | } | 163 | } |
159 | 164 | ||
165 | void cgit_index_link(char *name, char *title, char *class, char *pattern, | ||
166 | int ofs) | ||
167 | { | ||
168 | site_link(NULL, name, title, class, pattern, ofs); | ||
169 | } | ||
170 | |||
160 | static char *repolink(char *title, char *class, char *page, char *head, | 171 | static char *repolink(char *title, char *class, char *page, char *head, |
161 | char *path) | 172 | char *path) |
162 | { | 173 | { |
163 | char *delim = "?"; | 174 | char *delim = "?"; |
164 | 175 | ||
165 | html("<a"); | 176 | html("<a"); |
166 | if (title) { | 177 | if (title) { |
167 | html(" title='"); | 178 | html(" title='"); |
168 | html_attr(title); | 179 | html_attr(title); |
169 | html("'"); | 180 | html("'"); |
170 | } | 181 | } |
171 | if (class) { | 182 | if (class) { |
172 | html(" class='"); | 183 | html(" class='"); |
173 | html_attr(class); | 184 | html_attr(class); |
174 | html("'"); | 185 | html("'"); |
175 | } | 186 | } |
176 | html(" href='"); | 187 | html(" href='"); |
177 | if (ctx.cfg.virtual_root) { | 188 | if (ctx.cfg.virtual_root) { |
178 | html_attr(ctx.cfg.virtual_root); | 189 | html_attr(ctx.cfg.virtual_root); |
179 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') | 190 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
180 | html("/"); | 191 | html("/"); |
181 | html_attr(ctx.repo->url); | 192 | html_attr(ctx.repo->url); |
182 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') | 193 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
183 | html("/"); | 194 | html("/"); |
184 | if (page) { | 195 | if (page) { |
185 | html(page); | 196 | html(page); |
186 | html("/"); | 197 | html("/"); |
187 | if (path) | 198 | if (path) |
188 | html_attr(path); | 199 | html_attr(path); |
189 | } | 200 | } |
190 | } else { | 201 | } else { |
191 | html(ctx.cfg.script_name); | 202 | html(ctx.cfg.script_name); |
192 | html("?url="); | 203 | html("?url="); |
193 | html_attr(ctx.repo->url); | 204 | html_attr(ctx.repo->url); |
194 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') | 205 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
195 | html("/"); | 206 | html("/"); |
196 | if (page) { | 207 | if (page) { |
197 | html(page); | 208 | html(page); |
198 | html("/"); | 209 | html("/"); |
199 | if (path) | 210 | if (path) |
200 | html_attr(path); | 211 | html_attr(path); |
201 | } | 212 | } |
202 | delim = "&"; | 213 | delim = "&"; |
203 | } | 214 | } |
204 | if (head && strcmp(head, ctx.repo->defbranch)) { | 215 | if (head && strcmp(head, ctx.repo->defbranch)) { |
205 | html(delim); | 216 | html(delim); |
206 | html("h="); | 217 | html("h="); |
207 | html_attr(head); | 218 | html_attr(head); |
@@ -551,96 +562,97 @@ void cgit_print_pageheader(struct cgit_context *ctx) | |||
551 | if (ctx->repo) { | 562 | if (ctx->repo) { |
552 | html(" colspan='2'>"); | 563 | html(" colspan='2'>"); |
553 | html_txt(ctx->repo->desc); | 564 | html_txt(ctx->repo->desc); |
554 | } else { | 565 | } else { |
555 | html(">"); | 566 | html(">"); |
556 | if (ctx->cfg.root_desc) | 567 | if (ctx->cfg.root_desc) |
557 | html_txt(ctx->cfg.root_desc); | 568 | html_txt(ctx->cfg.root_desc); |
558 | else if (ctx->cfg.index_info) | 569 | else if (ctx->cfg.index_info) |
559 | html_include(ctx->cfg.index_info); | 570 | html_include(ctx->cfg.index_info); |
560 | } | 571 | } |
561 | html("</td></tr></table>\n"); | 572 | html("</td></tr></table>\n"); |
562 | 573 | ||
563 | html("<table class='tabs'><tr><td>\n"); | 574 | html("<table class='tabs'><tr><td>\n"); |
564 | if (ctx->repo) { | 575 | if (ctx->repo) { |
565 | reporevlink(NULL, "summary", NULL, hc(cmd, "summary"), | 576 | reporevlink(NULL, "summary", NULL, hc(cmd, "summary"), |
566 | ctx->qry.head, NULL, NULL); | 577 | ctx->qry.head, NULL, NULL); |
567 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, | 578 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, |
568 | ctx->qry.sha1, NULL); | 579 | ctx->qry.sha1, NULL); |
569 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, | 580 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, |
570 | NULL, NULL, 0, NULL, NULL); | 581 | NULL, NULL, 0, NULL, NULL); |
571 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, | 582 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, |
572 | ctx->qry.sha1, NULL); | 583 | ctx->qry.sha1, NULL); |
573 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), | 584 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), |
574 | ctx->qry.head, ctx->qry.sha1); | 585 | ctx->qry.head, ctx->qry.sha1); |
575 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, | 586 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, |
576 | ctx->qry.sha1, ctx->qry.sha2, NULL); | 587 | ctx->qry.sha1, ctx->qry.sha2, NULL); |
577 | if (ctx->repo->readme) | 588 | if (ctx->repo->readme) |
578 | reporevlink("about", "about", NULL, | 589 | reporevlink("about", "about", NULL, |
579 | hc(cmd, "about"), ctx->qry.head, NULL, | 590 | hc(cmd, "about"), ctx->qry.head, NULL, |
580 | NULL); | 591 | NULL); |
581 | html("</td><td class='form'>"); | 592 | html("</td><td class='form'>"); |
582 | html("<form class='right' method='get' action='"); | 593 | html("<form class='right' method='get' action='"); |
583 | if (ctx->cfg.virtual_root) | 594 | if (ctx->cfg.virtual_root) |
584 | html_attr(cgit_fileurl(ctx->qry.repo, "log", | 595 | html_attr(cgit_fileurl(ctx->qry.repo, "log", |
585 | ctx->qry.path, NULL)); | 596 | ctx->qry.path, NULL)); |
586 | html("'>\n"); | 597 | html("'>\n"); |
587 | add_hidden_formfields(1, 0, "log"); | 598 | add_hidden_formfields(1, 0, "log"); |
588 | html("<select name='qt'>\n"); | 599 | html("<select name='qt'>\n"); |
589 | html_option("grep", "log msg", ctx->qry.grep); | 600 | html_option("grep", "log msg", ctx->qry.grep); |
590 | html_option("author", "author", ctx->qry.grep); | 601 | html_option("author", "author", ctx->qry.grep); |
591 | html_option("committer", "committer", ctx->qry.grep); | 602 | html_option("committer", "committer", ctx->qry.grep); |
592 | html("</select>\n"); | 603 | html("</select>\n"); |
593 | html("<input class='txt' type='text' size='10' name='q' value='"); | 604 | html("<input class='txt' type='text' size='10' name='q' value='"); |
594 | html_attr(ctx->qry.search); | 605 | html_attr(ctx->qry.search); |
595 | html("'/>\n"); | 606 | html("'/>\n"); |
596 | html("<input type='submit' value='search'/>\n"); | 607 | html("<input type='submit' value='search'/>\n"); |
597 | html("</form>\n"); | 608 | html("</form>\n"); |
598 | } else { | 609 | } else { |
599 | site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL); | 610 | site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0); |
600 | if (ctx->cfg.root_readme) | 611 | if (ctx->cfg.root_readme) |
601 | site_link("about", "about", NULL, hc(cmd, "about"), NULL); | 612 | site_link("about", "about", NULL, hc(cmd, "about"), |
613 | NULL, 0); | ||
602 | html("</td><td class='form'>"); | 614 | html("</td><td class='form'>"); |
603 | html("<form method='get' action='"); | 615 | html("<form method='get' action='"); |
604 | html_attr(cgit_rooturl()); | 616 | html_attr(cgit_rooturl()); |
605 | html("'>\n"); | 617 | html("'>\n"); |
606 | html("<input type='text' name='q' size='10' value='"); | 618 | html("<input type='text' name='q' size='10' value='"); |
607 | html_attr(ctx->qry.search); | 619 | html_attr(ctx->qry.search); |
608 | html("'/>\n"); | 620 | html("'/>\n"); |
609 | html("<input type='submit' value='search'/>\n"); | 621 | html("<input type='submit' value='search'/>\n"); |
610 | html("</form>"); | 622 | html("</form>"); |
611 | } | 623 | } |
612 | html("</td></tr></table>\n"); | 624 | html("</td></tr></table>\n"); |
613 | html("<div class='content'>"); | 625 | html("<div class='content'>"); |
614 | } | 626 | } |
615 | 627 | ||
616 | void cgit_print_filemode(unsigned short mode) | 628 | void cgit_print_filemode(unsigned short mode) |
617 | { | 629 | { |
618 | if (S_ISDIR(mode)) | 630 | if (S_ISDIR(mode)) |
619 | html("d"); | 631 | html("d"); |
620 | else if (S_ISLNK(mode)) | 632 | else if (S_ISLNK(mode)) |
621 | html("l"); | 633 | html("l"); |
622 | else if (S_ISGITLINK(mode)) | 634 | else if (S_ISGITLINK(mode)) |
623 | html("m"); | 635 | html("m"); |
624 | else | 636 | else |
625 | html("-"); | 637 | html("-"); |
626 | html_fileperm(mode >> 6); | 638 | html_fileperm(mode >> 6); |
627 | html_fileperm(mode >> 3); | 639 | html_fileperm(mode >> 3); |
628 | html_fileperm(mode); | 640 | html_fileperm(mode); |
629 | } | 641 | } |
630 | 642 | ||
631 | void cgit_print_snapshot_links(const char *repo, const char *head, | 643 | void cgit_print_snapshot_links(const char *repo, const char *head, |
632 | const char *hex, int snapshots) | 644 | const char *hex, int snapshots) |
633 | { | 645 | { |
634 | const struct cgit_snapshot_format* f; | 646 | const struct cgit_snapshot_format* f; |
635 | char *filename; | 647 | char *filename; |
636 | 648 | ||
637 | for (f = cgit_snapshot_formats; f->suffix; f++) { | 649 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
638 | if (!(snapshots & f->bit)) | 650 | if (!(snapshots & f->bit)) |
639 | continue; | 651 | continue; |
640 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, | 652 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, |
641 | f->suffix); | 653 | f->suffix); |
642 | cgit_snapshot_link(filename, NULL, NULL, (char *)head, | 654 | cgit_snapshot_link(filename, NULL, NULL, (char *)head, |
643 | (char *)hex, filename); | 655 | (char *)hex, filename); |
644 | html("<br/>"); | 656 | html("<br/>"); |
645 | } | 657 | } |
646 | } | 658 | } |