Skip to content

Commit a29b0a1

Browse files
stefanbellergitster
authored andcommitted
diff.c: emit_diff_symbol learns DIFF_SYMBOL_HEADER
The header is constructed lazily including line breaks, so just emit the raw string as is. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3ee8b7b commit a29b0a1

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

diff.c

Lines changed: 20 additions & 8 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_HEADER,
564565
DIFF_SYMBOL_FILEPAIR_PLUS,
565566
DIFF_SYMBOL_FILEPAIR_MINUS,
566567
DIFF_SYMBOL_WORDS_PORCELAIN,
@@ -689,6 +690,9 @@ static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
689690
line, reset,
690691
strchr(line, ' ') ? "\t" : "");
691692
break;
693+
case DIFF_SYMBOL_HEADER:
694+
fprintf(o->file, "%s", line);
695+
break;
692696
default:
693697
die("BUG: unknown diff symbol");
694698
}
@@ -1385,7 +1389,8 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
13851389
o->found_changes = 1;
13861390

13871391
if (ecbdata->header) {
1388-
fprintf(o->file, "%s", ecbdata->header->buf);
1392+
emit_diff_symbol(o, DIFF_SYMBOL_HEADER,
1393+
ecbdata->header->buf, ecbdata->header->len, 0);
13891394
strbuf_reset(ecbdata->header);
13901395
ecbdata->header = NULL;
13911396
}
@@ -2519,7 +2524,8 @@ static void builtin_diff(const char *name_a,
25192524
if (complete_rewrite &&
25202525
(textconv_one || !diff_filespec_is_binary(one)) &&
25212526
(textconv_two || !diff_filespec_is_binary(two))) {
2522-
fprintf(o->file, "%s", header.buf);
2527+
emit_diff_symbol(o, DIFF_SYMBOL_HEADER,
2528+
header.buf, header.len, 0);
25232529
strbuf_reset(&header);
25242530
emit_rewrite_diff(name_a, name_b, one, two,
25252531
textconv_one, textconv_two, o);
@@ -2529,7 +2535,8 @@ static void builtin_diff(const char *name_a,
25292535
}
25302536

25312537
if (o->irreversible_delete && lbl[1][0] == '/') {
2532-
fprintf(o->file, "%s", header.buf);
2538+
emit_diff_symbol(o, DIFF_SYMBOL_HEADER, header.buf,
2539+
header.len, 0);
25332540
strbuf_reset(&header);
25342541
goto free_ab_and_return;
25352542
} else if (!DIFF_OPT_TST(o, TEXT) &&
@@ -2540,10 +2547,13 @@ static void builtin_diff(const char *name_a,
25402547
!DIFF_OPT_TST(o, BINARY)) {
25412548
if (!oidcmp(&one->oid, &two->oid)) {
25422549
if (must_show_header)
2543-
fprintf(o->file, "%s", header.buf);
2550+
emit_diff_symbol(o, DIFF_SYMBOL_HEADER,
2551+
header.buf, header.len,
2552+
0);
25442553
goto free_ab_and_return;
25452554
}
2546-
fprintf(o->file, "%s", header.buf);
2555+
emit_diff_symbol(o, DIFF_SYMBOL_HEADER,
2556+
header.buf, header.len, 0);
25472557
fprintf(o->file, "%sBinary files %s and %s differ\n",
25482558
line_prefix, lbl[0], lbl[1]);
25492559
goto free_ab_and_return;
@@ -2554,10 +2564,11 @@ static void builtin_diff(const char *name_a,
25542564
if (mf1.size == mf2.size &&
25552565
!memcmp(mf1.ptr, mf2.ptr, mf1.size)) {
25562566
if (must_show_header)
2557-
fprintf(o->file, "%s", header.buf);
2567+
emit_diff_symbol(o, DIFF_SYMBOL_HEADER,
2568+
header.buf, header.len, 0);
25582569
goto free_ab_and_return;
25592570
}
2560-
fprintf(o->file, "%s", header.buf);
2571+
emit_diff_symbol(o, DIFF_SYMBOL_HEADER, header.buf, header.len, 0);
25612572
strbuf_reset(&header);
25622573
if (DIFF_OPT_TST(o, BINARY))
25632574
emit_binary_diff(o->file, &mf1, &mf2, line_prefix);
@@ -2575,7 +2586,8 @@ static void builtin_diff(const char *name_a,
25752586
const struct userdiff_funcname *pe;
25762587

25772588
if (must_show_header) {
2578-
fprintf(o->file, "%s", header.buf);
2589+
emit_diff_symbol(o, DIFF_SYMBOL_HEADER,
2590+
header.buf, header.len, 0);
25792591
strbuf_reset(&header);
25802592
}
25812593

0 commit comments

Comments
 (0)