aboutsummaryrefslogtreecommitdiffstats
path: root/ui-shared.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-shared.c')
-rw-r--r--ui-shared.c86
1 files changed, 74 insertions, 12 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 5aa9119..43166af 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -133,7 +133,7 @@ char *cgit_currurl()
133 return fmt("%s/", ctx.cfg.virtual_root); 133 return fmt("%s/", ctx.cfg.virtual_root);
134} 134}
135 135
136static void site_url(const char *page, const char *search, int ofs) 136static void site_url(const char *page, const char *search, const char *sort, int ofs)
137{ 137{
138 char *delim = "?"; 138 char *delim = "?";
139 139
@@ -154,6 +154,12 @@ static void site_url(const char *page, const char *search, int ofs)
154 html_attr(search); 154 html_attr(search);
155 delim = "&"; 155 delim = "&";
156 } 156 }
157 if (sort) {
158 html(delim);
159 html("s=");
160 html_attr(sort);
161 delim = "&";
162 }
157 if (ofs) { 163 if (ofs) {
158 html(delim); 164 html(delim);
159 htmlf("ofs=%d", ofs); 165 htmlf("ofs=%d", ofs);
@@ -161,7 +167,7 @@ static void site_url(const char *page, const char *search, int ofs)
161} 167}
162 168
163static void site_link(const char *page, const char *name, const char *title, 169static void site_link(const char *page, const char *name, const char *title,
164 const char *class, const char *search, int ofs) 170 const char *class, const char *search, const char *sort, int ofs)
165{ 171{
166 html("<a"); 172 html("<a");
167 if (title) { 173 if (title) {
@@ -175,16 +181,16 @@ static void site_link(const char *page, const char *name, const char *title,
175 html("'"); 181 html("'");
176 } 182 }
177 html(" href='"); 183 html(" href='");
178 site_url(page, search, ofs); 184 site_url(page, search, sort, ofs);
179 html("'>"); 185 html("'>");
180 html_txt(name); 186 html_txt(name);
181 html("</a>"); 187 html("</a>");
182} 188}
183 189
184void cgit_index_link(const char *name, const char *title, const char *class, 190void cgit_index_link(const char *name, const char *title, const char *class,
185 const char *pattern, int ofs) 191 const char *pattern, const char *sort, int ofs)
186{ 192{
187 site_link(NULL, name, title, class, pattern, ofs); 193 site_link(NULL, name, title, class, pattern, sort, ofs);
188} 194}
189 195
190static char *repolink(const char *title, const char *class, const char *page, 196static char *repolink(const char *title, const char *class, const char *page,
@@ -288,7 +294,7 @@ void cgit_log_link(const char *name, const char *title, const char *class,
288 char *delim; 294 char *delim;
289 295
290 delim = repolink(title, class, "log", head, path); 296 delim = repolink(title, class, "log", head, path);
291 if (rev && strcmp(rev, ctx.qry.head)) { 297 if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) {
292 html(delim); 298 html(delim);
293 html("id="); 299 html("id=");
294 html_url_arg(rev); 300 html_url_arg(rev);
@@ -332,7 +338,7 @@ void cgit_commit_link(char *name, const char *title, const char *class,
332 char *delim; 338 char *delim;
333 339
334 delim = repolink(title, class, "commit", head, path); 340 delim = repolink(title, class, "commit", head, path);
335 if (rev && strcmp(rev, ctx.qry.head)) { 341 if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) {
336 html(delim); 342 html(delim);
337 html("id="); 343 html("id=");
338 html_url_arg(rev); 344 html_url_arg(rev);
@@ -428,7 +434,7 @@ void cgit_self_link(char *name, const char *title, const char *class,
428 struct cgit_context *ctx) 434 struct cgit_context *ctx)
429{ 435{
430 if (!strcmp(ctx->qry.page, "repolist")) 436 if (!strcmp(ctx->qry.page, "repolist"))
431 return cgit_index_link(name, title, class, ctx->qry.search, 437 return cgit_index_link(name, title, class, ctx->qry.search, ctx->qry.sort,
432 ctx->qry.ofs); 438 ctx->qry.ofs);
433 else if (!strcmp(ctx->qry.page, "summary")) 439 else if (!strcmp(ctx->qry.page, "summary"))
434 return cgit_summary_link(name, title, class, ctx->qry.head); 440 return cgit_summary_link(name, title, class, ctx->qry.head);
@@ -503,6 +509,62 @@ void cgit_object_link(struct object *obj)
503 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); 509 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
504} 510}
505 511
512struct string_list_item *lookup_path(struct string_list *list,
513 const char *path)
514{
515 struct string_list_item *item;
516
517 while (path && path[0]) {
518 if ((item = string_list_lookup(list, path)))
519 return item;
520 if (!(path = strchr(path, '/')))
521 break;
522 path++;
523 }
524 return NULL;
525}
526
527void cgit_submodule_link(const char *class, char *path, const char *rev)
528{
529 struct string_list *list;
530 struct string_list_item *item;
531 char tail, *dir;
532 size_t len;
533
534 tail = 0;
535 list = &ctx.repo->submodules;
536 item = lookup_path(list, path);
537 if (!item) {
538 len = strlen(path);
539 tail = path[len - 1];
540 if (tail == '/') {
541 path[len - 1] = 0;
542 item = lookup_path(list, path);
543 }
544 }
545 html("<a ");
546 if (class)
547 htmlf("class='%s' ", class);
548 html("href='");
549 if (item) {
550 html_attr(fmt(item->util, rev));
551 } else if (ctx.repo->module_link) {
552 dir = strrchr(path, '/');
553 if (dir)
554 dir++;
555 else
556 dir = path;
557 html_attr(fmt(ctx.repo->module_link, dir, rev));
558 } else {
559 html("#");
560 }
561 html("'>");
562 html_txt(path);
563 html("</a>");
564 if (item && tail)
565 path[len - 1] = tail;
566}
567
506void cgit_print_date(time_t secs, const char *format, int local_time) 568void cgit_print_date(time_t secs, const char *format, int local_time)
507{ 569{
508 char buf[64]; 570 char buf[64];
@@ -613,7 +675,7 @@ void cgit_print_docstart(struct cgit_context *ctx)
613 html_attr(ctx->cfg.favicon); 675 html_attr(ctx->cfg.favicon);
614 html("'/>\n"); 676 html("'/>\n");
615 } 677 }
616 if (host && ctx->repo) { 678 if (host && ctx->repo && ctx->qry.head) {
617 html("<link rel='alternate' title='Atom feed' href='"); 679 html("<link rel='alternate' title='Atom feed' href='");
618 html(cgit_httpscheme()); 680 html(cgit_httpscheme());
619 html_attr(cgit_hosturl()); 681 html_attr(cgit_hosturl());
@@ -782,7 +844,7 @@ static void print_header(struct cgit_context *ctx)
782 844
783 html("<td class='main'>"); 845 html("<td class='main'>");
784 if (ctx->repo) { 846 if (ctx->repo) {
785 cgit_index_link("index", NULL, NULL, NULL, 0); 847 cgit_index_link("index", NULL, NULL, NULL, NULL, 0);
786 html(" : "); 848 html(" : ");
787 cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); 849 cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL);
788 html("</td><td class='form'>"); 850 html("</td><td class='form'>");
@@ -858,10 +920,10 @@ void cgit_print_pageheader(struct cgit_context *ctx)
858 html("<input type='submit' value='search'/>\n"); 920 html("<input type='submit' value='search'/>\n");
859 html("</form>\n"); 921 html("</form>\n");
860 } else { 922 } else {
861 site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0); 923 site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, NULL, 0);
862 if (ctx->cfg.root_readme) 924 if (ctx->cfg.root_readme)
863 site_link("about", "about", NULL, hc(ctx, "about"), 925 site_link("about", "about", NULL, hc(ctx, "about"),
864 NULL, 0); 926 NULL, NULL, 0);
865 html("</td><td class='form'>"); 927 html("</td><td class='form'>");
866 html("<form method='get' action='"); 928 html("<form method='get' action='");
867 html_attr(cgit_rooturl()); 929 html_attr(cgit_rooturl());