summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Stefan Beller <sbeller@google.com>2017-06-29 17:06:58 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-06-30 13:13:01 -0700
commit4acaaa7af65a62db1f58861170d9d3918103c1b9 (patch)
tree75f5b4757ccba87491ea168d8961af87cb06b922
parentdiff.c: emit_diff_symbol learns DIFF_SYMBOL_HEADER (diff)
downloadtgif-4acaaa7af65a62db1f58861170d9d3918103c1b9.tar.xz
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>
-rw-r--r--diff.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/diff.c b/diff.c
index 78f7c6f82f..1d0f8b509f 100644
--- a/diff.c
+++ b/diff.c
@@ -561,6 +561,7 @@ static void emit_line(struct diff_options *o, const char *set, const char *reset
}
enum diff_symbol {
+ DIFF_SYMBOL_BINARY_FILES,
DIFF_SYMBOL_HEADER,
DIFF_SYMBOL_FILEPAIR_PLUS,
DIFF_SYMBOL_FILEPAIR_MINUS,
@@ -690,6 +691,7 @@ static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
line, reset,
strchr(line, ' ') ? "\t" : "");
break;
+ case DIFF_SYMBOL_BINARY_FILES:
case DIFF_SYMBOL_HEADER:
fprintf(o->file, "%s", line);
break;
@@ -2542,6 +2544,7 @@ static void builtin_diff(const char *name_a,
} else if (!DIFF_OPT_TST(o, TEXT) &&
( (!textconv_one && diff_filespec_is_binary(one)) ||
(!textconv_two && diff_filespec_is_binary(two)) )) {
+ struct strbuf sb = STRBUF_INIT;
if (!one->data && !two->data &&
S_ISREG(one->mode) && S_ISREG(two->mode) &&
!DIFF_OPT_TST(o, BINARY)) {
@@ -2554,8 +2557,11 @@ static void builtin_diff(const char *name_a,
}
emit_diff_symbol(o, DIFF_SYMBOL_HEADER,
header.buf, header.len, 0);
- fprintf(o->file, "%sBinary files %s and %s differ\n",
- line_prefix, lbl[0], lbl[1]);
+ strbuf_addf(&sb, "%sBinary files %s and %s differ\n",
+ 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;
}
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);
if (DIFF_OPT_TST(o, BINARY))
emit_binary_diff(o->file, &mf1, &mf2, line_prefix);
- else
- fprintf(o->file, "%sBinary files %s and %s differ\n",
- line_prefix, lbl[0], lbl[1]);
+ else {
+ strbuf_addf(&sb, "%sBinary files %s and %s differ\n",
+ 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;
} else {
/* Crazy xdl interfaces.. */