diff.c: emit_diff_symbol learns about DIFF_SYMBOL_BINARY_FILES

we could save a little bit of memory when buffering in a later mode
by just passing the inner part ("%s and %s", file1, file 2), but
those a just a few bytes, so instead let's reuse the implementation from
DIFF_SYMBOL_HEADER and keep the whole line around.

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:58 -07:00 committed by Junio C Hamano
parent a29b0a13bd
commit 4acaaa7af6

20
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_BINARY_FILES,
DIFF_SYMBOL_HEADER, DIFF_SYMBOL_HEADER,
DIFF_SYMBOL_FILEPAIR_PLUS, DIFF_SYMBOL_FILEPAIR_PLUS,
DIFF_SYMBOL_FILEPAIR_MINUS, DIFF_SYMBOL_FILEPAIR_MINUS,
@ -690,6 +691,7 @@ static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
line, reset, line, reset,
strchr(line, ' ') ? "\t" : ""); strchr(line, ' ') ? "\t" : "");
break; break;
case DIFF_SYMBOL_BINARY_FILES:
case DIFF_SYMBOL_HEADER: case DIFF_SYMBOL_HEADER:
fprintf(o->file, "%s", line); fprintf(o->file, "%s", line);
break; break;
@ -2542,6 +2544,7 @@ static void builtin_diff(const char *name_a,
} else if (!DIFF_OPT_TST(o, TEXT) && } else if (!DIFF_OPT_TST(o, TEXT) &&
( (!textconv_one && diff_filespec_is_binary(one)) || ( (!textconv_one && diff_filespec_is_binary(one)) ||
(!textconv_two && diff_filespec_is_binary(two)) )) { (!textconv_two && diff_filespec_is_binary(two)) )) {
struct strbuf sb = STRBUF_INIT;
if (!one->data && !two->data && if (!one->data && !two->data &&
S_ISREG(one->mode) && S_ISREG(two->mode) && S_ISREG(one->mode) && S_ISREG(two->mode) &&
!DIFF_OPT_TST(o, BINARY)) { !DIFF_OPT_TST(o, BINARY)) {
@ -2554,8 +2557,11 @@ static void builtin_diff(const char *name_a,
} }
emit_diff_symbol(o, DIFF_SYMBOL_HEADER, emit_diff_symbol(o, DIFF_SYMBOL_HEADER,
header.buf, header.len, 0); header.buf, header.len, 0);
fprintf(o->file, "%sBinary files %s and %s differ\n", strbuf_addf(&sb, "%sBinary files %s and %s differ\n",
line_prefix, lbl[0], lbl[1]); diff_line_prefix(o), lbl[0], lbl[1]);
emit_diff_symbol(o, DIFF_SYMBOL_BINARY_FILES,
sb.buf, sb.len, 0);
strbuf_release(&sb);
goto free_ab_and_return; goto free_ab_and_return;
} }
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0) if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
@ -2572,9 +2578,13 @@ static void builtin_diff(const char *name_a,
strbuf_reset(&header); strbuf_reset(&header);
if (DIFF_OPT_TST(o, BINARY)) if (DIFF_OPT_TST(o, BINARY))
emit_binary_diff(o->file, &mf1, &mf2, line_prefix); emit_binary_diff(o->file, &mf1, &mf2, line_prefix);
else else {
fprintf(o->file, "%sBinary files %s and %s differ\n", strbuf_addf(&sb, "%sBinary files %s and %s differ\n",
line_prefix, lbl[0], lbl[1]); diff_line_prefix(o), lbl[0], lbl[1]);
emit_diff_symbol(o, DIFF_SYMBOL_BINARY_FILES,
sb.buf, sb.len, 0);
strbuf_release(&sb);
}
o->found_changes = 1; o->found_changes = 1;
} else { } else {
/* Crazy xdl interfaces.. */ /* Crazy xdl interfaces.. */