Signed-off-by: Stefan Beller <[email protected]>
---
diff.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/diff.c b/diff.c
index a1804a7785..28be3226c2 100644
--- a/diff.c
+++ b/diff.c
@@ -563,11 +563,13 @@ enum diff_symbol {
DIFF_SYMBOL_SEPARATOR,
DIFF_SYMBOL_CONTEXT_MARKER,
DIFF_SYMBOL_CONTEXT_FRAGINFO,
+ DIFF_SYMBOL_NO_LF_EOF,
};
static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
const char *line, int len)
{
+ static const char *nneof = " No newline at end of file\n";
const char *context, *reset;
switch (s) {
case DIFF_SYMBOL_SEPARATOR:
@@ -583,6 +585,13 @@ static void emit_diff_symbol(struct diff_options *o, enum
diff_symbol s,
case DIFF_SYMBOL_CONTEXT_FRAGINFO:
emit_line(o, "", "", line, len);
break;
+ case DIFF_SYMBOL_NO_LF_EOF:
+ context = diff_get_color_opt(o, DIFF_CONTEXT);
+ reset = diff_get_color_opt(o, DIFF_RESET);
+ putc('\n', o->file);
+ emit_line_0(o, context, reset, '\\',
+ nneof, strlen(nneof));
+ break;
default:
die("BUG: unknown diff symbol");
}
@@ -750,7 +759,6 @@ static void emit_rewrite_lines(struct emit_callback *ecb,
int prefix, const char *data, int size)
{
const char *endp = NULL;
- static const char *nneof = " No newline at end of file\n";
const char *reset = diff_get_color(ecb->color_diff, DIFF_RESET);
while (0 < size) {
@@ -768,13 +776,8 @@ static void emit_rewrite_lines(struct emit_callback *ecb,
size -= len;
data += len;
}
- if (!endp) {
- const char *context = diff_get_color(ecb->color_diff,
- DIFF_CONTEXT);
- putc('\n', ecb->opt->file);
- emit_line_0(ecb->opt, context, reset, '\\',
- nneof, strlen(nneof));
- }
+ if (!endp)
+ emit_diff_symbol(ecb->opt, DIFF_SYMBOL_NO_LF_EOF, NULL, 0);
}
static void emit_rewrite_diff(const char *name_a,
--
2.12.2.575.gb14f27f917