Signed-off-by: Stefan Beller <[email protected]>
---
diff.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/diff.c b/diff.c
index 95f11ea86f..e56962b844 100644
--- a/diff.c
+++ b/diff.c
@@ -572,6 +572,7 @@ enum diff_symbol {
DIFF_SYMBOL_WORDS,
DIFF_SYMBOL_FILEPAIR,
DIFF_SYMBOL_HEADER,
+ DIFF_SYMBOL_BINARY_FILES,
};
/*
* Flags for content lines:
@@ -689,6 +690,10 @@ static void emit_diff_symbol(struct diff_options *o, enum
diff_symbol s,
case DIFF_SYMBOL_HEADER:
fprintf(o->file, "%s", line);
break;
+ case DIFF_SYMBOL_BINARY_FILES:
+ fprintf(o->file, "%sBinary files %s differ\n",
+ diff_line_prefix(o), line);
+ break;
default:
die("BUG: unknown diff symbol");
}
@@ -2537,6 +2542,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)) {
@@ -2549,8 +2555,10 @@ 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, "%s and %s", 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)
@@ -2567,9 +2575,12 @@ 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, "%s and %s", 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.. */
--
2.12.2.575.gb14f27f917