Skip to content

Commit dfa7b1e

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 02e13c0 commit dfa7b1e

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
@@ -1093,6 +1093,12 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
10931093
set = diff_get_color_opt(o, DIFF_FRAGINFO);
10941094
else if (c != '+')
10951095
set = diff_get_color_opt(o, DIFF_CONTEXT);
1096+
/* Avoid space-before-tab warning */
1097+
if (c == ' ' && (len < 2 || line[1] == '\t' ||
1098+
line[1] == '\r' || line[1] == '\n')) {
1099+
line++;
1100+
len--;
1101+
}
10961102
}
10971103
emit_line_ws_markup(o, set, reset, line, len, set_sign, '+',
10981104
flags & DIFF_SYMBOL_CONTENT_WS_MASK,

0 commit comments

Comments
 (0)