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>
Stefan Beller committed
Jun 29, 2017 at 17:06 UTC
4acaaa7af65a62db1f58861170d9d3918103c1b9
1 file changed
+15
-5
diff.c
+15
-5
@@ -561,6 +561,7 @@ static void emit_line(struct diff_options *o, const char *set, const char *reset
561
}
562
563
enum diff_symbol {
564
+ DIFF_SYMBOL_BINARY_FILES,
565
DIFF_SYMBOL_HEADER,
566
DIFF_SYMBOL_FILEPAIR_PLUS,
567
DIFF_SYMBOL_FILEPAIR_MINUS,
@@ -690,6 +691,7 @@ static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
691
line, reset,
692
strchr(line, ' ') ? "\t" : "");
693
break;
694
+ case DIFF_SYMBOL_BINARY_FILES:
695
case DIFF_SYMBOL_HEADER:
696
fprintf(o->file, "%s", line);
697
break;
@@ -2542,6 +2544,7 @@ static void builtin_diff(const char *name_a,
2544
} else if (!DIFF_OPT_TST(o, TEXT) &&
2545
( (!textconv_one && diff_filespec_is_binary(one)) ||
2546
(!textconv_two && diff_filespec_is_binary(two)) )) {
2547
+ struct strbuf sb = STRBUF_INIT;
2548
if (!one->data && !two->data &&
2549
S_ISREG(one->mode) && S_ISREG(two->mode) &&
2550
!DIFF_OPT_TST(o, BINARY)) {
@@ -2554,8 +2557,11 @@ static void builtin_diff(const char *name_a,
2557
}
2558
emit_diff_symbol(o, DIFF_SYMBOL_HEADER,
2559
header.buf, header.len, 0);
2557
- fprintf(o->file, "%sBinary files %s and %s differ\n",
2558
- line_prefix, lbl[0], lbl[1]);
2560
+ strbuf_addf(&sb, "%sBinary files %s and %s differ\n",
2561
+ diff_line_prefix(o), lbl[0], lbl[1]);
2562
+ emit_diff_symbol(o, DIFF_SYMBOL_BINARY_FILES,
2563
+ sb.buf, sb.len, 0);
2564
+ strbuf_release(&sb);
2565
goto free_ab_and_return;
2566
}
2567
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
@@ -2572,9 +2578,13 @@ static void builtin_diff(const char *name_a,
2578
strbuf_reset(&header);
2579
if (DIFF_OPT_TST(o, BINARY))
2580
emit_binary_diff(o->file, &mf1, &mf2, line_prefix);
2575
- else
2576
- fprintf(o->file, "%sBinary files %s and %s differ\n",
2577
- line_prefix, lbl[0], lbl[1]);
2581
+ else {
2582
+ strbuf_addf(&sb, "%sBinary files %s and %s differ\n",
2583
+ diff_line_prefix(o), lbl[0], lbl[1]);
2584
+ emit_diff_symbol(o, DIFF_SYMBOL_BINARY_FILES,
2585
+ sb.buf, sb.len, 0);
2586
+ strbuf_release(&sb);
2587
+ }
2588
o->found_changes = 1;
2589
} else {
2590
/* Crazy xdl interfaces.. */