summaryrefslogtreecommitdiffabout
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
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 (more/less context) (ignore whitespace changes)
-rw-r--r--ui-commit.c9
-rw-r--r--ui-log.c4
-rw-r--r--ui-refs.c2
-rw-r--r--ui-shared.c9
-rw-r--r--ui-shared.h3
5 files changed, 15 insertions, 12 deletions
diff --git a/ui-commit.c b/ui-commit.c
index 1793921..2d98ed9 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -49,54 +49,55 @@ void cgit_print_commit(char *hex, const char *prefix)
49 html("</td></tr>\n"); 49 html("</td></tr>\n");
50 html("<tr><th>committer</th><td>"); 50 html("<tr><th>committer</th><td>");
51 html_txt(info->committer); 51 html_txt(info->committer);
52 if (!ctx.cfg.noplainemail) { 52 if (!ctx.cfg.noplainemail) {
53 html(" "); 53 html(" ");
54 html_txt(info->committer_email); 54 html_txt(info->committer_email);
55 } 55 }
56 html("</td><td class='right'>"); 56 html("</td><td class='right'>");
57 cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time); 57 cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
58 html("</td></tr>\n"); 58 html("</td></tr>\n");
59 html("<tr><th>commit</th><td colspan='2' class='sha1'>"); 59 html("<tr><th>commit</th><td colspan='2' class='sha1'>");
60 tmp = sha1_to_hex(commit->object.sha1); 60 tmp = sha1_to_hex(commit->object.sha1);
61 cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, 0); 61 cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix, 0);
62 html(" ("); 62 html(" (");
63 cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix); 63 cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);
64 html(") ("); 64 html(") (");
65 if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) 65 if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))
66 cgit_commit_link("unidiff", NULL, NULL, ctx.qry.head, tmp, 1); 66 cgit_commit_link("unidiff", NULL, NULL, ctx.qry.head, tmp, prefix, 1);
67 else 67 else
68 cgit_commit_link("side-by-side diff", NULL, NULL, ctx.qry.head, tmp, 1); 68 cgit_commit_link("side-by-side diff", NULL, NULL, ctx.qry.head, tmp, prefix, 1);
69 html(")</td></tr>\n"); 69 html(")</td></tr>\n");
70 html("<tr><th>tree</th><td colspan='2' class='sha1'>"); 70 html("<tr><th>tree</th><td colspan='2' class='sha1'>");
71 tmp = xstrdup(hex); 71 tmp = xstrdup(hex);
72 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, 72 cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
73 ctx.qry.head, tmp, NULL); 73 ctx.qry.head, tmp, NULL);
74 if (prefix) { 74 if (prefix) {
75 html(" /"); 75 html(" /");
76 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix); 76 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
77 } 77 }
78 html("</td></tr>\n"); 78 html("</td></tr>\n");
79 for (p = commit->parents; p ; p = p->next) { 79 for (p = commit->parents; p ; p = p->next) {
80 parent = lookup_commit_reference(p->item->object.sha1); 80 parent = lookup_commit_reference(p->item->object.sha1);
81 if (!parent) { 81 if (!parent) {
82 html("<tr><td colspan='3'>"); 82 html("<tr><td colspan='3'>");
83 cgit_print_error("Error reading parent commit"); 83 cgit_print_error("Error reading parent commit");
84 html("</td></tr>"); 84 html("</td></tr>");
85 continue; 85 continue;
86 } 86 }
87 html("<tr><th>parent</th>" 87 html("<tr><th>parent</th>"
88 "<td colspan='2' class='sha1'>"); 88 "<td colspan='2' class='sha1'>");
89 cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, 89 cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL,
90 ctx.qry.head, sha1_to_hex(p->item->object.sha1), 0); 90 ctx.qry.head,
91 sha1_to_hex(p->item->object.sha1), prefix, 0);
91 html(" ("); 92 html(" (");
92 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, 93 cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
93 sha1_to_hex(p->item->object.sha1), prefix, 0); 94 sha1_to_hex(p->item->object.sha1), prefix, 0);
94 html(")</td></tr>"); 95 html(")</td></tr>");
95 parents++; 96 parents++;
96 } 97 }
97 if (ctx.repo->snapshots) { 98 if (ctx.repo->snapshots) {
98 html("<tr><th>download</th><td colspan='2' class='sha1'>"); 99 html("<tr><th>download</th><td colspan='2' class='sha1'>");
99 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, 100 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
100 hex, ctx.repo->snapshots); 101 hex, ctx.repo->snapshots);
101 html("</td></tr>"); 102 html("</td></tr>");
102 } 103 }
diff --git a/ui-log.c b/ui-log.c
index 0947604..282eca3 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -57,48 +57,48 @@ void show_commit_decorations(struct commit *commit)
57 strncpy(buf, deco->name + 10, sizeof(buf) - 1); 57 strncpy(buf, deco->name + 10, sizeof(buf) - 1);
58 cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); 58 cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
59 } 59 }
60 else if (!prefixcmp(deco->name, "refs/remotes/")) { 60 else if (!prefixcmp(deco->name, "refs/remotes/")) {
61 strncpy(buf, deco->name + 13, sizeof(buf) - 1); 61 strncpy(buf, deco->name + 13, sizeof(buf) - 1);
62 cgit_log_link(buf, NULL, "remote-deco", NULL, 62 cgit_log_link(buf, NULL, "remote-deco", NULL,
63 sha1_to_hex(commit->object.sha1), NULL, 63 sha1_to_hex(commit->object.sha1), NULL,
64 0, NULL, NULL, ctx.qry.showmsg); 64 0, NULL, NULL, ctx.qry.showmsg);
65 } 65 }
66 else { 66 else {
67 strncpy(buf, deco->name, sizeof(buf) - 1); 67 strncpy(buf, deco->name, sizeof(buf) - 1);
68 cgit_commit_link(buf, NULL, "deco", ctx.qry.head, 68 cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
69 sha1_to_hex(commit->object.sha1), 0); 69 sha1_to_hex(commit->object.sha1), NULL, 0);
70 } 70 }
71 deco = deco->next; 71 deco = deco->next;
72 } 72 }
73} 73}
74 74
75void print_commit(struct commit *commit) 75void print_commit(struct commit *commit)
76{ 76{
77 struct commitinfo *info; 77 struct commitinfo *info;
78 char *tmp; 78 char *tmp;
79 int cols = 2; 79 int cols = 2;
80 80
81 info = cgit_parse_commit(commit); 81 info = cgit_parse_commit(commit);
82 htmlf("<tr%s><td>", 82 htmlf("<tr%s><td>",
83 ctx.qry.showmsg ? " class='logheader'" : ""); 83 ctx.qry.showmsg ? " class='logheader'" : "");
84 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); 84 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
85 tmp = cgit_pageurl(ctx.repo->url, "commit", tmp); 85 tmp = cgit_pageurl(ctx.repo->url, "commit", tmp);
86 html_link_open(tmp, NULL, NULL); 86 html_link_open(tmp, NULL, NULL);
87 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); 87 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
88 html_link_close(); 88 html_link_close();
89 htmlf("</td><td%s>", 89 htmlf("</td><td%s>",
90 ctx.qry.showmsg ? " class='logsubject'" : ""); 90 ctx.qry.showmsg ? " class='logsubject'" : "");
91 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, 91 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
92 sha1_to_hex(commit->object.sha1), 0); 92 sha1_to_hex(commit->object.sha1), NULL, 0);
93 show_commit_decorations(commit); 93 show_commit_decorations(commit);
94 html("</td><td>"); 94 html("</td><td>");
95 html_txt(info->author); 95 html_txt(info->author);
96 if (ctx.repo->enable_log_filecount) { 96 if (ctx.repo->enable_log_filecount) {
97 files = 0; 97 files = 0;
98 add_lines = 0; 98 add_lines = 0;
99 rem_lines = 0; 99 rem_lines = 0;
100 cgit_diff_commit(commit, inspect_files); 100 cgit_diff_commit(commit, inspect_files);
101 html("</td><td>"); 101 html("</td><td>");
102 htmlf("%d", files); 102 htmlf("%d", files);
103 if (ctx.repo->enable_log_linecount) { 103 if (ctx.repo->enable_log_linecount) {
104 html("</td><td>"); 104 html("</td><td>");
diff --git a/ui-refs.c b/ui-refs.c
index 98738db..94ff6be 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -65,25 +65,25 @@ static int print_branch(struct refinfo *ref)
65{ 65{
66 struct commitinfo *info = ref->commit; 66 struct commitinfo *info = ref->commit;
67 char *name = (char *)ref->refname; 67 char *name = (char *)ref->refname;
68 68
69 if (!info) 69 if (!info)
70 return 1; 70 return 1;
71 html("<tr><td>"); 71 html("<tr><td>");
72 cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL, 72 cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL,
73 ctx.qry.showmsg); 73 ctx.qry.showmsg);
74 html("</td><td>"); 74 html("</td><td>");
75 75
76 if (ref->object->type == OBJ_COMMIT) { 76 if (ref->object->type == OBJ_COMMIT) {
77 cgit_commit_link(info->subject, NULL, NULL, name, NULL, 0); 77 cgit_commit_link(info->subject, NULL, NULL, name, NULL, NULL, 0);
78 html("</td><td>"); 78 html("</td><td>");
79 html_txt(info->author); 79 html_txt(info->author);
80 html("</td><td colspan='2'>"); 80 html("</td><td colspan='2'>");
81 cgit_print_age(info->commit->date, -1, NULL); 81 cgit_print_age(info->commit->date, -1, NULL);
82 } else { 82 } else {
83 html("</td><td></td><td>"); 83 html("</td><td></td><td>");
84 cgit_object_link(ref->object); 84 cgit_object_link(ref->object);
85 } 85 }
86 html("</td></tr>\n"); 86 html("</td></tr>\n");
87 return 0; 87 return 0;
88} 88}
89 89
diff --git a/ui-shared.c b/ui-shared.c
index d5c4c10..372b9e7 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -310,36 +310,37 @@ void cgit_log_link(const char *name, const char *title, const char *class,
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);
@@ -457,25 +458,25 @@ void cgit_self_link(char *name, const char *title, const char *class,
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)
@@ -784,25 +785,25 @@ void cgit_print_pageheader(struct cgit_context *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)
diff --git a/ui-shared.h b/ui-shared.h
index c0e5c55..3cc1258 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -20,25 +20,26 @@ extern void cgit_tag_link(const char *name, const char *title,
20extern void cgit_tree_link(const char *name, const char *title, 20extern void cgit_tree_link(const char *name, const char *title,
21 const char *class, const char *head, 21 const char *class, const char *head,
22 const char *rev, const char *path); 22 const char *rev, const char *path);
23extern void cgit_plain_link(const char *name, const char *title, 23extern void cgit_plain_link(const char *name, const char *title,
24 const char *class, const char *head, 24 const char *class, const char *head,
25 const char *rev, const char *path); 25 const char *rev, const char *path);
26extern void cgit_log_link(const char *name, const char *title, 26extern void cgit_log_link(const char *name, const char *title,
27 const char *class, const char *head, const char *rev, 27 const char *class, const char *head, const char *rev,
28 const char *path, int ofs, const char *grep, 28 const char *path, int ofs, const char *grep,
29 const char *pattern, int showmsg); 29 const char *pattern, int showmsg);
30extern void cgit_commit_link(char *name, const char *title, 30extern void cgit_commit_link(char *name, const char *title,
31 const char *class, const char *head, 31 const char *class, const char *head,
32 const char *rev, int toggle_ssdiff); 32 const char *rev, const char *path,
33 int toggle_ssdiff);
33extern void cgit_patch_link(const char *name, const char *title, 34extern void cgit_patch_link(const char *name, const char *title,
34 const char *class, const char *head, 35 const char *class, const char *head,
35 const char *rev, const char *path); 36 const char *rev, const char *path);
36extern void cgit_refs_link(const char *name, const char *title, 37extern void cgit_refs_link(const char *name, const char *title,
37 const char *class, const char *head, 38 const char *class, const char *head,
38 const char *rev, const char *path); 39 const char *rev, const char *path);
39extern void cgit_snapshot_link(const char *name, const char *title, 40extern void cgit_snapshot_link(const char *name, const char *title,
40 const char *class, const char *head, 41 const char *class, const char *head,
41 const char *rev, const char *archivename); 42 const char *rev, const char *archivename);
42extern void cgit_diff_link(const char *name, const char *title, 43extern void cgit_diff_link(const char *name, const char *title,
43 const char *class, const char *head, 44 const char *class, const char *head,
44 const char *new_rev, const char *old_rev, 45 const char *new_rev, const char *old_rev,