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
@@ -29,94 +29,95 @@ void cgit_print_commit(char *hex, const char *prefix)
29 return; 29 return;
30 } 30 }
31 commit = lookup_commit_reference(sha1); 31 commit = lookup_commit_reference(sha1);
32 if (!commit) { 32 if (!commit) {
33 cgit_print_error(fmt("Bad commit reference: %s", hex)); 33 cgit_print_error(fmt("Bad commit reference: %s", hex));
34 return; 34 return;
35 } 35 }
36 info = cgit_parse_commit(commit); 36 info = cgit_parse_commit(commit);
37 37
38 load_ref_decorations(DECORATE_FULL_REFS); 38 load_ref_decorations(DECORATE_FULL_REFS);
39 39
40 html("<table summary='commit info' class='commit-info'>\n"); 40 html("<table summary='commit info' class='commit-info'>\n");
41 html("<tr><th>author</th><td>"); 41 html("<tr><th>author</th><td>");
42 html_txt(info->author); 42 html_txt(info->author);
43 if (!ctx.cfg.noplainemail) { 43 if (!ctx.cfg.noplainemail) {
44 html(" "); 44 html(" ");
45 html_txt(info->author_email); 45 html_txt(info->author_email);
46 } 46 }
47 html("</td><td class='right'>"); 47 html("</td><td class='right'>");
48 cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time); 48 cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
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 }
103 html("</table>\n"); 104 html("</table>\n");
104 html("<div class='commit-subject'>"); 105 html("<div class='commit-subject'>");
105 if (ctx.repo->commit_filter) 106 if (ctx.repo->commit_filter)
106 cgit_open_filter(ctx.repo->commit_filter); 107 cgit_open_filter(ctx.repo->commit_filter);
107 html_txt(info->subject); 108 html_txt(info->subject);
108 if (ctx.repo->commit_filter) 109 if (ctx.repo->commit_filter)
109 cgit_close_filter(ctx.repo->commit_filter); 110 cgit_close_filter(ctx.repo->commit_filter);
110 show_commit_decorations(commit); 111 show_commit_decorations(commit);
111 html("</div>"); 112 html("</div>");
112 html("<div class='commit-msg'>"); 113 html("<div class='commit-msg'>");
113 if (ctx.repo->commit_filter) 114 if (ctx.repo->commit_filter)
114 cgit_open_filter(ctx.repo->commit_filter); 115 cgit_open_filter(ctx.repo->commit_filter);
115 html_txt(info->msg); 116 html_txt(info->msg);
116 if (ctx.repo->commit_filter) 117 if (ctx.repo->commit_filter)
117 cgit_close_filter(ctx.repo->commit_filter); 118 cgit_close_filter(ctx.repo->commit_filter);
118 html("</div>"); 119 html("</div>");
119 if (parents < 3) { 120 if (parents < 3) {
120 if (parents) 121 if (parents)
121 tmp = sha1_to_hex(commit->parents->item->object.sha1); 122 tmp = sha1_to_hex(commit->parents->item->object.sha1);
122 else 123 else
diff --git a/ui-log.c b/ui-log.c
index 0947604..282eca3 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -37,88 +37,88 @@ void inspect_files(struct diff_filepair *pair)
37} 37}
38 38
39void show_commit_decorations(struct commit *commit) 39void show_commit_decorations(struct commit *commit)
40{ 40{
41 struct name_decoration *deco; 41 struct name_decoration *deco;
42 static char buf[1024]; 42 static char buf[1024];
43 43
44 buf[sizeof(buf) - 1] = 0; 44 buf[sizeof(buf) - 1] = 0;
45 deco = lookup_decoration(&name_decoration, &commit->object); 45 deco = lookup_decoration(&name_decoration, &commit->object);
46 while (deco) { 46 while (deco) {
47 if (!prefixcmp(deco->name, "refs/heads/")) { 47 if (!prefixcmp(deco->name, "refs/heads/")) {
48 strncpy(buf, deco->name + 11, sizeof(buf) - 1); 48 strncpy(buf, deco->name + 11, sizeof(buf) - 1);
49 cgit_log_link(buf, NULL, "branch-deco", buf, NULL, NULL, 49 cgit_log_link(buf, NULL, "branch-deco", buf, NULL, NULL,
50 0, NULL, NULL, ctx.qry.showmsg); 50 0, NULL, NULL, ctx.qry.showmsg);
51 } 51 }
52 else if (!prefixcmp(deco->name, "tag: refs/tags/")) { 52 else if (!prefixcmp(deco->name, "tag: refs/tags/")) {
53 strncpy(buf, deco->name + 15, sizeof(buf) - 1); 53 strncpy(buf, deco->name + 15, sizeof(buf) - 1);
54 cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); 54 cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
55 } 55 }
56 else if (!prefixcmp(deco->name, "refs/tags/")) { 56 else if (!prefixcmp(deco->name, "refs/tags/")) {
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>");
105 htmlf("-%d/+%d", rem_lines, add_lines); 105 htmlf("-%d/+%d", rem_lines, add_lines);
106 } 106 }
107 } 107 }
108 html("</td></tr>\n"); 108 html("</td></tr>\n");
109 if (ctx.qry.showmsg) { 109 if (ctx.qry.showmsg) {
110 if (ctx.repo->enable_log_filecount) { 110 if (ctx.repo->enable_log_filecount) {
111 cols++; 111 cols++;
112 if (ctx.repo->enable_log_linecount) 112 if (ctx.repo->enable_log_linecount)
113 cols++; 113 cols++;
114 } 114 }
115 htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>", 115 htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>",
116 cols); 116 cols);
117 html_txt(info->msg); 117 html_txt(info->msg);
118 html("</td></tr>\n"); 118 html("</td></tr>\n");
119 } 119 }
120 cgit_free_commitinfo(info); 120 cgit_free_commitinfo(info);
121} 121}
122 122
123static const char *disambiguate_ref(const char *ref) 123static const char *disambiguate_ref(const char *ref)
124{ 124{
diff --git a/ui-refs.c b/ui-refs.c
index 98738db..94ff6be 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -45,65 +45,65 @@ static int cmp_branch_age(const void *a, const void *b)
45static int cmp_tag_age(const void *a, const void *b) 45static int cmp_tag_age(const void *a, const void *b)
46{ 46{
47 struct refinfo *r1 = *(struct refinfo **)a; 47 struct refinfo *r1 = *(struct refinfo **)a;
48 struct refinfo *r2 = *(struct refinfo **)b; 48 struct refinfo *r2 = *(struct refinfo **)b;
49 int r1date, r2date; 49 int r1date, r2date;
50 50
51 if (r1->object->type != OBJ_COMMIT) 51 if (r1->object->type != OBJ_COMMIT)
52 r1date = r1->tag->tagger_date; 52 r1date = r1->tag->tagger_date;
53 else 53 else
54 r1date = r1->commit->committer_date; 54 r1date = r1->commit->committer_date;
55 55
56 if (r2->object->type != OBJ_COMMIT) 56 if (r2->object->type != OBJ_COMMIT)
57 r2date = r2->tag->tagger_date; 57 r2date = r2->tag->tagger_date;
58 else 58 else
59 r2date = r2->commit->committer_date; 59 r2date = r2->commit->committer_date;
60 60
61 return cmp_age(r1date, r2date); 61 return cmp_age(r1date, r2date);
62} 62}
63 63
64static int print_branch(struct refinfo *ref) 64static 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
90static void print_tag_header() 90static void print_tag_header()
91{ 91{
92 html("<tr class='nohover'><th class='left'>Tag</th>" 92 html("<tr class='nohover'><th class='left'>Tag</th>"
93 "<th class='left'>Download</th>" 93 "<th class='left'>Download</th>"
94 "<th class='left'>Author</th>" 94 "<th class='left'>Author</th>"
95 "<th class='left' colspan='2'>Age</th></tr>\n"); 95 "<th class='left' colspan='2'>Age</th></tr>\n");
96 header = 1; 96 header = 1;
97} 97}
98 98
99static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) 99static void print_tag_downloads(const struct cgit_repo *repo, const char *ref)
100{ 100{
101 const struct cgit_snapshot_format* f; 101 const struct cgit_snapshot_format* f;
102 char *filename; 102 char *filename;
103 const char *basename; 103 const char *basename;
104 104
105 if (!ref || strlen(ref) < 2) 105 if (!ref || strlen(ref) < 2)
106 return; 106 return;
107 107
108 basename = cgit_repobasename(repo->url); 108 basename = cgit_repobasename(repo->url);
109 if (prefixcmp(ref, basename) != 0) { 109 if (prefixcmp(ref, basename) != 0) {
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'>");
diff --git a/ui-shared.h b/ui-shared.h
index c0e5c55..3cc1258 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -1,64 +1,65 @@
1#ifndef UI_SHARED_H 1#ifndef UI_SHARED_H
2#define UI_SHARED_H 2#define UI_SHARED_H
3 3
4extern char *cgit_httpscheme(); 4extern char *cgit_httpscheme();
5extern char *cgit_hosturl(); 5extern char *cgit_hosturl();
6extern char *cgit_rooturl(); 6extern char *cgit_rooturl();
7extern char *cgit_repourl(const char *reponame); 7extern char *cgit_repourl(const char *reponame);
8extern char *cgit_fileurl(const char *reponame, const char *pagename, 8extern char *cgit_fileurl(const char *reponame, const char *pagename,
9 const char *filename, const char *query); 9 const char *filename, const char *query);
10extern char *cgit_pageurl(const char *reponame, const char *pagename, 10extern char *cgit_pageurl(const char *reponame, const char *pagename,
11 const char *query); 11 const char *query);
12 12
13extern void cgit_index_link(const char *name, const char *title, 13extern void cgit_index_link(const char *name, const char *title,
14 const char *class, const char *pattern, int ofs); 14 const char *class, const char *pattern, int ofs);
15extern void cgit_summary_link(const char *name, const char *title, 15extern void cgit_summary_link(const char *name, const char *title,
16 const char *class, const char *head); 16 const char *class, const char *head);
17extern void cgit_tag_link(const char *name, const char *title, 17extern void cgit_tag_link(const char *name, const char *title,
18 const char *class, const char *head, 18 const char *class, const char *head,
19 const char *rev); 19 const char *rev);
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,
45 const char *path, int toggle_ssdiff); 46 const char *path, int toggle_ssdiff);
46extern void cgit_stats_link(const char *name, const char *title, 47extern void cgit_stats_link(const char *name, const char *title,
47 const char *class, const char *head, 48 const char *class, const char *head,
48 const char *path); 49 const char *path);
49extern void cgit_self_link(char *name, const char *title, 50extern void cgit_self_link(char *name, const char *title,
50 const char *class, struct cgit_context *ctx); 51 const char *class, struct cgit_context *ctx);
51extern void cgit_object_link(struct object *obj); 52extern void cgit_object_link(struct object *obj);
52 53
53extern void cgit_print_error(const char *msg); 54extern void cgit_print_error(const char *msg);
54extern void cgit_print_date(time_t secs, const char *format, int local_time); 55extern void cgit_print_date(time_t secs, const char *format, int local_time);
55extern void cgit_print_age(time_t t, time_t max_relative, const char *format); 56extern void cgit_print_age(time_t t, time_t max_relative, const char *format);
56extern void cgit_print_http_headers(struct cgit_context *ctx); 57extern void cgit_print_http_headers(struct cgit_context *ctx);
57extern void cgit_print_docstart(struct cgit_context *ctx); 58extern void cgit_print_docstart(struct cgit_context *ctx);
58extern void cgit_print_docend(); 59extern void cgit_print_docend();
59extern void cgit_print_pageheader(struct cgit_context *ctx); 60extern void cgit_print_pageheader(struct cgit_context *ctx);
60extern void cgit_print_filemode(unsigned short mode); 61extern void cgit_print_filemode(unsigned short mode);
61extern void cgit_print_snapshot_links(const char *repo, const char *head, 62extern void cgit_print_snapshot_links(const char *repo, const char *head,
62 const char *hex, int snapshots); 63 const char *hex, int snapshots);
63extern void cgit_add_hidden_formfields(int incl_head, int incl_search, 64extern void cgit_add_hidden_formfields(int incl_head, int incl_search,
64 const char *page); 65 const char *page);