From 2cc8b99f083014c58d8937bfa4dcd2bc47cd7e58 Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Thu, 24 Jun 2010 17:52:57 +0200 Subject: Add URL parameter 'ignorews' for optionally ignoring whitespace in diffs The new ctx.qry.ignorews variable is passed via cgit_diff_files() and cgit_diff_tree() to Git's diff machinery. This is equivalent to passing --ignore-all-space to 'git diff'. Signed-off-by: Johan Herland --- ui-diff.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'ui-diff.c') diff --git a/ui-diff.c b/ui-diff.c index e0a72f7..1656b77 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -127,7 +127,7 @@ static void inspect_filepair(struct diff_filepair *pair) lines_added = 0; lines_removed = 0; cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size, - &binary, 0, count_diff_lines); + &binary, 0, ctx.qry.ignorews, count_diff_lines); if (files >= slots) { if (slots == 0) slots = 4; @@ -174,7 +174,8 @@ void cgit_print_diffstat(const unsigned char *old_sha1, html(""); html(""); max_changes = 0; - cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix); + cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, prefix, + ctx.qry.ignorews); for(i = 0; i"); @@ -296,7 +297,8 @@ static void filepair_cb(struct diff_filepair *pair) return; } if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, - &new_size, &binary, ctx.qry.context, print_line_fn)) + &new_size, &binary, ctx.qry.context, + ctx.qry.ignorews, print_line_fn)) cgit_print_error("Error running diff"); if (binary) { if (use_ssdiff) @@ -356,7 +358,8 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi html("
"); html(""); html("
"); } - cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); + cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix, + ctx.qry.ignorews); if (!use_ssdiff) html("
"); -- cgit v1.2.3-59-g8ed1b From 72ef913514288bd2aae23509581097bfd3edf8c4 Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Thu, 24 Jun 2010 17:53:20 +0200 Subject: 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 --- ui-diff.c | 5 +++++ ui-shared.c | 10 ++++++++++ 2 files changed, 15 insertions(+) (limited to 'ui-diff.c') diff --git a/ui-diff.c b/ui-diff.c index 1656b77..0dcabe9 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -171,6 +171,11 @@ void cgit_print_diffstat(const unsigned char *old_sha1, cgit_self_link("less", NULL, NULL, &ctx); ctx.qry.context = save_context; html(" context)"); + html(" ("); + ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2; + cgit_self_link(ctx.qry.ignorews ? "ignore" : "show", NULL, NULL, &ctx); + ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2; + html(" whitespace changes)"); html(""); html(""); max_changes = 0; diff --git a/ui-shared.c b/ui-shared.c index c99bcec..f46c935 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -349,6 +349,11 @@ void cgit_commit_link(char *name, const char *title, const char *class, htmlf("%d", ctx.qry.context); delim = "&"; } + if (ctx.qry.ignorews) { + html(delim); + html("ignorews=1"); + delim = "&"; + } html("'>"); html_txt(name); html(""); @@ -397,6 +402,11 @@ void cgit_diff_link(const char *name, const char *title, const char *class, htmlf("%d", ctx.qry.context); delim = "&"; } + if (ctx.qry.ignorews) { + html(delim); + html("ignorews=1"); + delim = "&"; + } html("'>"); html_txt(name); html(""); -- cgit v1.2.3-59-g8ed1b