diff.c: emit_diff_symbol learns DIFF_SYMBOL_NO_LF_EOF

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Stefan Beller 2017-06-29 17:06:52 -07:00 committed by Junio C Hamano
parent 68abc6f1c7
commit b9cbfde6b1

19
diff.c
View File

@ -561,6 +561,7 @@ static void emit_line(struct diff_options *o, const char *set, const char *reset
} }
enum diff_symbol { enum diff_symbol {
DIFF_SYMBOL_NO_LF_EOF,
DIFF_SYMBOL_CONTEXT_FRAGINFO, DIFF_SYMBOL_CONTEXT_FRAGINFO,
DIFF_SYMBOL_CONTEXT_MARKER, DIFF_SYMBOL_CONTEXT_MARKER,
DIFF_SYMBOL_SEPARATOR DIFF_SYMBOL_SEPARATOR
@ -569,8 +570,16 @@ enum diff_symbol {
static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s, static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
const char *line, int len) const char *line, int len)
{ {
static const char *nneof = " No newline at end of file\n";
const char *context, *reset; const char *context, *reset;
switch (s) { switch (s) {
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;
case DIFF_SYMBOL_CONTEXT_FRAGINFO: case DIFF_SYMBOL_CONTEXT_FRAGINFO:
emit_line(o, "", "", line, len); emit_line(o, "", "", line, len);
break; break;
@ -751,7 +760,6 @@ static void emit_rewrite_lines(struct emit_callback *ecb,
int prefix, const char *data, int size) int prefix, const char *data, int size)
{ {
const char *endp = NULL; 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); const char *reset = diff_get_color(ecb->color_diff, DIFF_RESET);
while (0 < size) { while (0 < size) {
@ -769,13 +777,8 @@ static void emit_rewrite_lines(struct emit_callback *ecb,
size -= len; size -= len;
data += len; data += len;
} }
if (!endp) { if (!endp)
const char *context = diff_get_color(ecb->color_diff, emit_diff_symbol(ecb->opt, DIFF_SYMBOL_NO_LF_EOF, NULL, 0);
DIFF_CONTEXT);
putc('\n', ecb->opt->file);
emit_line_0(ecb->opt, context, reset, '\\',
nneof, strlen(nneof));
}
} }
static void emit_rewrite_diff(const char *name_a, static void emit_rewrite_diff(const char *name_a,