aboutsummaryrefslogtreecommitdiffstats
path: root/diff.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-11-05 13:30:45 -0800
committerJunio C Hamano <gitster@pobox.com>2025-11-05 13:37:19 -0800
commit7bcd6efba82874cae3be035320108a77b68192f7 (patch)
treebd1ebf241758e13c1175fb3ab33eb3ba8bb262ce /diff.c
parentdiff: fix incorrect counting of line numbers (diff)
downloadgit-7bcd6efba82874cae3be035320108a77b68192f7.tar.gz
git-7bcd6efba82874cae3be035320108a77b68192f7.zip
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 complete rewrite patch. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
-rw-r--r--diff.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/diff.c b/diff.c
index e73320dfb1..d388d318e4 100644
--- a/diff.c
+++ b/diff.c
@@ -1379,6 +1379,10 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
emit_line(o, "", "", line, len);
break;
case DIFF_SYMBOL_CONTEXT_INCOMPLETE:
+ set = diff_get_color_opt(o, DIFF_CONTEXT);
+ reset = diff_get_color_opt(o, DIFF_RESET);
+ emit_line(o, set, reset, line, len);
+ break;
case DIFF_SYMBOL_CONTEXT_MARKER:
context = diff_get_color_opt(o, DIFF_CONTEXT);
reset = diff_get_color_opt(o, DIFF_RESET);
@@ -1668,6 +1672,13 @@ static void emit_context_line(struct emit_callback *ecbdata,
emit_diff_symbol(ecbdata->opt, DIFF_SYMBOL_CONTEXT, line, len, flags);
}
+static void emit_incomplete_line(struct emit_callback *ecbdata,
+ const char *line, int len)
+{
+ emit_diff_symbol(ecbdata->opt, DIFF_SYMBOL_CONTEXT_INCOMPLETE,
+ line, len, 0);
+}
+
static void emit_hunk_header(struct emit_callback *ecbdata,
const char *line, int len)
{
@@ -2442,8 +2453,7 @@ static int fn_out_consume(void *priv, char *line, unsigned long len)
BUG("fn_out_consume: '\\No newline' after unknown line (%c)",
ecbdata->last_line_kind);
}
- emit_diff_symbol(o, DIFF_SYMBOL_CONTEXT_INCOMPLETE,
- line, len, 0);
+ emit_incomplete_line(ecbdata, line, len);
break;
default:
BUG("fn_out_consume: unknown line '%s'", line);