Currently git-diff only highlights trailing whitespace in the new lines (prefixed with '+'), thus it is not visible in the deleted lines (prefixed with '-'). Therefore introduce a new configuration variable for the core.whitespace setting "blank-at-eol-old" (default off) that will highlight trailing whitespace in those lines as well. Signed-off-by: Christian Brabandt <cb@xxxxxxxxxx> --- Hi, please be gentle, this is the first time I contribute to the git development. Here is my use case: I have been working in a team repository, reformatting the source and wondered, why my reformatting did introduce some trailing whitespace. I suspected a bug in Vim and started to debug it, until I found out, that git-diff simply does not show trailing whitespace in the deleted lines. Therefore, I'd like to have an option, to also show trailing whitespace in the deleted lines of a diff. So here is the patch. As far as I can see, this does not break any tests and also the behaviour of git-diff --check does not change. Documentation/config.txt | 2 ++ cache.h | 1 + diff.c | 8 +++++++- ws.c | 8 ++++++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 0f668bb..f73f0f7 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -670,6 +670,8 @@ core.whitespace:: + * `blank-at-eol` treats trailing whitespaces at the end of the line as an error (enabled by default). +* `blank-at-eol-old` like `blank-at-eol`, but for the deleted lines + of a patch (i.e. those preceeded with a '-') (not enabled by default) * `space-before-tab` treats a space character that appears immediately before a tab character in the initial indent part of the line as an error (enabled by default). diff --git a/cache.h b/cache.h index 1f4226b..811b640 100644 --- a/cache.h +++ b/cache.h @@ -1618,6 +1618,7 @@ void shift_tree_by(const unsigned char *, const unsigned char *, unsigned char * #define WS_CR_AT_EOL 01000 #define WS_BLANK_AT_EOF 02000 #define WS_TAB_IN_INDENT 04000 +#define WS_BLANK_AT_EOL_OLD 010000 #define WS_TRAILING_SPACE (WS_BLANK_AT_EOL|WS_BLANK_AT_EOF) #define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB|8) #define WS_TAB_WIDTH_MASK 077 diff --git a/diff.c b/diff.c index 7500c55..4245956 100644 --- a/diff.c +++ b/diff.c @@ -1254,10 +1254,16 @@ static void fn_out_consume(void *priv, char *line, unsigned long len) const char *color = diff_get_color(ecbdata->color_diff, line[0] == '-' ? DIFF_FILE_OLD : DIFF_PLAIN); + const char *ws = diff_get_color(ecbdata->color_diff, DIFF_WHITESPACE); + ecbdata->lno_in_preimage++; if (line[0] == ' ') ecbdata->lno_in_postimage++; - emit_line(ecbdata->opt, color, reset, line, len); + if (*ws && ecbdata->ws_rule & WS_BLANK_AT_EOL_OLD) + ws_check_emit(line, len, ecbdata->ws_rule, + ecbdata->opt->file, color, reset, ws); + else + emit_line(ecbdata->opt, color, reset, line, len); } else { ecbdata->lno_in_postimage++; emit_add_line(reset, ecbdata, line + 1, len - 1); diff --git a/ws.c b/ws.c index ea4b2b1..09e04f0 100644 --- a/ws.c +++ b/ws.c @@ -18,6 +18,7 @@ static struct whitespace_rule { { "indent-with-non-tab", WS_INDENT_WITH_NON_TAB, 0 }, { "cr-at-eol", WS_CR_AT_EOL, 1 }, { "blank-at-eol", WS_BLANK_AT_EOL, 0 }, + { "blank-at-eol-del", WS_BLANK_AT_EOL_OLD, 0, 1 }, { "blank-at-eof", WS_BLANK_AT_EOF, 0 }, { "tab-in-indent", WS_TAB_IN_INDENT, 0, 1 }, }; @@ -170,11 +171,14 @@ static unsigned ws_check_emit_1(const char *line, int len, unsigned ws_rule, } /* Check for trailing whitespace. */ - if (ws_rule & WS_BLANK_AT_EOL) { + if ((ws_rule & WS_BLANK_AT_EOL) || (ws_rule & WS_BLANK_AT_EOL_OLD)) { for (i = len - 1; i >= 0; i--) { if (isspace(line[i])) { trailing_whitespace = i; - result |= WS_BLANK_AT_EOL; + if (ws_rule & WS_BLANK_AT_EOL) + result |= WS_BLANK_AT_EOL; + else + result |= WS_BLANK_AT_EOL_OLD; } else break; -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html