author | Johan Herland <johan@herland.net> | 2010-06-24 15:53:20 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2010-07-18 08:54:02 (UTC) |
commit | 72ef913514288bd2aae23509581097bfd3edf8c4 (patch) (unidiff) | |
tree | 3a8b48aa0ebcc74a7e8b7f05f964432c6d577921 | |
parent | 2cc8b99f083014c58d8937bfa4dcd2bc47cd7e58 (diff) | |
download | cgit-72ef913514288bd2aae23509581097bfd3edf8c4.zip cgit-72ef913514288bd2aae23509581097bfd3edf8c4.tar.gz cgit-72ef913514288bd2aae23509581097bfd3edf8c4.tar.bz2 |
ui-diff: Add link to ignore/show whitespace changes in diffs
Add a link to the "Diffstat" line to ignore/show whitespace changes in the
generated diff.
To support this, cgit_commit_link() and cgit_diff_link() has learned to
preserve the ctx.qry.ignorews variable.
Signed-off-by: Johan Herland <johan@herland.net>
-rw-r--r-- | ui-diff.c | 5 | ||||
-rw-r--r-- | ui-shared.c | 10 |
2 files changed, 15 insertions, 0 deletions
@@ -126,96 +126,101 @@ static void inspect_filepair(struct diff_filepair *pair) | |||
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, ctx.qry.ignorews, count_diff_lines); | 130 | &binary, 0, ctx.qry.ignorews, 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, save_context = ctx.qry.context; | 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(" ("); | 166 | html(" ("); |
167 | ctx.qry.context = (save_context > 0 ? save_context : 3) << 1; | 167 | ctx.qry.context = (save_context > 0 ? save_context : 3) << 1; |
168 | cgit_self_link("more", NULL, NULL, &ctx); | 168 | cgit_self_link("more", NULL, NULL, &ctx); |
169 | html("/"); | 169 | html("/"); |
170 | ctx.qry.context = (save_context > 3 ? save_context : 3) >> 1; | 170 | ctx.qry.context = (save_context > 3 ? save_context : 3) >> 1; |
171 | cgit_self_link("less", NULL, NULL, &ctx); | 171 | cgit_self_link("less", NULL, NULL, &ctx); |
172 | ctx.qry.context = save_context; | 172 | ctx.qry.context = save_context; |
173 | html(" context)"); | 173 | html(" context)"); |
174 | html(" ("); | ||
175 | ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2; | ||
176 | cgit_self_link(ctx.qry.ignorews ? "ignore" : "show", NULL, NULL, &ctx); | ||
177 | ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2; | ||
178 | html(" whitespace changes)"); | ||
174 | html("</div>"); | 179 | html("</div>"); |
175 | html("<table summary='diffstat' class='diffstat'>"); | 180 | html("<table summary='diffstat' class='diffstat'>"); |
176 | max_changes = 0; | 181 | max_changes = 0; |
177 | cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix, | 182 | cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix, |
178 | ctx.qry.ignorews); | 183 | ctx.qry.ignorews); |
179 | for(i = 0; i<files; i++) | 184 | for(i = 0; i<files; i++) |
180 | print_fileinfo(&items[i]); | 185 | print_fileinfo(&items[i]); |
181 | html("</table>"); | 186 | html("</table>"); |
182 | html("<div class='diffstat-summary'>"); | 187 | html("<div class='diffstat-summary'>"); |
183 | htmlf("%d files changed, %d insertions, %d deletions", | 188 | htmlf("%d files changed, %d insertions, %d deletions", |
184 | files, total_adds, total_rems); | 189 | files, total_adds, total_rems); |
185 | html("</div>"); | 190 | html("</div>"); |
186 | } | 191 | } |
187 | 192 | ||
188 | 193 | ||
189 | /* | 194 | /* |
190 | * print a single line returned from xdiff | 195 | * print a single line returned from xdiff |
191 | */ | 196 | */ |
192 | static void print_line(char *line, int len) | 197 | static void print_line(char *line, int len) |
193 | { | 198 | { |
194 | char *class = "ctx"; | 199 | char *class = "ctx"; |
195 | char c = line[len-1]; | 200 | char c = line[len-1]; |
196 | 201 | ||
197 | if (line[0] == '+') | 202 | if (line[0] == '+') |
198 | class = "add"; | 203 | class = "add"; |
199 | else if (line[0] == '-') | 204 | else if (line[0] == '-') |
200 | class = "del"; | 205 | class = "del"; |
201 | else if (line[0] == '@') | 206 | else if (line[0] == '@') |
202 | class = "hunk"; | 207 | class = "hunk"; |
203 | 208 | ||
204 | htmlf("<div class='%s'>", class); | 209 | htmlf("<div class='%s'>", class); |
205 | line[len-1] = '\0'; | 210 | line[len-1] = '\0'; |
206 | html_txt(line); | 211 | html_txt(line); |
207 | html("</div>"); | 212 | html("</div>"); |
208 | line[len-1] = c; | 213 | line[len-1] = c; |
209 | } | 214 | } |
210 | 215 | ||
211 | static void header(unsigned char *sha1, char *path1, int mode1, | 216 | static void header(unsigned char *sha1, char *path1, int mode1, |
212 | unsigned char *sha2, char *path2, int mode2) | 217 | unsigned char *sha2, char *path2, int mode2) |
213 | { | 218 | { |
214 | char *abbrev1, *abbrev2; | 219 | char *abbrev1, *abbrev2; |
215 | int subproject; | 220 | int subproject; |
216 | 221 | ||
217 | subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); | 222 | subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); |
218 | html("<div class='head'>"); | 223 | html("<div class='head'>"); |
219 | html("diff --git a/"); | 224 | html("diff --git a/"); |
220 | html_txt(path1); | 225 | html_txt(path1); |
221 | html(" b/"); | 226 | html(" b/"); |
diff --git a/ui-shared.c b/ui-shared.c index c99bcec..f46c935 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -304,144 +304,154 @@ void cgit_log_link(const char *name, const char *title, const char *class, | |||
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 = "&"; | 344 | delim = "&"; |
345 | } | 345 | } |
346 | if (ctx.qry.context > 0 && ctx.qry.context != 3) { | 346 | if (ctx.qry.context > 0 && ctx.qry.context != 3) { |
347 | html(delim); | 347 | html(delim); |
348 | html("context="); | 348 | html("context="); |
349 | htmlf("%d", ctx.qry.context); | 349 | htmlf("%d", ctx.qry.context); |
350 | delim = "&"; | 350 | delim = "&"; |
351 | } | 351 | } |
352 | if (ctx.qry.ignorews) { | ||
353 | html(delim); | ||
354 | html("ignorews=1"); | ||
355 | delim = "&"; | ||
356 | } | ||
352 | html("'>"); | 357 | html("'>"); |
353 | html_txt(name); | 358 | html_txt(name); |
354 | html("</a>"); | 359 | html("</a>"); |
355 | } | 360 | } |
356 | 361 | ||
357 | void cgit_refs_link(const char *name, const char *title, const char *class, | 362 | void cgit_refs_link(const char *name, const char *title, const char *class, |
358 | const char *head, const char *rev, const char *path) | 363 | const char *head, const char *rev, const char *path) |
359 | { | 364 | { |
360 | reporevlink("refs", name, title, class, head, rev, path); | 365 | reporevlink("refs", name, title, class, head, rev, path); |
361 | } | 366 | } |
362 | 367 | ||
363 | void cgit_snapshot_link(const char *name, const char *title, const char *class, | 368 | void cgit_snapshot_link(const char *name, const char *title, const char *class, |
364 | const char *head, const char *rev, | 369 | const char *head, const char *rev, |
365 | const char *archivename) | 370 | const char *archivename) |
366 | { | 371 | { |
367 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 372 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
368 | } | 373 | } |
369 | 374 | ||
370 | void cgit_diff_link(const char *name, const char *title, const char *class, | 375 | void cgit_diff_link(const char *name, const char *title, const char *class, |
371 | const char *head, const char *new_rev, const char *old_rev, | 376 | const char *head, const char *new_rev, const char *old_rev, |
372 | const char *path, int toggle_ssdiff) | 377 | const char *path, int toggle_ssdiff) |
373 | { | 378 | { |
374 | char *delim; | 379 | char *delim; |
375 | 380 | ||
376 | delim = repolink(title, class, "diff", head, path); | 381 | delim = repolink(title, class, "diff", head, path); |
377 | if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) { | 382 | if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) { |
378 | html(delim); | 383 | html(delim); |
379 | html("id="); | 384 | html("id="); |
380 | html_url_arg(new_rev); | 385 | html_url_arg(new_rev); |
381 | delim = "&"; | 386 | delim = "&"; |
382 | } | 387 | } |
383 | if (old_rev) { | 388 | if (old_rev) { |
384 | html(delim); | 389 | html(delim); |
385 | html("id2="); | 390 | html("id2="); |
386 | html_url_arg(old_rev); | 391 | html_url_arg(old_rev); |
387 | delim = "&"; | 392 | delim = "&"; |
388 | } | 393 | } |
389 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { | 394 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { |
390 | html(delim); | 395 | html(delim); |
391 | html("ss=1"); | 396 | html("ss=1"); |
392 | delim = "&"; | 397 | delim = "&"; |
393 | } | 398 | } |
394 | if (ctx.qry.context > 0 && ctx.qry.context != 3) { | 399 | if (ctx.qry.context > 0 && ctx.qry.context != 3) { |
395 | html(delim); | 400 | html(delim); |
396 | html("context="); | 401 | html("context="); |
397 | htmlf("%d", ctx.qry.context); | 402 | htmlf("%d", ctx.qry.context); |
398 | delim = "&"; | 403 | delim = "&"; |
399 | } | 404 | } |
405 | if (ctx.qry.ignorews) { | ||
406 | html(delim); | ||
407 | html("ignorews=1"); | ||
408 | delim = "&"; | ||
409 | } | ||
400 | html("'>"); | 410 | html("'>"); |
401 | html_txt(name); | 411 | html_txt(name); |
402 | html("</a>"); | 412 | html("</a>"); |
403 | } | 413 | } |
404 | 414 | ||
405 | void cgit_patch_link(const char *name, const char *title, const char *class, | 415 | void cgit_patch_link(const char *name, const char *title, const char *class, |
406 | const char *head, const char *rev, const char *path) | 416 | const char *head, const char *rev, const char *path) |
407 | { | 417 | { |
408 | reporevlink("patch", name, title, class, head, rev, path); | 418 | reporevlink("patch", name, title, class, head, rev, path); |
409 | } | 419 | } |
410 | 420 | ||
411 | void cgit_stats_link(const char *name, const char *title, const char *class, | 421 | void cgit_stats_link(const char *name, const char *title, const char *class, |
412 | const char *head, const char *path) | 422 | const char *head, const char *path) |
413 | { | 423 | { |
414 | reporevlink("stats", name, title, class, head, NULL, path); | 424 | reporevlink("stats", name, title, class, head, NULL, path); |
415 | } | 425 | } |
416 | 426 | ||
417 | void cgit_self_link(char *name, const char *title, const char *class, | 427 | void cgit_self_link(char *name, const char *title, const char *class, |
418 | struct cgit_context *ctx) | 428 | struct cgit_context *ctx) |
419 | { | 429 | { |
420 | if (!strcmp(ctx->qry.page, "repolist")) | 430 | if (!strcmp(ctx->qry.page, "repolist")) |
421 | return cgit_index_link(name, title, class, ctx->qry.search, | 431 | return cgit_index_link(name, title, class, ctx->qry.search, |
422 | ctx->qry.ofs); | 432 | ctx->qry.ofs); |
423 | else if (!strcmp(ctx->qry.page, "summary")) | 433 | else if (!strcmp(ctx->qry.page, "summary")) |
424 | return cgit_summary_link(name, title, class, ctx->qry.head); | 434 | return cgit_summary_link(name, title, class, ctx->qry.head); |
425 | else if (!strcmp(ctx->qry.page, "tag")) | 435 | else if (!strcmp(ctx->qry.page, "tag")) |
426 | return cgit_tag_link(name, title, class, ctx->qry.head, | 436 | return cgit_tag_link(name, title, class, ctx->qry.head, |
427 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL); | 437 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL); |
428 | else if (!strcmp(ctx->qry.page, "tree")) | 438 | else if (!strcmp(ctx->qry.page, "tree")) |
429 | return cgit_tree_link(name, title, class, ctx->qry.head, | 439 | return cgit_tree_link(name, title, class, ctx->qry.head, |
430 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 440 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
431 | ctx->qry.path); | 441 | ctx->qry.path); |
432 | else if (!strcmp(ctx->qry.page, "plain")) | 442 | else if (!strcmp(ctx->qry.page, "plain")) |
433 | return cgit_plain_link(name, title, class, ctx->qry.head, | 443 | return cgit_plain_link(name, title, class, ctx->qry.head, |
434 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 444 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
435 | ctx->qry.path); | 445 | ctx->qry.path); |
436 | else if (!strcmp(ctx->qry.page, "log")) | 446 | else if (!strcmp(ctx->qry.page, "log")) |
437 | return cgit_log_link(name, title, class, ctx->qry.head, | 447 | return cgit_log_link(name, title, class, ctx->qry.head, |
438 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 448 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
439 | ctx->qry.path, ctx->qry.ofs, | 449 | ctx->qry.path, ctx->qry.ofs, |
440 | ctx->qry.grep, ctx->qry.search, | 450 | ctx->qry.grep, ctx->qry.search, |
441 | ctx->qry.showmsg); | 451 | ctx->qry.showmsg); |
442 | else if (!strcmp(ctx->qry.page, "commit")) | 452 | else if (!strcmp(ctx->qry.page, "commit")) |
443 | return cgit_commit_link(name, title, class, ctx->qry.head, | 453 | return cgit_commit_link(name, title, class, ctx->qry.head, |
444 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | 454 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, |
445 | ctx->qry.path, 0); | 455 | ctx->qry.path, 0); |
446 | else if (!strcmp(ctx->qry.page, "patch")) | 456 | else if (!strcmp(ctx->qry.page, "patch")) |
447 | return cgit_patch_link(name, title, class, ctx->qry.head, | 457 | return cgit_patch_link(name, title, class, ctx->qry.head, |