summaryrefslogtreecommitdiffabout
authorJohan Herland <johan@herland.net>2010-06-10 18:15:51 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2010-06-19 11:00:07 (UTC)
commitd20313e3daf855ee5d4808e050f54614c200d7b1 (patch) (unidiff)
tree5c462f3ba6ec97c0b099a309dfd0fa87d03fbc72
parent6180e6169d6e87a3bea7e4da835dca17f93e5cfd (diff)
downloadcgit-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>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ui-diff.c10
-rw-r--r--ui-shared.c14
2 files changed, 23 insertions, 1 deletions
diff --git a/ui-diff.c b/ui-diff.c
index d3a3b2c..e0a72f7 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -147,31 +147,39 @@ static void inspect_filepair(struct diff_filepair *pair)
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
156void cgit_print_diffstat(const unsigned char *old_sha1, 156void 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}
diff --git a/ui-shared.c b/ui-shared.c
index e991799..c99bcec 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -332,24 +332,31 @@ void cgit_commit_link(char *name, const char *title, const char *class,
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 = "&amp;"; 339 delim = "&amp;";
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 = "&amp;";
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 = "&amp;";
344 } 351 }
345 html("'>"); 352 html("'>");
346 html_txt(name); 353 html_txt(name);
347 html("</a>"); 354 html("</a>");
348} 355}
349 356
350void cgit_refs_link(const char *name, const char *title, const char *class, 357void 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
@@ -373,24 +380,31 @@ void cgit_diff_link(const char *name, const char *title, const char *class,
373 html_url_arg(new_rev); 380 html_url_arg(new_rev);
374 delim = "&amp;"; 381 delim = "&amp;";
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 = "&amp;"; 387 delim = "&amp;";
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 = "&amp;";
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 = "&amp;";
385 } 399 }
386 html("'>"); 400 html("'>");
387 html_txt(name); 401 html_txt(name);
388 html("</a>"); 402 html("</a>");
389} 403}
390 404
391void cgit_patch_link(const char *name, const char *title, const char *class, 405void 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