Skip to content

Commit 4acaaa7

Browse files
stefanbellergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a29b0a1 commit 4acaaa7

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

diff.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ static void emit_line(struct diff_options *o, const char *set, const char *reset
561561
}
562562

563563
enum diff_symbol {
564+
DIFF_SYMBOL_BINARY_FILES,
564565
DIFF_SYMBOL_HEADER,
565566
DIFF_SYMBOL_FILEPAIR_PLUS,
566567
DIFF_SYMBOL_FILEPAIR_MINUS,
@@ -690,6 +691,7 @@ static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
690691
line, reset,
691692
strchr(line, ' ') ? "\t" : "");
692693
break;
694+
case DIFF_SYMBOL_BINARY_FILES:
693695
case DIFF_SYMBOL_HEADER:
694696
fprintf(o->file, "%s", line);
695697
break;
@@ -2542,6 +2544,7 @@ static void builtin_diff(const char *name_a,
25422544
} else if (!DIFF_OPT_TST(o, TEXT) &&
25432545
( (!textconv_one && diff_filespec_is_binary(one)) ||
25442546
(!textconv_two && diff_filespec_is_binary(two)) )) {
2547+
struct strbuf sb = STRBUF_INIT;
25452548
if (!one->data && !two->data &&
25462549
S_ISREG(one->mode) && S_ISREG(two->mode) &&
25472550
!DIFF_OPT_TST(o, BINARY)) {
@@ -2554,8 +2557,11 @@ static void builtin_diff(const char *name_a,
25542557
}
25552558
emit_diff_symbol(o, DIFF_SYMBOL_HEADER,
25562559
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);
25592565
goto free_ab_and_return;
25602566
}
25612567
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
@@ -2572,9 +2578,13 @@ static void builtin_diff(const char *name_a,
25722578
strbuf_reset(&header);
25732579
if (DIFF_OPT_TST(o, BINARY))
25742580
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+
}
25782588
o->found_changes = 1;
25792589
} else {
25802590
/* Crazy xdl interfaces.. */

0 commit comments

Comments
 (0)