[PATCH v3 16/20] range-diff --dual-color: work around bogus white-space warning
- From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
- Date
- May 3, 2018, 01:11 UTC
- Message-ID
- <dfa7b1e71f7a39dfa608e1e205579d3b95d8a34f.1530617166.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.1.v3.git.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
When displaying a diff of diffs, it is possible that there is an outer `+` before a context line. That happens when the context changed between old and new commit. When that context line starts with a tab (after the space that marks it as context line), our diff machinery spits out a white-space error (space before tab), but in this case, that is incorrect.
Work around this by detecting that situation and simply *not* printing the space in that case.
This is slightly improper a fix because it is conceivable that an output_prefix might be configured with *just* the right length to let that tab jump to a different tab stop depending whether we emit that space or not.
However, the proper fix would be relatively ugly and intrusive because it would have to *weaken* the WS_SPACE_BEFORE_TAB option in ws.c. Besides, we do not expose the --dual-color option in cases other than the `git range-diff` command, which only uses a hard-coded output_prefix of four spaces (which misses the problem by one column... ;-)).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> --- diff.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/diff.c b/diff.c index 26445ffa1..325007167 100644 --- a/diff.c +++ b/diff.c @@ -1093,6 +1093,12 @@ static void emit_diff_symbol_from_struct(struct diff_options *o, set = diff_get_color_opt(o, DIFF_FRAGINFO); else if (c != '+') set = diff_get_color_opt(o, DIFF_CONTEXT); + /* Avoid space-before-tab warning */ + if (c == ' ' && (len < 2 || line[1] == '\t' || + line[1] == '\r' || line[1] == '\n')) { + line++; + len--; + } } emit_line_ws_markup(o, set, reset, line, len, set_sign, '+', flags & DIFF_SYMBOL_CONTENT_WS_MASK,
-- gitgitgadget