Skip to content

Commit 29228cb

Browse files
committed
diff: refactor output of incomplete line
Create a helper function that reacts to "\ No newline at the end of file" in preparation for unifying the incomplete line handling in the code path that handles xdiff output and the code path that bypasses xdiff and produces a complete-rewrite patch. Currently the output from the DIFF_SYMBOL_CONTEXT_INCOMPLETE case still (ab)uses the same code as what is used for context lines, but that would change in a later step where we introduce support to treat an incomplete line as a whitespace error. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ced0561 commit 29228cb

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

diff.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,10 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
13791379
emit_line(o, "", "", line, len);
13801380
break;
13811381
case DIFF_SYMBOL_CONTEXT_INCOMPLETE:
1382+
set = diff_get_color_opt(o, DIFF_CONTEXT);
1383+
reset = diff_get_color_opt(o, DIFF_RESET);
1384+
emit_line(o, set, reset, line, len);
1385+
break;
13821386
case DIFF_SYMBOL_CONTEXT_MARKER:
13831387
context = diff_get_color_opt(o, DIFF_CONTEXT);
13841388
reset = diff_get_color_opt(o, DIFF_RESET);
@@ -1668,6 +1672,13 @@ static void emit_context_line(struct emit_callback *ecbdata,
16681672
emit_diff_symbol(ecbdata->opt, DIFF_SYMBOL_CONTEXT, line, len, flags);
16691673
}
16701674

1675+
static void emit_incomplete_line_marker(struct emit_callback *ecbdata,
1676+
const char *line, int len)
1677+
{
1678+
emit_diff_symbol(ecbdata->opt, DIFF_SYMBOL_CONTEXT_INCOMPLETE,
1679+
line, len, 0);
1680+
}
1681+
16711682
static void emit_hunk_header(struct emit_callback *ecbdata,
16721683
const char *line, int len)
16731684
{
@@ -2437,8 +2448,7 @@ static int fn_out_consume(void *priv, char *line, unsigned long len)
24372448
ecbdata->last_line_kind);
24382449
}
24392450
ecbdata->lno_in_preimage++;
2440-
emit_diff_symbol(o, DIFF_SYMBOL_CONTEXT_INCOMPLETE,
2441-
line, len, 0);
2451+
emit_incomplete_line_marker(ecbdata, line, len);
24422452
break;
24432453
default:
24442454
BUG("fn_out_consume: unknown line '%s'", line);

0 commit comments

Comments
 (0)