[PATCH 16/18] branch-diff --dual-color: work around bogus white-space warning
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- May 3, 2018, 15:31 UTC
- Message-ID
- <62f0e2cf73fb392114e0ded73af79b7dfa9ab66f.1525361419.git.johannes.schindelin@gmx.de>
- In-Reply-To
- <cover.1525361419.git.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 `branch-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 98a41e88620..b98a18fe014 100644 --- a/diff.c +++ b/diff.c @@ -1098,6 +1098,12 @@ static void emit_diff_symbol_from_struct(struct diff_options *o, set = diff_get_color_opt(o, DIFF_FILE_OLD); 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,
-- 2.17.0.395.g6a618d6010f.dirty