Skip to content

Commit 926ec7e

Browse files
committed
range-diff --dual-color: work around bogus white-space warning
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 <[email protected]>
1 parent b5de55d commit 926ec7e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

diff.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,12 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
11011101
set = diff_get_color_opt(o, DIFF_FRAGINFO);
11021102
else if (c != '+')
11031103
set = diff_get_color_opt(o, DIFF_CONTEXT);
1104+
/* Avoid space-before-tab warning */
1105+
if (c == ' ' && (len < 2 || line[1] == '\t' ||
1106+
line[1] == '\r' || line[1] == '\n')) {
1107+
line++;
1108+
len--;
1109+
}
11041110
}
11051111
emit_line_ws_markup(o, set, reset, line, len, set_sign, '+',
11061112
flags & DIFF_SYMBOL_CONTENT_WS_MASK,

0 commit comments

Comments
 (0)