summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-05-26 10:11:28 -0700
committerJunio C Hamano <gitster@pobox.com>2015-05-26 12:45:21 -0700
commita9872ab425f2f7890e208cf555ab439c7bc77f08 (patch)
treea7e3f6dbf45f7df3d31ac0db625dd1af0f70ddd2 /diff.c
parenta778e54498ca5e65c141bcdaff60f9a10b942dbf (diff)
downloadgit-jc/diff-ws-check-deleted.tar.gz
diff.c: --ws-check-deleted optionjc/diff-ws-check-deleted
Traditionally, we only cared about whitespace breakages introduced in new lines. Some people want to paint whitespace breakages on old lines, too. When they see a whitespace breakage on a new line, they can spot the same kind of whitespace breakage on the corresponding old line and want to say "Ah, those breakages are there but they were inherited from the original, so let's not touch them for now." Enable such use case with the new option, "--ws-check-deleted". Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/diff.c b/diff.c
index 75b134291a..30eeaea06a 100644
--- a/diff.c
+++ b/diff.c
@@ -503,8 +503,22 @@ static void emit_del_line(const char *reset,
const char *line, int len)
{
const char *set = diff_get_color(ecbdata->color_diff, DIFF_FILE_OLD);
+ const char *ws = NULL;
- emit_line_0(ecbdata->opt, set, reset, '-', line, len);
+ if (ecbdata->opt->ws_check_deleted) {
+ ws = diff_get_color(ecbdata->color_diff, DIFF_WHITESPACE);
+ if (!*ws)
+ ws = NULL;
+ }
+
+ if (!ws)
+ emit_line_0(ecbdata->opt, set, reset, '-', line, len);
+ else {
+ /* Emit just the prefix, then the rest. */
+ emit_line_0(ecbdata->opt, set, reset, '-', "", 0);
+ ws_check_emit(line, len, ecbdata->ws_rule,
+ ecbdata->opt->file, set, reset, ws);
+ }
}
static void emit_hunk_header(struct emit_callback *ecbdata,
@@ -3823,6 +3837,11 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
else if (skip_prefix(arg, "--submodule=", &arg))
return parse_submodule_opt(options, arg);
+ else if (!strcmp(arg, "--ws-check-deleted"))
+ options->ws_check_deleted = 1;
+ else if (!strcmp(arg, "--no-ws-check-deleted"))
+ options->ws_check_deleted = 0;
+
/* misc options */
else if (!strcmp(arg, "-z"))
options->line_termination = 0;