summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
authorJohan Herland <johan@herland.net>2010-06-09 23:09:35 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2010-06-19 08:40:24 (UTC)
commit685872b770be2af643d00365d5358e46687f7385 (patch) (unidiff)
tree279a8399c3e9b189a7171df6ca009a58bf1bb8c7 /ui-shared.c
parent34c2331d2c33ea28743a2ee3e62f7337ae9887f6 (diff)
downloadcgit-685872b770be2af643d00365d5358e46687f7385.zip
cgit-685872b770be2af643d00365d5358e46687f7385.tar.gz
cgit-685872b770be2af643d00365d5358e46687f7385.tar.bz2
ui-commit: Preserve path limit in links to commit page
This includes adding a path argument to cgit_commit_link() and updating all its callers. The callers from within the commit page (i.e. the "commit", "unidiff"/"side-by-side diff" and "parent" links) all preserve the path limit of the current commit page. All other callers pass NULL (i.e. no path limit). Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/ui-shared.c b/ui-shared.c
index d5c4c10..372b9e7 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -290,76 +290,77 @@ void cgit_log_link(const char *name, const char *title, const char *class,
290 delim = repolink(title, class, "log", head, path); 290 delim = repolink(title, class, "log", head, path);
291 if (rev && strcmp(rev, ctx.qry.head)) { 291 if (rev && strcmp(rev, ctx.qry.head)) {
292 html(delim); 292 html(delim);
293 html("id="); 293 html("id=");
294 html_url_arg(rev); 294 html_url_arg(rev);
295 delim = "&"; 295 delim = "&";
296 } 296 }
297 if (grep && pattern) { 297 if (grep && pattern) {
298 html(delim); 298 html(delim);
299 html("qt="); 299 html("qt=");
300 html_url_arg(grep); 300 html_url_arg(grep);
301 delim = "&"; 301 delim = "&";
302 html(delim); 302 html(delim);
303 html("q="); 303 html("q=");
304 html_url_arg(pattern); 304 html_url_arg(pattern);
305 } 305 }
306 if (ofs > 0) { 306 if (ofs > 0) {
307 html(delim); 307 html(delim);
308 html("ofs="); 308 html("ofs=");
309 htmlf("%d", ofs); 309 htmlf("%d", ofs);
310 delim = "&"; 310 delim = "&";
311 } 311 }
312 if (showmsg) { 312 if (showmsg) {
313 html(delim); 313 html(delim);
314 html("showmsg=1"); 314 html("showmsg=1");
315 } 315 }
316 html("'>"); 316 html("'>");
317 html_txt(name); 317 html_txt(name);
318 html("</a>"); 318 html("</a>");
319} 319}
320 320
321void cgit_commit_link(char *name, const char *title, const char *class, 321void cgit_commit_link(char *name, const char *title, const char *class,
322 const char *head, const char *rev, int toggle_ssdiff) 322 const char *head, const char *rev, const char *path,
323 int toggle_ssdiff)
323{ 324{
324 if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { 325 if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
325 name[ctx.cfg.max_msg_len] = '\0'; 326 name[ctx.cfg.max_msg_len] = '\0';
326 name[ctx.cfg.max_msg_len - 1] = '.'; 327 name[ctx.cfg.max_msg_len - 1] = '.';
327 name[ctx.cfg.max_msg_len - 2] = '.'; 328 name[ctx.cfg.max_msg_len - 2] = '.';
328 name[ctx.cfg.max_msg_len - 3] = '.'; 329 name[ctx.cfg.max_msg_len - 3] = '.';
329 } 330 }
330 331
331 char *delim; 332 char *delim;
332 333
333 delim = repolink(title, class, "commit", head, NULL); 334 delim = repolink(title, class, "commit", head, path);
334 if (rev && strcmp(rev, ctx.qry.head)) { 335 if (rev && strcmp(rev, ctx.qry.head)) {
335 html(delim); 336 html(delim);
336 html("id="); 337 html("id=");
337 html_url_arg(rev); 338 html_url_arg(rev);
338 delim = "&amp;"; 339 delim = "&amp;";
339 } 340 }
340 if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { 341 if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) {
341 html(delim); 342 html(delim);
342 html("ss=1"); 343 html("ss=1");
343 } 344 }
344 html("'>"); 345 html("'>");
345 html_txt(name); 346 html_txt(name);
346 html("</a>"); 347 html("</a>");
347} 348}
348 349
349void cgit_refs_link(const char *name, const char *title, const char *class, 350void cgit_refs_link(const char *name, const char *title, const char *class,
350 const char *head, const char *rev, const char *path) 351 const char *head, const char *rev, const char *path)
351{ 352{
352 reporevlink("refs", name, title, class, head, rev, path); 353 reporevlink("refs", name, title, class, head, rev, path);
353} 354}
354 355
355void cgit_snapshot_link(const char *name, const char *title, const char *class, 356void cgit_snapshot_link(const char *name, const char *title, const char *class,
356 const char *head, const char *rev, 357 const char *head, const char *rev,
357 const char *archivename) 358 const char *archivename)
358{ 359{
359 reporevlink("snapshot", name, title, class, head, rev, archivename); 360 reporevlink("snapshot", name, title, class, head, rev, archivename);
360} 361}
361 362
362void cgit_diff_link(const char *name, const char *title, const char *class, 363void cgit_diff_link(const char *name, const char *title, const char *class,
363 const char *head, const char *new_rev, const char *old_rev, 364 const char *head, const char *new_rev, const char *old_rev,
364 const char *path, int toggle_ssdiff) 365 const char *path, int toggle_ssdiff)
365{ 366{
@@ -437,65 +438,65 @@ void cgit_self_link(char *name, const char *title, const char *class,
437 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 438 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
438 ctx->qry.path); 439 ctx->qry.path);
439 else if (!strcmp(ctx->qry.page, "snapshot")) 440 else if (!strcmp(ctx->qry.page, "snapshot"))
440 return cgit_snapshot_link(name, title, class, ctx->qry.head, 441 return cgit_snapshot_link(name, title, class, ctx->qry.head,
441 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 442 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
442 ctx->qry.path); 443 ctx->qry.path);
443 else if (!strcmp(ctx->qry.page, "diff")) 444 else if (!strcmp(ctx->qry.page, "diff"))
444 return cgit_diff_link(name, title, class, ctx->qry.head, 445 return cgit_diff_link(name, title, class, ctx->qry.head,
445 ctx->qry.sha1, ctx->qry.sha2, 446 ctx->qry.sha1, ctx->qry.sha2,
446 ctx->qry.path, 0); 447 ctx->qry.path, 0);
447 else if (!strcmp(ctx->qry.page, "stats")) 448 else if (!strcmp(ctx->qry.page, "stats"))
448 return cgit_stats_link(name, title, class, ctx->qry.head, 449 return cgit_stats_link(name, title, class, ctx->qry.head,
449 ctx->qry.path); 450 ctx->qry.path);
450 451
451 /* Don't known how to make link for this page */ 452 /* Don't known how to make link for this page */
452 repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path); 453 repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path);
453 html("><!-- cgit_self_link() doesn't know how to make link for page '"); 454 html("><!-- cgit_self_link() doesn't know how to make link for page '");
454 html_txt(ctx->qry.page); 455 html_txt(ctx->qry.page);
455 html("' -->"); 456 html("' -->");
456 html_txt(name); 457 html_txt(name);
457 html("</a>"); 458 html("</a>");
458} 459}
459 460
460void cgit_object_link(struct object *obj) 461void cgit_object_link(struct object *obj)
461{ 462{
462 char *page, *shortrev, *fullrev, *name; 463 char *page, *shortrev, *fullrev, *name;
463 464
464 fullrev = sha1_to_hex(obj->sha1); 465 fullrev = sha1_to_hex(obj->sha1);
465 shortrev = xstrdup(fullrev); 466 shortrev = xstrdup(fullrev);
466 shortrev[10] = '\0'; 467 shortrev[10] = '\0';
467 if (obj->type == OBJ_COMMIT) { 468 if (obj->type == OBJ_COMMIT) {
468 cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, 469 cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
469 ctx.qry.head, fullrev, 0); 470 ctx.qry.head, fullrev, NULL, 0);
470 return; 471 return;
471 } else if (obj->type == OBJ_TREE) 472 } else if (obj->type == OBJ_TREE)
472 page = "tree"; 473 page = "tree";
473 else if (obj->type == OBJ_TAG) 474 else if (obj->type == OBJ_TAG)
474 page = "tag"; 475 page = "tag";
475 else 476 else
476 page = "blob"; 477 page = "blob";
477 name = fmt("%s %s...", typename(obj->type), shortrev); 478 name = fmt("%s %s...", typename(obj->type), shortrev);
478 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); 479 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
479} 480}
480 481
481void cgit_print_date(time_t secs, const char *format, int local_time) 482void cgit_print_date(time_t secs, const char *format, int local_time)
482{ 483{
483 char buf[64]; 484 char buf[64];
484 struct tm *time; 485 struct tm *time;
485 486
486 if (!secs) 487 if (!secs)
487 return; 488 return;
488 if(local_time) 489 if(local_time)
489 time = localtime(&secs); 490 time = localtime(&secs);
490 else 491 else
491 time = gmtime(&secs); 492 time = gmtime(&secs);
492 strftime(buf, sizeof(buf)-1, format, time); 493 strftime(buf, sizeof(buf)-1, format, time);
493 html_txt(buf); 494 html_txt(buf);
494} 495}
495 496
496void cgit_print_age(time_t t, time_t max_relative, const char *format) 497void cgit_print_age(time_t t, time_t max_relative, const char *format)
497{ 498{
498 time_t now, secs; 499 time_t now, secs;
499 500
500 if (!t) 501 if (!t)
501 return; 502 return;
@@ -764,65 +765,65 @@ static void print_header(struct cgit_context *ctx)
764 765
765 html("<tr><td class='sub'>"); 766 html("<tr><td class='sub'>");
766 if (ctx->repo) { 767 if (ctx->repo) {
767 html_txt(ctx->repo->desc); 768 html_txt(ctx->repo->desc);
768 html("</td><td class='sub right'>"); 769 html("</td><td class='sub right'>");
769 html_txt(ctx->repo->owner); 770 html_txt(ctx->repo->owner);
770 } else { 771 } else {
771 if (ctx->cfg.root_desc) 772 if (ctx->cfg.root_desc)
772 html_txt(ctx->cfg.root_desc); 773 html_txt(ctx->cfg.root_desc);
773 else if (ctx->cfg.index_info) 774 else if (ctx->cfg.index_info)
774 html_include(ctx->cfg.index_info); 775 html_include(ctx->cfg.index_info);
775 } 776 }
776 html("</td></tr></table>\n"); 777 html("</td></tr></table>\n");
777} 778}
778 779
779void cgit_print_pageheader(struct cgit_context *ctx) 780void cgit_print_pageheader(struct cgit_context *ctx)
780{ 781{
781 html("<div id='cgit'>"); 782 html("<div id='cgit'>");
782 if (!ctx->cfg.noheader) 783 if (!ctx->cfg.noheader)
783 print_header(ctx); 784 print_header(ctx);
784 785
785 html("<table class='tabs'><tr><td>\n"); 786 html("<table class='tabs'><tr><td>\n");
786 if (ctx->repo) { 787 if (ctx->repo) {
787 cgit_summary_link("summary", NULL, hc(ctx, "summary"), 788 cgit_summary_link("summary", NULL, hc(ctx, "summary"),
788 ctx->qry.head); 789 ctx->qry.head);
789 cgit_refs_link("refs", NULL, hc(ctx, "refs"), ctx->qry.head, 790 cgit_refs_link("refs", NULL, hc(ctx, "refs"), ctx->qry.head,
790 ctx->qry.sha1, NULL); 791 ctx->qry.sha1, NULL);
791 cgit_log_link("log", NULL, hc(ctx, "log"), ctx->qry.head, 792 cgit_log_link("log", NULL, hc(ctx, "log"), ctx->qry.head,
792 NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg); 793 NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg);
793 cgit_tree_link("tree", NULL, hc(ctx, "tree"), ctx->qry.head, 794 cgit_tree_link("tree", NULL, hc(ctx, "tree"), ctx->qry.head,
794 ctx->qry.sha1, NULL); 795 ctx->qry.sha1, NULL);
795 cgit_commit_link("commit", NULL, hc(ctx, "commit"), 796 cgit_commit_link("commit", NULL, hc(ctx, "commit"),
796 ctx->qry.head, ctx->qry.sha1, 0); 797 ctx->qry.head, ctx->qry.sha1, NULL, 0);
797 cgit_diff_link("diff", NULL, hc(ctx, "diff"), ctx->qry.head, 798 cgit_diff_link("diff", NULL, hc(ctx, "diff"), ctx->qry.head,
798 ctx->qry.sha1, ctx->qry.sha2, NULL, 0); 799 ctx->qry.sha1, ctx->qry.sha2, NULL, 0);
799 if (ctx->repo->max_stats) 800 if (ctx->repo->max_stats)
800 cgit_stats_link("stats", NULL, hc(ctx, "stats"), 801 cgit_stats_link("stats", NULL, hc(ctx, "stats"),
801 ctx->qry.head, NULL); 802 ctx->qry.head, NULL);
802 if (ctx->repo->readme) 803 if (ctx->repo->readme)
803 reporevlink("about", "about", NULL, 804 reporevlink("about", "about", NULL,
804 hc(ctx, "about"), ctx->qry.head, NULL, 805 hc(ctx, "about"), ctx->qry.head, NULL,
805 NULL); 806 NULL);
806 html("</td><td class='form'>"); 807 html("</td><td class='form'>");
807 html("<form class='right' method='get' action='"); 808 html("<form class='right' method='get' action='");
808 if (ctx->cfg.virtual_root) 809 if (ctx->cfg.virtual_root)
809 html_url_path(cgit_fileurl(ctx->qry.repo, "log", 810 html_url_path(cgit_fileurl(ctx->qry.repo, "log",
810 ctx->qry.vpath, NULL)); 811 ctx->qry.vpath, NULL));
811 html("'>\n"); 812 html("'>\n");
812 cgit_add_hidden_formfields(1, 0, "log"); 813 cgit_add_hidden_formfields(1, 0, "log");
813 html("<select name='qt'>\n"); 814 html("<select name='qt'>\n");
814 html_option("grep", "log msg", ctx->qry.grep); 815 html_option("grep", "log msg", ctx->qry.grep);
815 html_option("author", "author", ctx->qry.grep); 816 html_option("author", "author", ctx->qry.grep);
816 html_option("committer", "committer", ctx->qry.grep); 817 html_option("committer", "committer", ctx->qry.grep);
817 html("</select>\n"); 818 html("</select>\n");
818 html("<input class='txt' type='text' size='10' name='q' value='"); 819 html("<input class='txt' type='text' size='10' name='q' value='");
819 html_attr(ctx->qry.search); 820 html_attr(ctx->qry.search);
820 html("'/>\n"); 821 html("'/>\n");
821 html("<input type='submit' value='search'/>\n"); 822 html("<input type='submit' value='search'/>\n");
822 html("</form>\n"); 823 html("</form>\n");
823 } else { 824 } else {
824 site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0); 825 site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0);
825 if (ctx->cfg.root_readme) 826 if (ctx->cfg.root_readme)
826 site_link("about", "about", NULL, hc(ctx, "about"), 827 site_link("about", "about", NULL, hc(ctx, "about"),
827 NULL, 0); 828 NULL, 0);
828 html("</td><td class='form'>"); 829 html("</td><td class='form'>");