author | Johan Herland <johan@herland.net> | 2010-06-10 18:15:51 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2010-06-19 11:00:07 (UTC) |
commit | d20313e3daf855ee5d4808e050f54614c200d7b1 (patch) (unidiff) | |
tree | 5c462f3ba6ec97c0b099a309dfd0fa87d03fbc72 | |
parent | 6180e6169d6e87a3bea7e4da835dca17f93e5cfd (diff) | |
download | cgit-d20313e3daf855ee5d4808e050f54614c200d7b1.zip cgit-d20313e3daf855ee5d4808e050f54614c200d7b1.tar.gz cgit-d20313e3daf855ee5d4808e050f54614c200d7b1.tar.bz2 |
ui-diff: Add links to increase/decrease number of context lines in diffs
Add two links to the "Diffstat" line to show more/less context lines in the
generated diff.
To support this, cgit_commit_link() and cgit_diff_link() has learned to
preserve the ctx.qry.context variable.
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-diff.c | 10 | ||||
-rw-r--r-- | ui-shared.c | 14 |
2 files changed, 23 insertions, 1 deletions
@@ -1,355 +1,363 @@ | |||
1 | /* ui-diff.c: show diff between two blobs | 1 | /* ui-diff.c: show diff between two blobs |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | #include "ui-ssdiff.h" | 12 | #include "ui-ssdiff.h" |
13 | 13 | ||
14 | unsigned char old_rev_sha1[20]; | 14 | unsigned char old_rev_sha1[20]; |
15 | unsigned char new_rev_sha1[20]; | 15 | unsigned char new_rev_sha1[20]; |
16 | 16 | ||
17 | static int files, slots; | 17 | static int files, slots; |
18 | static int total_adds, total_rems, max_changes; | 18 | static int total_adds, total_rems, max_changes; |
19 | static int lines_added, lines_removed; | 19 | static int lines_added, lines_removed; |
20 | 20 | ||
21 | static struct fileinfo { | 21 | static struct fileinfo { |
22 | char status; | 22 | char status; |
23 | unsigned char old_sha1[20]; | 23 | unsigned char old_sha1[20]; |
24 | unsigned char new_sha1[20]; | 24 | unsigned char new_sha1[20]; |
25 | unsigned short old_mode; | 25 | unsigned short old_mode; |
26 | unsigned short new_mode; | 26 | unsigned short new_mode; |
27 | char *old_path; | 27 | char *old_path; |
28 | char *new_path; | 28 | char *new_path; |
29 | unsigned int added; | 29 | unsigned int added; |
30 | unsigned int removed; | 30 | unsigned int removed; |
31 | unsigned long old_size; | 31 | unsigned long old_size; |
32 | unsigned long new_size; | 32 | unsigned long new_size; |
33 | int binary:1; | 33 | int binary:1; |
34 | } *items; | 34 | } *items; |
35 | 35 | ||
36 | static int use_ssdiff = 0; | 36 | static int use_ssdiff = 0; |
37 | 37 | ||
38 | static void print_fileinfo(struct fileinfo *info) | 38 | static void print_fileinfo(struct fileinfo *info) |
39 | { | 39 | { |
40 | char *class; | 40 | char *class; |
41 | 41 | ||
42 | switch (info->status) { | 42 | switch (info->status) { |
43 | case DIFF_STATUS_ADDED: | 43 | case DIFF_STATUS_ADDED: |
44 | class = "add"; | 44 | class = "add"; |
45 | break; | 45 | break; |
46 | case DIFF_STATUS_COPIED: | 46 | case DIFF_STATUS_COPIED: |
47 | class = "cpy"; | 47 | class = "cpy"; |
48 | break; | 48 | break; |
49 | case DIFF_STATUS_DELETED: | 49 | case DIFF_STATUS_DELETED: |
50 | class = "del"; | 50 | class = "del"; |
51 | break; | 51 | break; |
52 | case DIFF_STATUS_MODIFIED: | 52 | case DIFF_STATUS_MODIFIED: |
53 | class = "upd"; | 53 | class = "upd"; |
54 | break; | 54 | break; |
55 | case DIFF_STATUS_RENAMED: | 55 | case DIFF_STATUS_RENAMED: |
56 | class = "mov"; | 56 | class = "mov"; |
57 | break; | 57 | break; |
58 | case DIFF_STATUS_TYPE_CHANGED: | 58 | case DIFF_STATUS_TYPE_CHANGED: |
59 | class = "typ"; | 59 | class = "typ"; |
60 | break; | 60 | break; |
61 | case DIFF_STATUS_UNKNOWN: | 61 | case DIFF_STATUS_UNKNOWN: |
62 | class = "unk"; | 62 | class = "unk"; |
63 | break; | 63 | break; |
64 | case DIFF_STATUS_UNMERGED: | 64 | case DIFF_STATUS_UNMERGED: |
65 | class = "stg"; | 65 | class = "stg"; |
66 | break; | 66 | break; |
67 | default: | 67 | default: |
68 | die("bug: unhandled diff status %c", info->status); | 68 | die("bug: unhandled diff status %c", info->status); |
69 | } | 69 | } |
70 | 70 | ||
71 | html("<tr>"); | 71 | html("<tr>"); |
72 | htmlf("<td class='mode'>"); | 72 | htmlf("<td class='mode'>"); |
73 | if (is_null_sha1(info->new_sha1)) { | 73 | if (is_null_sha1(info->new_sha1)) { |
74 | cgit_print_filemode(info->old_mode); | 74 | cgit_print_filemode(info->old_mode); |
75 | } else { | 75 | } else { |
76 | cgit_print_filemode(info->new_mode); | 76 | cgit_print_filemode(info->new_mode); |
77 | } | 77 | } |
78 | 78 | ||
79 | if (info->old_mode != info->new_mode && | 79 | if (info->old_mode != info->new_mode && |
80 | !is_null_sha1(info->old_sha1) && | 80 | !is_null_sha1(info->old_sha1) && |
81 | !is_null_sha1(info->new_sha1)) { | 81 | !is_null_sha1(info->new_sha1)) { |
82 | html("<span class='modechange'>["); | 82 | html("<span class='modechange'>["); |
83 | cgit_print_filemode(info->old_mode); | 83 | cgit_print_filemode(info->old_mode); |
84 | html("]</span>"); | 84 | html("]</span>"); |
85 | } | 85 | } |
86 | htmlf("</td><td class='%s'>", class); | 86 | htmlf("</td><td class='%s'>", class); |
87 | cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, | 87 | cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, |
88 | ctx.qry.sha2, info->new_path, 0); | 88 | ctx.qry.sha2, info->new_path, 0); |
89 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) | 89 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) |
90 | htmlf(" (%s from %s)", | 90 | htmlf(" (%s from %s)", |
91 | info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", | 91 | info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", |
92 | info->old_path); | 92 | info->old_path); |
93 | html("</td><td class='right'>"); | 93 | html("</td><td class='right'>"); |
94 | if (info->binary) { | 94 | if (info->binary) { |
95 | htmlf("bin</td><td class='graph'>%d -> %d bytes", | 95 | htmlf("bin</td><td class='graph'>%d -> %d bytes", |
96 | info->old_size, info->new_size); | 96 | info->old_size, info->new_size); |
97 | return; | 97 | return; |
98 | } | 98 | } |
99 | htmlf("%d", info->added + info->removed); | 99 | htmlf("%d", info->added + info->removed); |
100 | html("</td><td class='graph'>"); | 100 | html("</td><td class='graph'>"); |
101 | htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); | 101 | htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); |
102 | htmlf("<td class='add' style='width: %.1f%%;'/>", | 102 | htmlf("<td class='add' style='width: %.1f%%;'/>", |
103 | info->added * 100.0 / max_changes); | 103 | info->added * 100.0 / max_changes); |
104 | htmlf("<td class='rem' style='width: %.1f%%;'/>", | 104 | htmlf("<td class='rem' style='width: %.1f%%;'/>", |
105 | info->removed * 100.0 / max_changes); | 105 | info->removed * 100.0 / max_changes); |
106 | htmlf("<td class='none' style='width: %.1f%%;'/>", | 106 | htmlf("<td class='none' style='width: %.1f%%;'/>", |
107 | (max_changes - info->removed - info->added) * 100.0 / max_changes); | 107 | (max_changes - info->removed - info->added) * 100.0 / max_changes); |
108 | html("</tr></table></td></tr>\n"); | 108 | html("</tr></table></td></tr>\n"); |
109 | } | 109 | } |
110 | 110 | ||
111 | static void count_diff_lines(char *line, int len) | 111 | static void count_diff_lines(char *line, int len) |
112 | { | 112 | { |
113 | if (line && (len > 0)) { | 113 | if (line && (len > 0)) { |
114 | if (line[0] == '+') | 114 | if (line[0] == '+') |
115 | lines_added++; | 115 | lines_added++; |
116 | else if (line[0] == '-') | 116 | else if (line[0] == '-') |
117 | lines_removed++; | 117 | lines_removed++; |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | static void inspect_filepair(struct diff_filepair *pair) | 121 | static void inspect_filepair(struct diff_filepair *pair) |
122 | { | 122 | { |
123 | int binary = 0; | 123 | int binary = 0; |
124 | unsigned long old_size = 0; | 124 | unsigned long old_size = 0; |
125 | unsigned long new_size = 0; | 125 | unsigned long new_size = 0; |
126 | files++; | 126 | files++; |
127 | lines_added = 0; | 127 | lines_added = 0; |
128 | lines_removed = 0; | 128 | lines_removed = 0; |
129 | cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size, | 129 | cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size, |
130 | &binary, 0, count_diff_lines); | 130 | &binary, 0, count_diff_lines); |
131 | if (files >= slots) { | 131 | if (files >= slots) { |
132 | if (slots == 0) | 132 | if (slots == 0) |
133 | slots = 4; | 133 | slots = 4; |
134 | else | 134 | else |
135 | slots = slots * 2; | 135 | slots = slots * 2; |
136 | items = xrealloc(items, slots * sizeof(struct fileinfo)); | 136 | items = xrealloc(items, slots * sizeof(struct fileinfo)); |
137 | } | 137 | } |
138 | items[files-1].status = pair->status; | 138 | items[files-1].status = pair->status; |
139 | hashcpy(items[files-1].old_sha1, pair->one->sha1); | 139 | hashcpy(items[files-1].old_sha1, pair->one->sha1); |
140 | hashcpy(items[files-1].new_sha1, pair->two->sha1); | 140 | hashcpy(items[files-1].new_sha1, pair->two->sha1); |
141 | items[files-1].old_mode = pair->one->mode; | 141 | items[files-1].old_mode = pair->one->mode; |
142 | items[files-1].new_mode = pair->two->mode; | 142 | items[files-1].new_mode = pair->two->mode; |
143 | items[files-1].old_path = xstrdup(pair->one->path); | 143 | items[files-1].old_path = xstrdup(pair->one->path); |
144 | items[files-1].new_path = xstrdup(pair->two->path); | 144 | items[files-1].new_path = xstrdup(pair->two->path); |
145 | items[files-1].added = lines_added; | 145 | items[files-1].added = lines_added; |
146 | items[files-1].removed = lines_removed; | 146 | items[files-1].removed = lines_removed; |
147 | items[files-1].old_size = old_size; | 147 | items[files-1].old_size = old_size; |
148 | items[files-1].new_size = new_size; | 148 | items[files-1].new_size = new_size; |
149 | items[files-1].binary = binary; | 149 | items[files-1].binary = binary; |
150 | if (lines_added + lines_removed > max_changes) | 150 | if (lines_added + lines_removed > max_changes) |
151 | max_changes = lines_added + lines_removed; | 151 | max_changes = lines_added + lines_removed; |
152 | total_adds += lines_added; | 152 | total_adds += lines_added; |
153 | total_rems += lines_removed; | 153 | total_rems += lines_removed; |
154 | } | 154 | } |
155 | 155 | ||
156 | void cgit_print_diffstat(const unsigned char *old_sha1, | 156 | void cgit_print_diffstat(const unsigned char *old_sha1, |
157 | const unsigned char *new_sha1, const char *prefix) | 157 | const unsigned char *new_sha1, const char *prefix) |
158 | { | 158 | { |
159 | int i; | 159 | int i, save_context = ctx.qry.context; |
160 | 160 | ||
161 | html("<div class='diffstat-header'>"); | 161 | html("<div class='diffstat-header'>"); |
162 | cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1, | 162 | cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1, |
163 | ctx.qry.sha2, NULL, 0); | 163 | ctx.qry.sha2, NULL, 0); |
164 | if (prefix) | 164 | if (prefix) |
165 | htmlf(" (limited to '%s')", prefix); | 165 | htmlf(" (limited to '%s')", prefix); |
166 | html(" ("); | ||
167 | ctx.qry.context = (save_context > 0 ? save_context : 3) << 1; | ||
168 | cgit_self_link("more", NULL, NULL, &ctx); | ||
169 | html("/"); | ||
170 | ctx.qry.context = (save_context > 3 ? save_context : 3) >> 1; | ||
171 | cgit_self_link("less", NULL, NULL, &ctx); | ||
172 | ctx.qry.context = save_context; | ||
173 | html(" context)"); | ||
166 | html("</div>"); | 174 | html("</div>"); |
167 | html("<table summary='diffstat' class='diffstat'>"); | 175 | html("<table summary='diffstat' class='diffstat'>"); |
168 | max_changes = 0; | 176 | max_changes = 0; |
169 | cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix); | 177 | cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix); |
170 | for(i = 0; i<files; i++) | 178 | for(i = 0; i<files; i++) |
171 | print_fileinfo(&items[i]); | 179 | print_fileinfo(&items[i]); |
172 | html("</table>"); | 180 | html("</table>"); |
173 | html("<div class='diffstat-summary'>"); | 181 | html("<div class='diffstat-summary'>"); |
174 | htmlf("%d files changed, %d insertions, %d deletions", | 182 | htmlf("%d files changed, %d insertions, %d deletions", |
175 | files, total_adds, total_rems); | 183 | files, total_adds, total_rems); |
176 | html("</div>"); | 184 | html("</div>"); |
177 | } | 185 | } |
178 | 186 | ||
179 | 187 | ||
180 | /* | 188 | /* |
181 | * print a single line returned from xdiff | 189 | * print a single line returned from xdiff |
182 | */ | 190 | */ |
183 | static void print_line(char *line, int len) | 191 | static void print_line(char *line, int len) |
184 | { | 192 | { |
185 | char *class = "ctx"; | 193 | char *class = "ctx"; |
186 | char c = line[len-1]; | 194 | char c = line[len-1]; |
187 | 195 | ||
188 | if (line[0] == '+') | 196 | if (line[0] == '+') |
189 | class = "add"; | 197 | class = "add"; |
190 | else if (line[0] == '-') | 198 | else if (line[0] == '-') |
191 | class = "del"; | 199 | class = "del"; |
192 | else if (line[0] == '@') | 200 | else if (line[0] == '@') |
193 | class = "hunk"; | 201 | class = "hunk"; |
194 | 202 | ||
195 | htmlf("<div class='%s'>", class); | 203 | htmlf("<div class='%s'>", class); |
196 | line[len-1] = '\0'; | 204 | line[len-1] = '\0'; |
197 | html_txt(line); | 205 | html_txt(line); |
198 | html("</div>"); | 206 | html("</div>"); |
199 | line[len-1] = c; | 207 | line[len-1] = c; |
200 | } | 208 | } |
201 | 209 | ||
202 | static void header(unsigned char *sha1, char *path1, int mode1, | 210 | static void header(unsigned char *sha1, char *path1, int mode1, |
203 | unsigned char *sha2, char *path2, int mode2) | 211 | unsigned char *sha2, char *path2, int mode2) |
204 | { | 212 | { |
205 | char *abbrev1, *abbrev2; | 213 | char *abbrev1, *abbrev2; |
206 | int subproject; | 214 | int subproject; |
207 | 215 | ||
208 | subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); | 216 | subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); |
209 | html("<div class='head'>"); | 217 | html("<div class='head'>"); |
210 | html("diff --git a/"); | 218 | html("diff --git a/"); |
211 | html_txt(path1); | 219 | html_txt(path1); |
212 | html(" b/"); | 220 | html(" b/"); |
213 | html_txt(path2); | 221 | html_txt(path2); |
214 | 222 | ||
215 | if (is_null_sha1(sha1)) | 223 | if (is_null_sha1(sha1)) |
216 | path1 = "dev/null"; | 224 | path1 = "dev/null"; |
217 | if (is_null_sha1(sha2)) | 225 | if (is_null_sha1(sha2)) |
218 | path2 = "dev/null"; | 226 | path2 = "dev/null"; |
219 | 227 | ||
220 | if (mode1 == 0) | 228 | if (mode1 == 0) |
221 | htmlf("<br/>new file mode %.6o", mode2); | 229 | htmlf("<br/>new file mode %.6o", mode2); |
222 | 230 | ||
223 | if (mode2 == 0) | 231 | if (mode2 == 0) |
224 | htmlf("<br/>deleted file mode %.6o", mode1); | 232 | htmlf("<br/>deleted file mode %.6o", mode1); |
225 | 233 | ||
226 | if (!subproject) { | 234 | if (!subproject) { |
227 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); | 235 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); |
228 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); | 236 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); |
229 | htmlf("<br/>index %s..%s", abbrev1, abbrev2); | 237 | htmlf("<br/>index %s..%s", abbrev1, abbrev2); |
230 | free(abbrev1); | 238 | free(abbrev1); |
231 | free(abbrev2); | 239 | free(abbrev2); |
232 | if (mode1 != 0 && mode2 != 0) { | 240 | if (mode1 != 0 && mode2 != 0) { |
233 | htmlf(" %.6o", mode1); | 241 | htmlf(" %.6o", mode1); |
234 | if (mode2 != mode1) | 242 | if (mode2 != mode1) |
235 | htmlf("..%.6o", mode2); | 243 | htmlf("..%.6o", mode2); |
236 | } | 244 | } |
237 | html("<br/>--- a/"); | 245 | html("<br/>--- a/"); |
238 | if (mode1 != 0) | 246 | if (mode1 != 0) |
239 | cgit_tree_link(path1, NULL, NULL, ctx.qry.head, | 247 | cgit_tree_link(path1, NULL, NULL, ctx.qry.head, |
240 | sha1_to_hex(old_rev_sha1), path1); | 248 | sha1_to_hex(old_rev_sha1), path1); |
241 | else | 249 | else |
242 | html_txt(path1); | 250 | html_txt(path1); |
243 | html("<br/>+++ b/"); | 251 | html("<br/>+++ b/"); |
244 | if (mode2 != 0) | 252 | if (mode2 != 0) |
245 | cgit_tree_link(path2, NULL, NULL, ctx.qry.head, | 253 | cgit_tree_link(path2, NULL, NULL, ctx.qry.head, |
246 | sha1_to_hex(new_rev_sha1), path2); | 254 | sha1_to_hex(new_rev_sha1), path2); |
247 | else | 255 | else |
248 | html_txt(path2); | 256 | html_txt(path2); |
249 | } | 257 | } |
250 | html("</div>"); | 258 | html("</div>"); |
251 | } | 259 | } |
252 | 260 | ||
253 | static void print_ssdiff_link() | 261 | static void print_ssdiff_link() |
254 | { | 262 | { |
255 | if (!strcmp(ctx.qry.page, "diff")) { | 263 | if (!strcmp(ctx.qry.page, "diff")) { |
256 | if (use_ssdiff) | 264 | if (use_ssdiff) |
257 | cgit_diff_link("Unidiff", NULL, NULL, ctx.qry.head, | 265 | cgit_diff_link("Unidiff", NULL, NULL, ctx.qry.head, |
258 | ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1); | 266 | ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1); |
259 | else | 267 | else |
260 | cgit_diff_link("Side-by-side diff", NULL, NULL, | 268 | cgit_diff_link("Side-by-side diff", NULL, NULL, |
261 | ctx.qry.head, ctx.qry.sha1, | 269 | ctx.qry.head, ctx.qry.sha1, |
262 | ctx.qry.sha2, ctx.qry.path, 1); | 270 | ctx.qry.sha2, ctx.qry.path, 1); |
263 | } | 271 | } |
264 | } | 272 | } |
265 | 273 | ||
266 | static void filepair_cb(struct diff_filepair *pair) | 274 | static void filepair_cb(struct diff_filepair *pair) |
267 | { | 275 | { |
268 | unsigned long old_size = 0; | 276 | unsigned long old_size = 0; |
269 | unsigned long new_size = 0; | 277 | unsigned long new_size = 0; |
270 | int binary = 0; | 278 | int binary = 0; |
271 | linediff_fn print_line_fn = print_line; | 279 | linediff_fn print_line_fn = print_line; |
272 | 280 | ||
273 | if (use_ssdiff) { | 281 | if (use_ssdiff) { |
274 | cgit_ssdiff_header_begin(); | 282 | cgit_ssdiff_header_begin(); |
275 | print_line_fn = cgit_ssdiff_line_cb; | 283 | print_line_fn = cgit_ssdiff_line_cb; |
276 | } | 284 | } |
277 | header(pair->one->sha1, pair->one->path, pair->one->mode, | 285 | header(pair->one->sha1, pair->one->path, pair->one->mode, |
278 | pair->two->sha1, pair->two->path, pair->two->mode); | 286 | pair->two->sha1, pair->two->path, pair->two->mode); |
279 | if (use_ssdiff) | 287 | if (use_ssdiff) |
280 | cgit_ssdiff_header_end(); | 288 | cgit_ssdiff_header_end(); |
281 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { | 289 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { |
282 | if (S_ISGITLINK(pair->one->mode)) | 290 | if (S_ISGITLINK(pair->one->mode)) |
283 | print_line_fn(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); | 291 | print_line_fn(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); |
284 | if (S_ISGITLINK(pair->two->mode)) | 292 | if (S_ISGITLINK(pair->two->mode)) |
285 | print_line_fn(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); | 293 | print_line_fn(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); |
286 | if (use_ssdiff) | 294 | if (use_ssdiff) |
287 | cgit_ssdiff_footer(); | 295 | cgit_ssdiff_footer(); |
288 | return; | 296 | return; |
289 | } | 297 | } |
290 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, | 298 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, |
291 | &new_size, &binary, ctx.qry.context, print_line_fn)) | 299 | &new_size, &binary, ctx.qry.context, print_line_fn)) |
292 | cgit_print_error("Error running diff"); | 300 | cgit_print_error("Error running diff"); |
293 | if (binary) { | 301 | if (binary) { |
294 | if (use_ssdiff) | 302 | if (use_ssdiff) |
295 | html("<tr><td colspan='4'>Binary files differ</td></tr>"); | 303 | html("<tr><td colspan='4'>Binary files differ</td></tr>"); |
296 | else | 304 | else |
297 | html("Binary files differ"); | 305 | html("Binary files differ"); |
298 | } | 306 | } |
299 | if (use_ssdiff) | 307 | if (use_ssdiff) |
300 | cgit_ssdiff_footer(); | 308 | cgit_ssdiff_footer(); |
301 | } | 309 | } |
302 | 310 | ||
303 | void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) | 311 | void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) |
304 | { | 312 | { |
305 | enum object_type type; | 313 | enum object_type type; |
306 | unsigned long size; | 314 | unsigned long size; |
307 | struct commit *commit, *commit2; | 315 | struct commit *commit, *commit2; |
308 | 316 | ||
309 | if (!new_rev) | 317 | if (!new_rev) |
310 | new_rev = ctx.qry.head; | 318 | new_rev = ctx.qry.head; |
311 | get_sha1(new_rev, new_rev_sha1); | 319 | get_sha1(new_rev, new_rev_sha1); |
312 | type = sha1_object_info(new_rev_sha1, &size); | 320 | type = sha1_object_info(new_rev_sha1, &size); |
313 | if (type == OBJ_BAD) { | 321 | if (type == OBJ_BAD) { |
314 | cgit_print_error(fmt("Bad object name: %s", new_rev)); | 322 | cgit_print_error(fmt("Bad object name: %s", new_rev)); |
315 | return; | 323 | return; |
316 | } | 324 | } |
317 | commit = lookup_commit_reference(new_rev_sha1); | 325 | commit = lookup_commit_reference(new_rev_sha1); |
318 | if (!commit || parse_commit(commit)) | 326 | if (!commit || parse_commit(commit)) |
319 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1))); | 327 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1))); |
320 | 328 | ||
321 | if (old_rev) | 329 | if (old_rev) |
322 | get_sha1(old_rev, old_rev_sha1); | 330 | get_sha1(old_rev, old_rev_sha1); |
323 | else if (commit->parents && commit->parents->item) | 331 | else if (commit->parents && commit->parents->item) |
324 | hashcpy(old_rev_sha1, commit->parents->item->object.sha1); | 332 | hashcpy(old_rev_sha1, commit->parents->item->object.sha1); |
325 | else | 333 | else |
326 | hashclr(old_rev_sha1); | 334 | hashclr(old_rev_sha1); |
327 | 335 | ||
328 | if (!is_null_sha1(old_rev_sha1)) { | 336 | if (!is_null_sha1(old_rev_sha1)) { |
329 | type = sha1_object_info(old_rev_sha1, &size); | 337 | type = sha1_object_info(old_rev_sha1, &size); |
330 | if (type == OBJ_BAD) { | 338 | if (type == OBJ_BAD) { |
331 | cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1))); | 339 | cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1))); |
332 | return; | 340 | return; |
333 | } | 341 | } |
334 | commit2 = lookup_commit_reference(old_rev_sha1); | 342 | commit2 = lookup_commit_reference(old_rev_sha1); |
335 | if (!commit2 || parse_commit(commit2)) | 343 | if (!commit2 || parse_commit(commit2)) |
336 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); | 344 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); |
337 | } | 345 | } |
338 | 346 | ||
339 | if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) | 347 | if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) |
340 | use_ssdiff = 1; | 348 | use_ssdiff = 1; |
341 | 349 | ||
342 | print_ssdiff_link(); | 350 | print_ssdiff_link(); |
343 | cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix); | 351 | cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix); |
344 | 352 | ||
345 | if (use_ssdiff) { | 353 | if (use_ssdiff) { |
346 | html("<table summary='ssdiff' class='ssdiff'>"); | 354 | html("<table summary='ssdiff' class='ssdiff'>"); |
347 | } else { | 355 | } else { |
348 | html("<table summary='diff' class='diff'>"); | 356 | html("<table summary='diff' class='diff'>"); |
349 | html("<tr><td>"); | 357 | html("<tr><td>"); |
350 | } | 358 | } |
351 | cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); | 359 | cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); |
352 | if (!use_ssdiff) | 360 | if (!use_ssdiff) |
353 | html("</td></tr>"); | 361 | html("</td></tr>"); |
354 | html("</table>"); | 362 | html("</table>"); |
355 | } | 363 | } |
diff --git a/ui-shared.c b/ui-shared.c index e991799..c99bcec 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -1,884 +1,898 @@ | |||
1 | /* ui-shared.c: common web output functions | 1 | /* ui-shared.c: common web output functions |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "cmd.h" | 10 | #include "cmd.h" |
11 | #include "html.h" | 11 | #include "html.h" |
12 | 12 | ||
13 | const char cgit_doctype[] = | 13 | const char cgit_doctype[] = |
14 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" | 14 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" |
15 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | 15 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
16 | 16 | ||
17 | static char *http_date(time_t t) | 17 | static char *http_date(time_t t) |
18 | { | 18 | { |
19 | static char day[][4] = | 19 | static char day[][4] = |
20 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; | 20 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; |
21 | static char month[][4] = | 21 | static char month[][4] = |
22 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | 22 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
23 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; | 23 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
24 | struct tm *tm = gmtime(&t); | 24 | struct tm *tm = gmtime(&t); |
25 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], | 25 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], |
26 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, | 26 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, |
27 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 27 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
28 | } | 28 | } |
29 | 29 | ||
30 | void cgit_print_error(const char *msg) | 30 | void cgit_print_error(const char *msg) |
31 | { | 31 | { |
32 | html("<div class='error'>"); | 32 | html("<div class='error'>"); |
33 | html_txt(msg); | 33 | html_txt(msg); |
34 | html("</div>\n"); | 34 | html("</div>\n"); |
35 | } | 35 | } |
36 | 36 | ||
37 | char *cgit_httpscheme() | 37 | char *cgit_httpscheme() |
38 | { | 38 | { |
39 | if (ctx.env.https && !strcmp(ctx.env.https, "on")) | 39 | if (ctx.env.https && !strcmp(ctx.env.https, "on")) |
40 | return "https://"; | 40 | return "https://"; |
41 | else | 41 | else |
42 | return "http://"; | 42 | return "http://"; |
43 | } | 43 | } |
44 | 44 | ||
45 | char *cgit_hosturl() | 45 | char *cgit_hosturl() |
46 | { | 46 | { |
47 | if (ctx.env.http_host) | 47 | if (ctx.env.http_host) |
48 | return ctx.env.http_host; | 48 | return ctx.env.http_host; |
49 | if (!ctx.env.server_name) | 49 | if (!ctx.env.server_name) |
50 | return NULL; | 50 | return NULL; |
51 | if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80) | 51 | if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80) |
52 | return ctx.env.server_name; | 52 | return ctx.env.server_name; |
53 | return xstrdup(fmt("%s:%s", ctx.env.server_name, ctx.env.server_port)); | 53 | return xstrdup(fmt("%s:%s", ctx.env.server_name, ctx.env.server_port)); |
54 | } | 54 | } |
55 | 55 | ||
56 | char *cgit_rooturl() | 56 | char *cgit_rooturl() |
57 | { | 57 | { |
58 | if (ctx.cfg.virtual_root) | 58 | if (ctx.cfg.virtual_root) |
59 | return fmt("%s/", ctx.cfg.virtual_root); | 59 | return fmt("%s/", ctx.cfg.virtual_root); |
60 | else | 60 | else |
61 | return ctx.cfg.script_name; | 61 | return ctx.cfg.script_name; |
62 | } | 62 | } |
63 | 63 | ||
64 | char *cgit_repourl(const char *reponame) | 64 | char *cgit_repourl(const char *reponame) |
65 | { | 65 | { |
66 | if (ctx.cfg.virtual_root) { | 66 | if (ctx.cfg.virtual_root) { |
67 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); | 67 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); |
68 | } else { | 68 | } else { |
69 | return fmt("?r=%s", reponame); | 69 | return fmt("?r=%s", reponame); |
70 | } | 70 | } |
71 | } | 71 | } |
72 | 72 | ||
73 | char *cgit_fileurl(const char *reponame, const char *pagename, | 73 | char *cgit_fileurl(const char *reponame, const char *pagename, |
74 | const char *filename, const char *query) | 74 | const char *filename, const char *query) |
75 | { | 75 | { |
76 | char *tmp; | 76 | char *tmp; |
77 | char *delim; | 77 | char *delim; |
78 | 78 | ||
79 | if (ctx.cfg.virtual_root) { | 79 | if (ctx.cfg.virtual_root) { |
80 | tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, | 80 | tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, |
81 | pagename, (filename ? filename:"")); | 81 | pagename, (filename ? filename:"")); |
82 | delim = "?"; | 82 | delim = "?"; |
83 | } else { | 83 | } else { |
84 | tmp = fmt("?url=%s/%s/%s", reponame, pagename, | 84 | tmp = fmt("?url=%s/%s/%s", reponame, pagename, |
85 | (filename ? filename : "")); | 85 | (filename ? filename : "")); |
86 | delim = "&"; | 86 | delim = "&"; |
87 | } | 87 | } |
88 | if (query) | 88 | if (query) |
89 | tmp = fmt("%s%s%s", tmp, delim, query); | 89 | tmp = fmt("%s%s%s", tmp, delim, query); |
90 | return tmp; | 90 | return tmp; |
91 | } | 91 | } |
92 | 92 | ||
93 | char *cgit_pageurl(const char *reponame, const char *pagename, | 93 | char *cgit_pageurl(const char *reponame, const char *pagename, |
94 | const char *query) | 94 | const char *query) |
95 | { | 95 | { |
96 | return cgit_fileurl(reponame,pagename,0,query); | 96 | return cgit_fileurl(reponame,pagename,0,query); |
97 | } | 97 | } |
98 | 98 | ||
99 | const char *cgit_repobasename(const char *reponame) | 99 | const char *cgit_repobasename(const char *reponame) |
100 | { | 100 | { |
101 | /* I assume we don't need to store more than one repo basename */ | 101 | /* I assume we don't need to store more than one repo basename */ |
102 | static char rvbuf[1024]; | 102 | static char rvbuf[1024]; |
103 | int p; | 103 | int p; |
104 | const char *rv; | 104 | const char *rv; |
105 | strncpy(rvbuf,reponame,sizeof(rvbuf)); | 105 | strncpy(rvbuf,reponame,sizeof(rvbuf)); |
106 | if(rvbuf[sizeof(rvbuf)-1]) | 106 | if(rvbuf[sizeof(rvbuf)-1]) |
107 | die("cgit_repobasename: truncated repository name '%s'", reponame); | 107 | die("cgit_repobasename: truncated repository name '%s'", reponame); |
108 | p = strlen(rvbuf)-1; | 108 | p = strlen(rvbuf)-1; |
109 | /* strip trailing slashes */ | 109 | /* strip trailing slashes */ |
110 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; | 110 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; |
111 | /* strip trailing .git */ | 111 | /* strip trailing .git */ |
112 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { | 112 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { |
113 | p -= 3; rvbuf[p--] = 0; | 113 | p -= 3; rvbuf[p--] = 0; |
114 | } | 114 | } |
115 | /* strip more trailing slashes if any */ | 115 | /* strip more trailing slashes if any */ |
116 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; | 116 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; |
117 | /* find last slash in the remaining string */ | 117 | /* find last slash in the remaining string */ |
118 | rv = strrchr(rvbuf,'/'); | 118 | rv = strrchr(rvbuf,'/'); |
119 | if(rv) | 119 | if(rv) |
120 | return ++rv; | 120 | return ++rv; |
121 | return rvbuf; | 121 | return rvbuf; |
122 | } | 122 | } |
123 | 123 | ||
124 | char *cgit_currurl() | 124 | char *cgit_currurl() |
125 | { | 125 | { |
126 | if (!ctx.cfg.virtual_root) | 126 | if (!ctx.cfg.virtual_root) |
127 | return ctx.cfg.script_name; | 127 | return ctx.cfg.script_name; |
128 | else if (ctx.qry.page) | 128 | else if (ctx.qry.page) |
129 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); | 129 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); |
130 | else if (ctx.qry.repo) | 130 | else if (ctx.qry.repo) |
131 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); | 131 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); |
132 | else | 132 | else |
133 | return fmt("%s/", ctx.cfg.virtual_root); | 133 | return fmt("%s/", ctx.cfg.virtual_root); |
134 | } | 134 | } |
135 | 135 | ||
136 | static void site_url(const char *page, const char *search, int ofs) | 136 | static void site_url(const char *page, const char *search, int ofs) |
137 | { | 137 | { |
138 | char *delim = "?"; | 138 | char *delim = "?"; |
139 | 139 | ||
140 | if (ctx.cfg.virtual_root) { | 140 | if (ctx.cfg.virtual_root) { |
141 | html_attr(ctx.cfg.virtual_root); | 141 | html_attr(ctx.cfg.virtual_root); |
142 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') | 142 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
143 | html("/"); | 143 | html("/"); |
144 | } else | 144 | } else |
145 | html(ctx.cfg.script_name); | 145 | html(ctx.cfg.script_name); |
146 | 146 | ||
147 | if (page) { | 147 | if (page) { |
148 | htmlf("?p=%s", page); | 148 | htmlf("?p=%s", page); |
149 | delim = "&"; | 149 | delim = "&"; |
150 | } | 150 | } |
151 | if (search) { | 151 | if (search) { |
152 | html(delim); | 152 | html(delim); |
153 | html("q="); | 153 | html("q="); |
154 | html_attr(search); | 154 | html_attr(search); |
155 | delim = "&"; | 155 | delim = "&"; |
156 | } | 156 | } |
157 | if (ofs) { | 157 | if (ofs) { |
158 | html(delim); | 158 | html(delim); |
159 | htmlf("ofs=%d", ofs); | 159 | htmlf("ofs=%d", ofs); |
160 | } | 160 | } |
161 | } | 161 | } |
162 | 162 | ||
163 | static void site_link(const char *page, const char *name, const char *title, | 163 | static void site_link(const char *page, const char *name, const char *title, |
164 | const char *class, const char *search, int ofs) | 164 | const char *class, const char *search, int ofs) |
165 | { | 165 | { |
166 | html("<a"); | 166 | html("<a"); |
167 | if (title) { | 167 | if (title) { |
168 | html(" title='"); | 168 | html(" title='"); |
169 | html_attr(title); | 169 | html_attr(title); |
170 | html("'"); | 170 | html("'"); |
171 | } | 171 | } |
172 | if (class) { | 172 | if (class) { |
173 | html(" class='"); | 173 | html(" class='"); |
174 | html_attr(class); | 174 | html_attr(class); |
175 | html("'"); | 175 | html("'"); |
176 | } | 176 | } |
177 | html(" href='"); | 177 | html(" href='"); |
178 | site_url(page, search, ofs); | 178 | site_url(page, search, ofs); |
179 | html("'>"); | 179 | html("'>"); |
180 | html_txt(name); | 180 | html_txt(name); |
181 | html("</a>"); | 181 | html("</a>"); |
182 | } | 182 | } |
183 | 183 | ||
184 | void cgit_index_link(const char *name, const char *title, const char *class, | 184 | void cgit_index_link(const char *name, const char *title, const char *class, |
185 | const char *pattern, int ofs) | 185 | const char *pattern, int ofs) |
186 | { | 186 | { |
187 | site_link(NULL, name, title, class, pattern, ofs); | 187 | site_link(NULL, name, title, class, pattern, ofs); |
188 | } | 188 | } |
189 | 189 | ||
190 | static char *repolink(const char *title, const char *class, const char *page, | 190 | static char *repolink(const char *title, const char *class, const char *page, |
191 | const char *head, const char *path) | 191 | const char *head, const char *path) |
192 | { | 192 | { |
193 | char *delim = "?"; | 193 | char *delim = "?"; |
194 | 194 | ||
195 | html("<a"); | 195 | html("<a"); |
196 | if (title) { | 196 | if (title) { |
197 | html(" title='"); | 197 | html(" title='"); |
198 | html_attr(title); | 198 | html_attr(title); |
199 | html("'"); | 199 | html("'"); |
200 | } | 200 | } |
201 | if (class) { | 201 | if (class) { |
202 | html(" class='"); | 202 | html(" class='"); |
203 | html_attr(class); | 203 | html_attr(class); |
204 | html("'"); | 204 | html("'"); |
205 | } | 205 | } |
206 | html(" href='"); | 206 | html(" href='"); |
207 | if (ctx.cfg.virtual_root) { | 207 | if (ctx.cfg.virtual_root) { |
208 | html_url_path(ctx.cfg.virtual_root); | 208 | html_url_path(ctx.cfg.virtual_root); |
209 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') | 209 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
210 | html("/"); | 210 | html("/"); |
211 | html_url_path(ctx.repo->url); | 211 | html_url_path(ctx.repo->url); |
212 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') | 212 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
213 | html("/"); | 213 | html("/"); |
214 | if (page) { | 214 | if (page) { |
215 | html_url_path(page); | 215 | html_url_path(page); |
216 | html("/"); | 216 | html("/"); |
217 | if (path) | 217 | if (path) |
218 | html_url_path(path); | 218 | html_url_path(path); |
219 | } | 219 | } |
220 | } else { | 220 | } else { |
221 | html(ctx.cfg.script_name); | 221 | html(ctx.cfg.script_name); |
222 | html("?url="); | 222 | html("?url="); |
223 | html_url_arg(ctx.repo->url); | 223 | html_url_arg(ctx.repo->url); |
224 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') | 224 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
225 | html("/"); | 225 | html("/"); |
226 | if (page) { | 226 | if (page) { |
227 | html_url_arg(page); | 227 | html_url_arg(page); |
228 | html("/"); | 228 | html("/"); |
229 | if (path) | 229 | if (path) |
230 | html_url_arg(path); | 230 | html_url_arg(path); |
231 | } | 231 | } |
232 | delim = "&"; | 232 | delim = "&"; |
233 | } | 233 | } |
234 | if (head && strcmp(head, ctx.repo->defbranch)) { | 234 | if (head && strcmp(head, ctx.repo->defbranch)) { |
235 | html(delim); | 235 | html(delim); |
236 | html("h="); | 236 | html("h="); |
237 | html_url_arg(head); | 237 | html_url_arg(head); |
238 | delim = "&"; | 238 | delim = "&"; |
239 | } | 239 | } |
240 | return fmt("%s", delim); | 240 | return fmt("%s", delim); |
241 | } | 241 | } |
242 | 242 | ||
243 | static void reporevlink(const char *page, const char *name, const char *title, | 243 | static void reporevlink(const char *page, const char *name, const char *title, |
244 | const char *class, const char *head, const char *rev, | 244 | const char *class, const char *head, const char *rev, |
245 | const char *path) | 245 | const char *path) |
246 | { | 246 | { |
247 | char *delim; | 247 | char *delim; |
248 | 248 | ||
249 | delim = repolink(title, class, page, head, path); | 249 | delim = repolink(title, class, page, head, path); |
250 | if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) { | 250 | if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) { |
251 | html(delim); | 251 | html(delim); |
252 | html("id="); | 252 | html("id="); |
253 | html_url_arg(rev); | 253 | html_url_arg(rev); |
254 | } | 254 | } |
255 | html("'>"); | 255 | html("'>"); |
256 | html_txt(name); | 256 | html_txt(name); |
257 | html("</a>"); | 257 | html("</a>"); |
258 | } | 258 | } |
259 | 259 | ||
260 | void cgit_summary_link(const char *name, const char *title, const char *class, | 260 | void cgit_summary_link(const char *name, const char *title, const char *class, |
261 | const char *head) | 261 | const char *head) |
262 | { | 262 | { |
263 | reporevlink(NULL, name, title, class, head, NULL, NULL); | 263 | reporevlink(NULL, name, title, class, head, NULL, NULL); |
264 | } | 264 | } |
265 | 265 | ||
266 | void cgit_tag_link(const char *name, const char *title, const char *class, | 266 | void cgit_tag_link(const char *name, const char *title, const char *class, |
267 | const char *head, const char *rev) | 267 | const char *head, const char *rev) |
268 | { | 268 | { |
269 | reporevlink("tag", name, title, class, head, rev, NULL); | 269 | reporevlink("tag", name, title, class, head, rev, NULL); |
270 | } | 270 | } |
271 | 271 | ||
272 | void cgit_tree_link(const char *name, const char *title, const char *class, | 272 | void cgit_tree_link(const char *name, const char *title, const char *class, |
273 | const char *head, const char *rev, const char *path) | 273 | const char *head, const char *rev, const char *path) |
274 | { | 274 | { |
275 | reporevlink("tree", name, title, class, head, rev, path); | 275 | reporevlink("tree", name, title, class, head, rev, path); |
276 | } | 276 | } |
277 | 277 | ||
278 | void cgit_plain_link(const char *name, const char *title, const char *class, | 278 | void cgit_plain_link(const char *name, const char *title, const char *class, |
279 | const char *head, const char *rev, const char *path) | 279 | const char *head, const char *rev, const char *path) |
280 | { | 280 | { |
281 | reporevlink("plain", name, title, class, head, rev, path); | 281 | reporevlink("plain", name, title, class, head, rev, path); |
282 | } | 282 | } |
283 | 283 | ||
284 | void cgit_log_link(const char *name, const char *title, const char *class, | 284 | void cgit_log_link(const char *name, const char *title, const char *class, |
285 | const char *head, const char *rev, const char *path, | 285 | const char *head, const char *rev, const char *path, |
286 | int ofs, const char *grep, const char *pattern, int showmsg) | 286 | int ofs, const char *grep, const char *pattern, int showmsg) |
287 | { | 287 | { |
288 | char *delim; | 288 | char *delim; |
289 | 289 | ||
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 | ||
321 | void cgit_commit_link(char *name, const char *title, const char *class, | 321 | void cgit_commit_link(char *name, const char *title, const char *class, |
322 | const char *head, const char *rev, const char *path, | 322 | const char *head, const char *rev, const char *path, |
323 | int toggle_ssdiff) | 323 | int toggle_ssdiff) |
324 | { | 324 | { |
325 | 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) { |
326 | name[ctx.cfg.max_msg_len] = '\0'; | 326 | name[ctx.cfg.max_msg_len] = '\0'; |
327 | name[ctx.cfg.max_msg_len - 1] = '.'; | 327 | name[ctx.cfg.max_msg_len - 1] = '.'; |
328 | name[ctx.cfg.max_msg_len - 2] = '.'; | 328 | name[ctx.cfg.max_msg_len - 2] = '.'; |
329 | name[ctx.cfg.max_msg_len - 3] = '.'; | 329 | name[ctx.cfg.max_msg_len - 3] = '.'; |
330 | } | 330 | } |
331 | 331 | ||
332 | char *delim; | 332 | char *delim; |
333 | 333 | ||
334 | delim = repolink(title, class, "commit", head, path); | 334 | delim = repolink(title, class, "commit", head, path); |
335 | if (rev && strcmp(rev, ctx.qry.head)) { | 335 | if (rev && strcmp(rev, ctx.qry.head)) { |
336 | html(delim); | 336 | html(delim); |
337 | html("id="); | 337 | html("id="); |
338 | html_url_arg(rev); | 338 | html_url_arg(rev); |
339 | delim = "&"; | 339 | delim = "&"; |
340 | } | 340 | } |
341 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { | 341 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { |
342 | html(delim); | 342 | html(delim); |
343 | html("ss=1"); | 343 | html("ss=1"); |
344 | delim = "&"; | ||
345 | } | ||
346 | if (ctx.qry.context > 0 && ctx.qry.context != 3) { | ||
347 | html(delim); | ||
348 | html("context="); | ||
349 | htmlf("%d", ctx.qry.context); | ||
350 | delim = "&"; | ||
344 | } | 351 | } |
345 | html("'>"); | 352 | html("'>"); |
346 | html_txt(name); | 353 | html_txt(name); |
347 | html("</a>"); | 354 | html("</a>"); |
348 | } | 355 | } |
349 | 356 | ||
350 | void cgit_refs_link(const char *name, const char *title, const char *class, | 357 | void cgit_refs_link(const char *name, const char *title, const char *class, |
351 | const char *head, const char *rev, const char *path) | 358 | const char *head, const char *rev, const char *path) |
352 | { | 359 | { |
353 | reporevlink("refs", name, title, class, head, rev, path); | 360 | reporevlink("refs", name, title, class, head, rev, path); |
354 | } | 361 | } |
355 | 362 | ||
356 | void cgit_snapshot_link(const char *name, const char *title, const char *class, | 363 | void cgit_snapshot_link(const char *name, const char *title, const char *class, |
357 | const char *head, const char *rev, | 364 | const char *head, const char *rev, |
358 | const char *archivename) | 365 | const char *archivename) |
359 | { | 366 | { |
360 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 367 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
361 | } | 368 | } |
362 | 369 | ||
363 | void cgit_diff_link(const char *name, const char *title, const char *class, | 370 | void cgit_diff_link(const char *name, const char *title, const char *class, |
364 | const char *head, const char *new_rev, const char *old_rev, | 371 | const char *head, const char *new_rev, const char *old_rev, |
365 | const char *path, int toggle_ssdiff) | 372 | const char *path, int toggle_ssdiff) |
366 | { | 373 | { |
367 | char *delim; | 374 | char *delim; |
368 | 375 | ||
369 | delim = repolink(title, class, "diff", head, path); | 376 | delim = repolink(title, class, "diff", head, path); |
370 | if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) { | 377 | if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) { |
371 | html(delim); | 378 | html(delim); |
372 | html("id="); | 379 | html("id="); |
373 | html_url_arg(new_rev); | 380 | html_url_arg(new_rev); |
374 | delim = "&"; | 381 | delim = "&"; |
375 | } | 382 | } |
376 | if (old_rev) { | 383 | if (old_rev) { |
377 | html(delim); | 384 | html(delim); |
378 | html("id2="); | 385 | html("id2="); |
379 | html_url_arg(old_rev); | 386 | html_url_arg(old_rev); |
380 | delim = "&"; | 387 | delim = "&"; |
381 | } | 388 | } |
382 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { | 389 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { |
383 | html(delim); | 390 | html(delim); |
384 | html("ss=1"); | 391 | html("ss=1"); |
392 | delim = "&"; | ||
393 | } | ||
394 | if (ctx.qry.context > 0 && ctx.qry.context != 3) { | ||
395 | html(delim); | ||
396 | html("context="); | ||
397 | htmlf("%d", ctx.qry.context); | ||
398 | delim = "&"; | ||
385 | } | 399 | } |
386 | html("'>"); | 400 | html("'>"); |
387 | html_txt(name); | 401 | html_txt(name); |
388 | html("</a>"); | 402 | html("</a>"); |
389 | } | 403 | } |
390 | 404 | ||
391 | void cgit_patch_link(const char *name, const char *title, const char *class, | 405 | void cgit_patch_link(const char *name, const char *title, const char *class, |
392 | const char *head, const char *rev, const char *path) | 406 | const char *head, const char *rev, const char *path) |
393 | { | 407 | { |
394 | reporevlink("patch", name, title, class, head, rev, path); | 408 | reporevlink("patch", name, title, class, head, rev, path); |
395 | } | 409 | } |
396 | 410 | ||
397 | void cgit_stats_link(const char *name, const char *title, const char *class, | 411 | void cgit_stats_link(const char *name, const char *title, const char *class, |
398 | const char *head, const char *path) | 412 | const char *head, const char *path) |
399 | { | 413 | { |
400 | reporevlink("stats", name, title, class, head, NULL, path); | 414 | reporevlink("stats", name, title, class, head, NULL, path); |
401 | } | 415 | } |
402 | 416 | ||
403 | void cgit_self_link(char *name, const char *title, const char *class, | 417 | void cgit_self_link(char *name, const char *title, const char *class, |
404 | struct cgit_context *ctx) | 418 | struct cgit_context *ctx) |
405 | { | 419 | { |
406 | if (!strcmp(ctx->qry.page, "repolist")) | 420 | if (!strcmp(ctx->qry.page, "repolist")) |
407 | return cgit_index_link(name, title, class, ctx->qry.search, | 421 | return cgit_index_link(name, title, class, ctx->qry.search, |
408 | ctx->qry.ofs); | 422 | ctx->qry.ofs); |
409 | else if (!strcmp(ctx->qry.page, "summary")) | 423 | else if (!strcmp(ctx->qry.page, "summary")) |
410 | return cgit_summary_link(name, title, class, ctx->qry.head); | 424 | return cgit_summary_link(name, title, class, ctx->qry.head); |
411 | else if (!strcmp(ctx->qry.page, "tag")) | 425 | else if (!strcmp(ctx->qry.page, "tag")) |
412 | return cgit_tag_link(name, title, class, ctx->qry.head, | 426 | return cgit_tag_link(name, title, class, ctx->qry.head, |
413 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL); | 427 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL); |
414 | else if (!strcmp(ctx->qry.page, "tree")) | 428 | else if (!strcmp(ctx->qry.page, "tree")) |
415 | return cgit_tree_link(name, title, class, ctx->qry.head, | 429 | return cgit_tree_link(name, title, class, ctx->qry.head, |
416 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 430 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
417 | ctx->qry.path); | 431 | ctx->qry.path); |
418 | else if (!strcmp(ctx->qry.page, "plain")) | 432 | else if (!strcmp(ctx->qry.page, "plain")) |
419 | return cgit_plain_link(name, title, class, ctx->qry.head, | 433 | return cgit_plain_link(name, title, class, ctx->qry.head, |
420 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 434 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
421 | ctx->qry.path); | 435 | ctx->qry.path); |
422 | else if (!strcmp(ctx->qry.page, "log")) | 436 | else if (!strcmp(ctx->qry.page, "log")) |
423 | return cgit_log_link(name, title, class, ctx->qry.head, | 437 | return cgit_log_link(name, title, class, ctx->qry.head, |
424 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 438 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
425 | ctx->qry.path, ctx->qry.ofs, | 439 | ctx->qry.path, ctx->qry.ofs, |
426 | ctx->qry.grep, ctx->qry.search, | 440 | ctx->qry.grep, ctx->qry.search, |
427 | ctx->qry.showmsg); | 441 | ctx->qry.showmsg); |
428 | else if (!strcmp(ctx->qry.page, "commit")) | 442 | else if (!strcmp(ctx->qry.page, "commit")) |
429 | return cgit_commit_link(name, title, class, ctx->qry.head, | 443 | return cgit_commit_link(name, title, class, ctx->qry.head, |
430 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 444 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
431 | ctx->qry.path, 0); | 445 | ctx->qry.path, 0); |
432 | else if (!strcmp(ctx->qry.page, "patch")) | 446 | else if (!strcmp(ctx->qry.page, "patch")) |
433 | return cgit_patch_link(name, title, class, ctx->qry.head, | 447 | return cgit_patch_link(name, title, class, ctx->qry.head, |
434 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 448 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
435 | ctx->qry.path); | 449 | ctx->qry.path); |
436 | else if (!strcmp(ctx->qry.page, "refs")) | 450 | else if (!strcmp(ctx->qry.page, "refs")) |
437 | return cgit_refs_link(name, title, class, ctx->qry.head, | 451 | return cgit_refs_link(name, title, class, ctx->qry.head, |
438 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 452 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
439 | ctx->qry.path); | 453 | ctx->qry.path); |
440 | else if (!strcmp(ctx->qry.page, "snapshot")) | 454 | else if (!strcmp(ctx->qry.page, "snapshot")) |
441 | return cgit_snapshot_link(name, title, class, ctx->qry.head, | 455 | return cgit_snapshot_link(name, title, class, ctx->qry.head, |
442 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 456 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
443 | ctx->qry.path); | 457 | ctx->qry.path); |
444 | else if (!strcmp(ctx->qry.page, "diff")) | 458 | else if (!strcmp(ctx->qry.page, "diff")) |
445 | return cgit_diff_link(name, title, class, ctx->qry.head, | 459 | return cgit_diff_link(name, title, class, ctx->qry.head, |
446 | ctx->qry.sha1, ctx->qry.sha2, | 460 | ctx->qry.sha1, ctx->qry.sha2, |
447 | ctx->qry.path, 0); | 461 | ctx->qry.path, 0); |
448 | else if (!strcmp(ctx->qry.page, "stats")) | 462 | else if (!strcmp(ctx->qry.page, "stats")) |
449 | return cgit_stats_link(name, title, class, ctx->qry.head, | 463 | return cgit_stats_link(name, title, class, ctx->qry.head, |
450 | ctx->qry.path); | 464 | ctx->qry.path); |
451 | 465 | ||
452 | /* Don't known how to make link for this page */ | 466 | /* Don't known how to make link for this page */ |
453 | repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path); | 467 | repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path); |
454 | html("><!-- cgit_self_link() doesn't know how to make link for page '"); | 468 | html("><!-- cgit_self_link() doesn't know how to make link for page '"); |
455 | html_txt(ctx->qry.page); | 469 | html_txt(ctx->qry.page); |
456 | html("' -->"); | 470 | html("' -->"); |
457 | html_txt(name); | 471 | html_txt(name); |
458 | html("</a>"); | 472 | html("</a>"); |
459 | } | 473 | } |
460 | 474 | ||
461 | void cgit_object_link(struct object *obj) | 475 | void cgit_object_link(struct object *obj) |
462 | { | 476 | { |
463 | char *page, *shortrev, *fullrev, *name; | 477 | char *page, *shortrev, *fullrev, *name; |
464 | 478 | ||
465 | fullrev = sha1_to_hex(obj->sha1); | 479 | fullrev = sha1_to_hex(obj->sha1); |
466 | shortrev = xstrdup(fullrev); | 480 | shortrev = xstrdup(fullrev); |
467 | shortrev[10] = '\0'; | 481 | shortrev[10] = '\0'; |
468 | if (obj->type == OBJ_COMMIT) { | 482 | if (obj->type == OBJ_COMMIT) { |
469 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, | 483 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, |
470 | ctx.qry.head, fullrev, NULL, 0); | 484 | ctx.qry.head, fullrev, NULL, 0); |
471 | return; | 485 | return; |
472 | } else if (obj->type == OBJ_TREE) | 486 | } else if (obj->type == OBJ_TREE) |
473 | page = "tree"; | 487 | page = "tree"; |
474 | else if (obj->type == OBJ_TAG) | 488 | else if (obj->type == OBJ_TAG) |
475 | page = "tag"; | 489 | page = "tag"; |
476 | else | 490 | else |
477 | page = "blob"; | 491 | page = "blob"; |
478 | name = fmt("%s %s...", typename(obj->type), shortrev); | 492 | name = fmt("%s %s...", typename(obj->type), shortrev); |
479 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); | 493 | reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); |
480 | } | 494 | } |
481 | 495 | ||
482 | void cgit_print_date(time_t secs, const char *format, int local_time) | 496 | void cgit_print_date(time_t secs, const char *format, int local_time) |
483 | { | 497 | { |
484 | char buf[64]; | 498 | char buf[64]; |
485 | struct tm *time; | 499 | struct tm *time; |
486 | 500 | ||
487 | if (!secs) | 501 | if (!secs) |
488 | return; | 502 | return; |
489 | if(local_time) | 503 | if(local_time) |
490 | time = localtime(&secs); | 504 | time = localtime(&secs); |
491 | else | 505 | else |
492 | time = gmtime(&secs); | 506 | time = gmtime(&secs); |
493 | strftime(buf, sizeof(buf)-1, format, time); | 507 | strftime(buf, sizeof(buf)-1, format, time); |
494 | html_txt(buf); | 508 | html_txt(buf); |
495 | } | 509 | } |
496 | 510 | ||
497 | void cgit_print_age(time_t t, time_t max_relative, const char *format) | 511 | void cgit_print_age(time_t t, time_t max_relative, const char *format) |
498 | { | 512 | { |
499 | time_t now, secs; | 513 | time_t now, secs; |
500 | 514 | ||
501 | if (!t) | 515 | if (!t) |
502 | return; | 516 | return; |
503 | time(&now); | 517 | time(&now); |
504 | secs = now - t; | 518 | secs = now - t; |
505 | 519 | ||
506 | if (secs > max_relative && max_relative >= 0) { | 520 | if (secs > max_relative && max_relative >= 0) { |
507 | cgit_print_date(t, format, ctx.cfg.local_time); | 521 | cgit_print_date(t, format, ctx.cfg.local_time); |
508 | return; | 522 | return; |
509 | } | 523 | } |
510 | 524 | ||
511 | if (secs < TM_HOUR * 2) { | 525 | if (secs < TM_HOUR * 2) { |
512 | htmlf("<span class='age-mins'>%.0f min.</span>", | 526 | htmlf("<span class='age-mins'>%.0f min.</span>", |
513 | secs * 1.0 / TM_MIN); | 527 | secs * 1.0 / TM_MIN); |
514 | return; | 528 | return; |
515 | } | 529 | } |
516 | if (secs < TM_DAY * 2) { | 530 | if (secs < TM_DAY * 2) { |
517 | htmlf("<span class='age-hours'>%.0f hours</span>", | 531 | htmlf("<span class='age-hours'>%.0f hours</span>", |
518 | secs * 1.0 / TM_HOUR); | 532 | secs * 1.0 / TM_HOUR); |
519 | return; | 533 | return; |
520 | } | 534 | } |
521 | if (secs < TM_WEEK * 2) { | 535 | if (secs < TM_WEEK * 2) { |
522 | htmlf("<span class='age-days'>%.0f days</span>", | 536 | htmlf("<span class='age-days'>%.0f days</span>", |
523 | secs * 1.0 / TM_DAY); | 537 | secs * 1.0 / TM_DAY); |
524 | return; | 538 | return; |
525 | } | 539 | } |
526 | if (secs < TM_MONTH * 2) { | 540 | if (secs < TM_MONTH * 2) { |
527 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 541 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
528 | secs * 1.0 / TM_WEEK); | 542 | secs * 1.0 / TM_WEEK); |
529 | return; | 543 | return; |
530 | } | 544 | } |
531 | if (secs < TM_YEAR * 2) { | 545 | if (secs < TM_YEAR * 2) { |
532 | htmlf("<span class='age-months'>%.0f months</span>", | 546 | htmlf("<span class='age-months'>%.0f months</span>", |
533 | secs * 1.0 / TM_MONTH); | 547 | secs * 1.0 / TM_MONTH); |
534 | return; | 548 | return; |
535 | } | 549 | } |
536 | htmlf("<span class='age-years'>%.0f years</span>", | 550 | htmlf("<span class='age-years'>%.0f years</span>", |
537 | secs * 1.0 / TM_YEAR); | 551 | secs * 1.0 / TM_YEAR); |
538 | } | 552 | } |
539 | 553 | ||
540 | void cgit_print_http_headers(struct cgit_context *ctx) | 554 | void cgit_print_http_headers(struct cgit_context *ctx) |
541 | { | 555 | { |
542 | if (ctx->env.no_http && !strcmp(ctx->env.no_http, "1")) | 556 | if (ctx->env.no_http && !strcmp(ctx->env.no_http, "1")) |
543 | return; | 557 | return; |
544 | 558 | ||
545 | if (ctx->page.status) | 559 | if (ctx->page.status) |
546 | htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); | 560 | htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); |
547 | if (ctx->page.mimetype && ctx->page.charset) | 561 | if (ctx->page.mimetype && ctx->page.charset) |
548 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, | 562 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, |
549 | ctx->page.charset); | 563 | ctx->page.charset); |
550 | else if (ctx->page.mimetype) | 564 | else if (ctx->page.mimetype) |
551 | htmlf("Content-Type: %s\n", ctx->page.mimetype); | 565 | htmlf("Content-Type: %s\n", ctx->page.mimetype); |
552 | if (ctx->page.size) | 566 | if (ctx->page.size) |
553 | htmlf("Content-Length: %ld\n", ctx->page.size); | 567 | htmlf("Content-Length: %ld\n", ctx->page.size); |
554 | if (ctx->page.filename) | 568 | if (ctx->page.filename) |
555 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", | 569 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", |
556 | ctx->page.filename); | 570 | ctx->page.filename); |
557 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); | 571 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); |
558 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); | 572 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); |
559 | if (ctx->page.etag) | 573 | if (ctx->page.etag) |
560 | htmlf("ETag: \"%s\"\n", ctx->page.etag); | 574 | htmlf("ETag: \"%s\"\n", ctx->page.etag); |
561 | html("\n"); | 575 | html("\n"); |
562 | if (ctx->env.request_method && !strcmp(ctx->env.request_method, "HEAD")) | 576 | if (ctx->env.request_method && !strcmp(ctx->env.request_method, "HEAD")) |
563 | exit(0); | 577 | exit(0); |
564 | } | 578 | } |
565 | 579 | ||
566 | void cgit_print_docstart(struct cgit_context *ctx) | 580 | void cgit_print_docstart(struct cgit_context *ctx) |
567 | { | 581 | { |
568 | if (ctx->cfg.embedded) { | 582 | if (ctx->cfg.embedded) { |
569 | if (ctx->cfg.header) | 583 | if (ctx->cfg.header) |
570 | html_include(ctx->cfg.header); | 584 | html_include(ctx->cfg.header); |
571 | return; | 585 | return; |
572 | } | 586 | } |
573 | 587 | ||
574 | char *host = cgit_hosturl(); | 588 | char *host = cgit_hosturl(); |
575 | html(cgit_doctype); | 589 | html(cgit_doctype); |
576 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 590 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
577 | html("<head>\n"); | 591 | html("<head>\n"); |
578 | html("<title>"); | 592 | html("<title>"); |
579 | html_txt(ctx->page.title); | 593 | html_txt(ctx->page.title); |
580 | html("</title>\n"); | 594 | html("</title>\n"); |
581 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 595 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
582 | if (ctx->cfg.robots && *ctx->cfg.robots) | 596 | if (ctx->cfg.robots && *ctx->cfg.robots) |
583 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); | 597 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
584 | html("<link rel='stylesheet' type='text/css' href='"); | 598 | html("<link rel='stylesheet' type='text/css' href='"); |
585 | html_attr(ctx->cfg.css); | 599 | html_attr(ctx->cfg.css); |
586 | html("'/>\n"); | 600 | html("'/>\n"); |
587 | if (ctx->cfg.favicon) { | 601 | if (ctx->cfg.favicon) { |
588 | html("<link rel='shortcut icon' href='"); | 602 | html("<link rel='shortcut icon' href='"); |
589 | html_attr(ctx->cfg.favicon); | 603 | html_attr(ctx->cfg.favicon); |
590 | html("'/>\n"); | 604 | html("'/>\n"); |
591 | } | 605 | } |
592 | if (host && ctx->repo) { | 606 | if (host && ctx->repo) { |
593 | html("<link rel='alternate' title='Atom feed' href='"); | 607 | html("<link rel='alternate' title='Atom feed' href='"); |
594 | html(cgit_httpscheme()); | 608 | html(cgit_httpscheme()); |
595 | html_attr(cgit_hosturl()); | 609 | html_attr(cgit_hosturl()); |
596 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.vpath, | 610 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.vpath, |
597 | fmt("h=%s", ctx->qry.head))); | 611 | fmt("h=%s", ctx->qry.head))); |
598 | html("' type='application/atom+xml'/>\n"); | 612 | html("' type='application/atom+xml'/>\n"); |
599 | } | 613 | } |
600 | if (ctx->cfg.head_include) | 614 | if (ctx->cfg.head_include) |
601 | html_include(ctx->cfg.head_include); | 615 | html_include(ctx->cfg.head_include); |
602 | html("</head>\n"); | 616 | html("</head>\n"); |
603 | html("<body>\n"); | 617 | html("<body>\n"); |
604 | if (ctx->cfg.header) | 618 | if (ctx->cfg.header) |
605 | html_include(ctx->cfg.header); | 619 | html_include(ctx->cfg.header); |
606 | } | 620 | } |
607 | 621 | ||
608 | void cgit_print_docend() | 622 | void cgit_print_docend() |
609 | { | 623 | { |
610 | html("</div> <!-- class=content -->\n"); | 624 | html("</div> <!-- class=content -->\n"); |
611 | if (ctx.cfg.embedded) { | 625 | if (ctx.cfg.embedded) { |
612 | html("</div> <!-- id=cgit -->\n"); | 626 | html("</div> <!-- id=cgit -->\n"); |
613 | if (ctx.cfg.footer) | 627 | if (ctx.cfg.footer) |
614 | html_include(ctx.cfg.footer); | 628 | html_include(ctx.cfg.footer); |
615 | return; | 629 | return; |
616 | } | 630 | } |
617 | if (ctx.cfg.footer) | 631 | if (ctx.cfg.footer) |
618 | html_include(ctx.cfg.footer); | 632 | html_include(ctx.cfg.footer); |
619 | else { | 633 | else { |
620 | htmlf("<div class='footer'>generated by cgit %s at ", | 634 | htmlf("<div class='footer'>generated by cgit %s at ", |
621 | cgit_version); | 635 | cgit_version); |
622 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); | 636 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); |
623 | html("</div>\n"); | 637 | html("</div>\n"); |
624 | } | 638 | } |
625 | html("</div> <!-- id=cgit -->\n"); | 639 | html("</div> <!-- id=cgit -->\n"); |
626 | html("</body>\n</html>\n"); | 640 | html("</body>\n</html>\n"); |
627 | } | 641 | } |
628 | 642 | ||
629 | int print_branch_option(const char *refname, const unsigned char *sha1, | 643 | int print_branch_option(const char *refname, const unsigned char *sha1, |
630 | int flags, void *cb_data) | 644 | int flags, void *cb_data) |
631 | { | 645 | { |
632 | char *name = (char *)refname; | 646 | char *name = (char *)refname; |
633 | html_option(name, name, ctx.qry.head); | 647 | html_option(name, name, ctx.qry.head); |
634 | return 0; | 648 | return 0; |
635 | } | 649 | } |
636 | 650 | ||
637 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 651 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
638 | int flags, void *cb_data) | 652 | int flags, void *cb_data) |
639 | { | 653 | { |
640 | struct tag *tag; | 654 | struct tag *tag; |
641 | struct taginfo *info; | 655 | struct taginfo *info; |
642 | struct object *obj; | 656 | struct object *obj; |
643 | char buf[256], *url; | 657 | char buf[256], *url; |
644 | unsigned char fileid[20]; | 658 | unsigned char fileid[20]; |
645 | int *header = (int *)cb_data; | 659 | int *header = (int *)cb_data; |
646 | 660 | ||
647 | if (prefixcmp(refname, "refs/archives")) | 661 | if (prefixcmp(refname, "refs/archives")) |
648 | return 0; | 662 | return 0; |
649 | strncpy(buf, refname+14, sizeof(buf)); | 663 | strncpy(buf, refname+14, sizeof(buf)); |
650 | obj = parse_object(sha1); | 664 | obj = parse_object(sha1); |
651 | if (!obj) | 665 | if (!obj) |
652 | return 1; | 666 | return 1; |
653 | if (obj->type == OBJ_TAG) { | 667 | if (obj->type == OBJ_TAG) { |
654 | tag = lookup_tag(sha1); | 668 | tag = lookup_tag(sha1); |
655 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 669 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
656 | return 0; | 670 | return 0; |
657 | hashcpy(fileid, tag->tagged->sha1); | 671 | hashcpy(fileid, tag->tagged->sha1); |
658 | } else if (obj->type != OBJ_BLOB) { | 672 | } else if (obj->type != OBJ_BLOB) { |
659 | return 0; | 673 | return 0; |
660 | } else { | 674 | } else { |
661 | hashcpy(fileid, sha1); | 675 | hashcpy(fileid, sha1); |
662 | } | 676 | } |
663 | if (!*header) { | 677 | if (!*header) { |
664 | html("<h1>download</h1>\n"); | 678 | html("<h1>download</h1>\n"); |
665 | *header = 1; | 679 | *header = 1; |
666 | } | 680 | } |
667 | url = cgit_pageurl(ctx.qry.repo, "blob", | 681 | url = cgit_pageurl(ctx.qry.repo, "blob", |
668 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 682 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
669 | buf)); | 683 | buf)); |
670 | html_link_open(url, NULL, "menu"); | 684 | html_link_open(url, NULL, "menu"); |
671 | html_txt(strlpart(buf, 20)); | 685 | html_txt(strlpart(buf, 20)); |
672 | html_link_close(); | 686 | html_link_close(); |
673 | return 0; | 687 | return 0; |
674 | } | 688 | } |
675 | 689 | ||
676 | void cgit_add_hidden_formfields(int incl_head, int incl_search, | 690 | void cgit_add_hidden_formfields(int incl_head, int incl_search, |
677 | const char *page) | 691 | const char *page) |
678 | { | 692 | { |
679 | char *url; | 693 | char *url; |
680 | 694 | ||
681 | if (!ctx.cfg.virtual_root) { | 695 | if (!ctx.cfg.virtual_root) { |
682 | url = fmt("%s/%s", ctx.qry.repo, page); | 696 | url = fmt("%s/%s", ctx.qry.repo, page); |
683 | if (ctx.qry.vpath) | 697 | if (ctx.qry.vpath) |
684 | url = fmt("%s/%s", url, ctx.qry.vpath); | 698 | url = fmt("%s/%s", url, ctx.qry.vpath); |
685 | html_hidden("url", url); | 699 | html_hidden("url", url); |
686 | } | 700 | } |
687 | 701 | ||
688 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && | 702 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && |
689 | strcmp(ctx.qry.head, ctx.repo->defbranch)) | 703 | strcmp(ctx.qry.head, ctx.repo->defbranch)) |
690 | html_hidden("h", ctx.qry.head); | 704 | html_hidden("h", ctx.qry.head); |
691 | 705 | ||
692 | if (ctx.qry.sha1) | 706 | if (ctx.qry.sha1) |
693 | html_hidden("id", ctx.qry.sha1); | 707 | html_hidden("id", ctx.qry.sha1); |
694 | if (ctx.qry.sha2) | 708 | if (ctx.qry.sha2) |
695 | html_hidden("id2", ctx.qry.sha2); | 709 | html_hidden("id2", ctx.qry.sha2); |
696 | if (ctx.qry.showmsg) | 710 | if (ctx.qry.showmsg) |
697 | html_hidden("showmsg", "1"); | 711 | html_hidden("showmsg", "1"); |
698 | 712 | ||
699 | if (incl_search) { | 713 | if (incl_search) { |
700 | if (ctx.qry.grep) | 714 | if (ctx.qry.grep) |
701 | html_hidden("qt", ctx.qry.grep); | 715 | html_hidden("qt", ctx.qry.grep); |
702 | if (ctx.qry.search) | 716 | if (ctx.qry.search) |
703 | html_hidden("q", ctx.qry.search); | 717 | html_hidden("q", ctx.qry.search); |
704 | } | 718 | } |
705 | } | 719 | } |
706 | 720 | ||
707 | static const char *hc(struct cgit_context *ctx, const char *page) | 721 | static const char *hc(struct cgit_context *ctx, const char *page) |
708 | { | 722 | { |
709 | return strcmp(ctx->qry.page, page) ? NULL : "active"; | 723 | return strcmp(ctx->qry.page, page) ? NULL : "active"; |
710 | } | 724 | } |
711 | 725 | ||
712 | static void cgit_print_path_crumbs(struct cgit_context *ctx, char *path) | 726 | static void cgit_print_path_crumbs(struct cgit_context *ctx, char *path) |
713 | { | 727 | { |
714 | char *old_path = ctx->qry.path; | 728 | char *old_path = ctx->qry.path; |
715 | char *p = path, *q, *end = path + strlen(path); | 729 | char *p = path, *q, *end = path + strlen(path); |
716 | 730 | ||
717 | ctx->qry.path = NULL; | 731 | ctx->qry.path = NULL; |
718 | cgit_self_link("root", NULL, NULL, ctx); | 732 | cgit_self_link("root", NULL, NULL, ctx); |
719 | ctx->qry.path = p = path; | 733 | ctx->qry.path = p = path; |
720 | while (p < end) { | 734 | while (p < end) { |
721 | if (!(q = strchr(p, '/'))) | 735 | if (!(q = strchr(p, '/'))) |
722 | q = end; | 736 | q = end; |
723 | *q = '\0'; | 737 | *q = '\0'; |
724 | html_txt("/"); | 738 | html_txt("/"); |
725 | cgit_self_link(p, NULL, NULL, ctx); | 739 | cgit_self_link(p, NULL, NULL, ctx); |
726 | if (q < end) | 740 | if (q < end) |
727 | *q = '/'; | 741 | *q = '/'; |
728 | p = q + 1; | 742 | p = q + 1; |
729 | } | 743 | } |
730 | ctx->qry.path = old_path; | 744 | ctx->qry.path = old_path; |
731 | } | 745 | } |
732 | 746 | ||
733 | static void print_header(struct cgit_context *ctx) | 747 | static void print_header(struct cgit_context *ctx) |
734 | { | 748 | { |
735 | html("<table id='header'>\n"); | 749 | html("<table id='header'>\n"); |
736 | html("<tr>\n"); | 750 | html("<tr>\n"); |
737 | 751 | ||
738 | if (ctx->cfg.logo && ctx->cfg.logo[0] != 0) { | 752 | if (ctx->cfg.logo && ctx->cfg.logo[0] != 0) { |
739 | html("<td class='logo' rowspan='2'><a href='"); | 753 | html("<td class='logo' rowspan='2'><a href='"); |
740 | if (ctx->cfg.logo_link) | 754 | if (ctx->cfg.logo_link) |
741 | html_attr(ctx->cfg.logo_link); | 755 | html_attr(ctx->cfg.logo_link); |
742 | else | 756 | else |
743 | html_attr(cgit_rooturl()); | 757 | html_attr(cgit_rooturl()); |
744 | html("'><img src='"); | 758 | html("'><img src='"); |
745 | html_attr(ctx->cfg.logo); | 759 | html_attr(ctx->cfg.logo); |
746 | html("' alt='cgit logo'/></a></td>\n"); | 760 | html("' alt='cgit logo'/></a></td>\n"); |
747 | } | 761 | } |
748 | 762 | ||
749 | html("<td class='main'>"); | 763 | html("<td class='main'>"); |
750 | if (ctx->repo) { | 764 | if (ctx->repo) { |
751 | cgit_index_link("index", NULL, NULL, NULL, 0); | 765 | cgit_index_link("index", NULL, NULL, NULL, 0); |
752 | html(" : "); | 766 | html(" : "); |
753 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); | 767 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); |
754 | html("</td><td class='form'>"); | 768 | html("</td><td class='form'>"); |
755 | html("<form method='get' action=''>\n"); | 769 | html("<form method='get' action=''>\n"); |
756 | cgit_add_hidden_formfields(0, 1, ctx->qry.page); | 770 | cgit_add_hidden_formfields(0, 1, ctx->qry.page); |
757 | html("<select name='h' onchange='this.form.submit();'>\n"); | 771 | html("<select name='h' onchange='this.form.submit();'>\n"); |
758 | for_each_branch_ref(print_branch_option, ctx->qry.head); | 772 | for_each_branch_ref(print_branch_option, ctx->qry.head); |
759 | html("</select> "); | 773 | html("</select> "); |
760 | html("<input type='submit' name='' value='switch'/>"); | 774 | html("<input type='submit' name='' value='switch'/>"); |
761 | html("</form>"); | 775 | html("</form>"); |
762 | } else | 776 | } else |
763 | html_txt(ctx->cfg.root_title); | 777 | html_txt(ctx->cfg.root_title); |
764 | html("</td></tr>\n"); | 778 | html("</td></tr>\n"); |
765 | 779 | ||
766 | html("<tr><td class='sub'>"); | 780 | html("<tr><td class='sub'>"); |
767 | if (ctx->repo) { | 781 | if (ctx->repo) { |
768 | html_txt(ctx->repo->desc); | 782 | html_txt(ctx->repo->desc); |
769 | html("</td><td class='sub right'>"); | 783 | html("</td><td class='sub right'>"); |
770 | html_txt(ctx->repo->owner); | 784 | html_txt(ctx->repo->owner); |
771 | } else { | 785 | } else { |
772 | if (ctx->cfg.root_desc) | 786 | if (ctx->cfg.root_desc) |
773 | html_txt(ctx->cfg.root_desc); | 787 | html_txt(ctx->cfg.root_desc); |
774 | else if (ctx->cfg.index_info) | 788 | else if (ctx->cfg.index_info) |
775 | html_include(ctx->cfg.index_info); | 789 | html_include(ctx->cfg.index_info); |
776 | } | 790 | } |
777 | html("</td></tr></table>\n"); | 791 | html("</td></tr></table>\n"); |
778 | } | 792 | } |
779 | 793 | ||
780 | void cgit_print_pageheader(struct cgit_context *ctx) | 794 | void cgit_print_pageheader(struct cgit_context *ctx) |
781 | { | 795 | { |
782 | html("<div id='cgit'>"); | 796 | html("<div id='cgit'>"); |
783 | if (!ctx->cfg.noheader) | 797 | if (!ctx->cfg.noheader) |
784 | print_header(ctx); | 798 | print_header(ctx); |
785 | 799 | ||
786 | html("<table class='tabs'><tr><td>\n"); | 800 | html("<table class='tabs'><tr><td>\n"); |
787 | if (ctx->repo) { | 801 | if (ctx->repo) { |
788 | cgit_summary_link("summary", NULL, hc(ctx, "summary"), | 802 | cgit_summary_link("summary", NULL, hc(ctx, "summary"), |
789 | ctx->qry.head); | 803 | ctx->qry.head); |
790 | cgit_refs_link("refs", NULL, hc(ctx, "refs"), ctx->qry.head, | 804 | cgit_refs_link("refs", NULL, hc(ctx, "refs"), ctx->qry.head, |
791 | ctx->qry.sha1, NULL); | 805 | ctx->qry.sha1, NULL); |
792 | cgit_log_link("log", NULL, hc(ctx, "log"), ctx->qry.head, | 806 | cgit_log_link("log", NULL, hc(ctx, "log"), ctx->qry.head, |
793 | NULL, ctx->qry.vpath, 0, NULL, NULL, | 807 | NULL, ctx->qry.vpath, 0, NULL, NULL, |
794 | ctx->qry.showmsg); | 808 | ctx->qry.showmsg); |
795 | cgit_tree_link("tree", NULL, hc(ctx, "tree"), ctx->qry.head, | 809 | cgit_tree_link("tree", NULL, hc(ctx, "tree"), ctx->qry.head, |
796 | ctx->qry.sha1, ctx->qry.vpath); | 810 | ctx->qry.sha1, ctx->qry.vpath); |
797 | cgit_commit_link("commit", NULL, hc(ctx, "commit"), | 811 | cgit_commit_link("commit", NULL, hc(ctx, "commit"), |
798 | ctx->qry.head, ctx->qry.sha1, ctx->qry.vpath, 0); | 812 | ctx->qry.head, ctx->qry.sha1, ctx->qry.vpath, 0); |
799 | cgit_diff_link("diff", NULL, hc(ctx, "diff"), ctx->qry.head, | 813 | cgit_diff_link("diff", NULL, hc(ctx, "diff"), ctx->qry.head, |
800 | ctx->qry.sha1, ctx->qry.sha2, ctx->qry.vpath, 0); | 814 | ctx->qry.sha1, ctx->qry.sha2, ctx->qry.vpath, 0); |
801 | if (ctx->repo->max_stats) | 815 | if (ctx->repo->max_stats) |
802 | cgit_stats_link("stats", NULL, hc(ctx, "stats"), | 816 | cgit_stats_link("stats", NULL, hc(ctx, "stats"), |
803 | ctx->qry.head, ctx->qry.vpath); | 817 | ctx->qry.head, ctx->qry.vpath); |
804 | if (ctx->repo->readme) | 818 | if (ctx->repo->readme) |
805 | reporevlink("about", "about", NULL, | 819 | reporevlink("about", "about", NULL, |
806 | hc(ctx, "about"), ctx->qry.head, NULL, | 820 | hc(ctx, "about"), ctx->qry.head, NULL, |
807 | NULL); | 821 | NULL); |
808 | html("</td><td class='form'>"); | 822 | html("</td><td class='form'>"); |
809 | html("<form class='right' method='get' action='"); | 823 | html("<form class='right' method='get' action='"); |
810 | if (ctx->cfg.virtual_root) | 824 | if (ctx->cfg.virtual_root) |
811 | html_url_path(cgit_fileurl(ctx->qry.repo, "log", | 825 | html_url_path(cgit_fileurl(ctx->qry.repo, "log", |
812 | ctx->qry.vpath, NULL)); | 826 | ctx->qry.vpath, NULL)); |
813 | html("'>\n"); | 827 | html("'>\n"); |
814 | cgit_add_hidden_formfields(1, 0, "log"); | 828 | cgit_add_hidden_formfields(1, 0, "log"); |
815 | html("<select name='qt'>\n"); | 829 | html("<select name='qt'>\n"); |
816 | html_option("grep", "log msg", ctx->qry.grep); | 830 | html_option("grep", "log msg", ctx->qry.grep); |
817 | html_option("author", "author", ctx->qry.grep); | 831 | html_option("author", "author", ctx->qry.grep); |
818 | html_option("committer", "committer", ctx->qry.grep); | 832 | html_option("committer", "committer", ctx->qry.grep); |
819 | html("</select>\n"); | 833 | html("</select>\n"); |
820 | html("<input class='txt' type='text' size='10' name='q' value='"); | 834 | html("<input class='txt' type='text' size='10' name='q' value='"); |
821 | html_attr(ctx->qry.search); | 835 | html_attr(ctx->qry.search); |
822 | html("'/>\n"); | 836 | html("'/>\n"); |
823 | html("<input type='submit' value='search'/>\n"); | 837 | html("<input type='submit' value='search'/>\n"); |
824 | html("</form>\n"); | 838 | html("</form>\n"); |
825 | } else { | 839 | } else { |
826 | site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0); | 840 | site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0); |
827 | if (ctx->cfg.root_readme) | 841 | if (ctx->cfg.root_readme) |
828 | site_link("about", "about", NULL, hc(ctx, "about"), | 842 | site_link("about", "about", NULL, hc(ctx, "about"), |
829 | NULL, 0); | 843 | NULL, 0); |
830 | html("</td><td class='form'>"); | 844 | html("</td><td class='form'>"); |
831 | html("<form method='get' action='"); | 845 | html("<form method='get' action='"); |
832 | html_attr(cgit_rooturl()); | 846 | html_attr(cgit_rooturl()); |
833 | html("'>\n"); | 847 | html("'>\n"); |
834 | html("<input type='text' name='q' size='10' value='"); | 848 | html("<input type='text' name='q' size='10' value='"); |
835 | html_attr(ctx->qry.search); | 849 | html_attr(ctx->qry.search); |
836 | html("'/>\n"); | 850 | html("'/>\n"); |
837 | html("<input type='submit' value='search'/>\n"); | 851 | html("<input type='submit' value='search'/>\n"); |
838 | html("</form>"); | 852 | html("</form>"); |
839 | } | 853 | } |
840 | html("</td></tr></table>\n"); | 854 | html("</td></tr></table>\n"); |
841 | if (ctx->qry.vpath) { | 855 | if (ctx->qry.vpath) { |
842 | html("<div class='path'>"); | 856 | html("<div class='path'>"); |
843 | html("path: "); | 857 | html("path: "); |
844 | cgit_print_path_crumbs(ctx, ctx->qry.vpath); | 858 | cgit_print_path_crumbs(ctx, ctx->qry.vpath); |
845 | html("</div>"); | 859 | html("</div>"); |
846 | } | 860 | } |
847 | html("<div class='content'>"); | 861 | html("<div class='content'>"); |
848 | } | 862 | } |
849 | 863 | ||
850 | void cgit_print_filemode(unsigned short mode) | 864 | void cgit_print_filemode(unsigned short mode) |
851 | { | 865 | { |
852 | if (S_ISDIR(mode)) | 866 | if (S_ISDIR(mode)) |
853 | html("d"); | 867 | html("d"); |
854 | else if (S_ISLNK(mode)) | 868 | else if (S_ISLNK(mode)) |
855 | html("l"); | 869 | html("l"); |
856 | else if (S_ISGITLINK(mode)) | 870 | else if (S_ISGITLINK(mode)) |
857 | html("m"); | 871 | html("m"); |
858 | else | 872 | else |
859 | html("-"); | 873 | html("-"); |
860 | html_fileperm(mode >> 6); | 874 | html_fileperm(mode >> 6); |
861 | html_fileperm(mode >> 3); | 875 | html_fileperm(mode >> 3); |
862 | html_fileperm(mode); | 876 | html_fileperm(mode); |
863 | } | 877 | } |
864 | 878 | ||
865 | void cgit_print_snapshot_links(const char *repo, const char *head, | 879 | void cgit_print_snapshot_links(const char *repo, const char *head, |
866 | const char *hex, int snapshots) | 880 | const char *hex, int snapshots) |
867 | { | 881 | { |
868 | const struct cgit_snapshot_format* f; | 882 | const struct cgit_snapshot_format* f; |
869 | char *prefix; | 883 | char *prefix; |
870 | char *filename; | 884 | char *filename; |
871 | unsigned char sha1[20]; | 885 | unsigned char sha1[20]; |
872 | 886 | ||
873 | if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 && | 887 | if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 && |
874 | (hex[0] == 'v' || hex[0] == 'V') && isdigit(hex[1])) | 888 | (hex[0] == 'v' || hex[0] == 'V') && isdigit(hex[1])) |
875 | hex++; | 889 | hex++; |
876 | prefix = xstrdup(fmt("%s-%s", cgit_repobasename(repo), hex)); | 890 | prefix = xstrdup(fmt("%s-%s", cgit_repobasename(repo), hex)); |
877 | for (f = cgit_snapshot_formats; f->suffix; f++) { | 891 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
878 | if (!(snapshots & f->bit)) | 892 | if (!(snapshots & f->bit)) |
879 | continue; | 893 | continue; |
880 | filename = fmt("%s%s", prefix, f->suffix); | 894 | filename = fmt("%s%s", prefix, f->suffix); |
881 | cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); | 895 | cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); |
882 | html("<br/>"); | 896 | html("<br/>"); |
883 | } | 897 | } |
884 | } | 898 | } |