Skip to content

Commit 7581e16

Browse files
stefanbellergitster
authored andcommitted
diff: use emit_line_0 once per line
All lines that use emit_line_0 multiple times per line, are combined into a single call to emit_line_0, making use of the 'set' argument. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dce49bb commit 7581e16

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

diff.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,7 @@ static void emit_line_0(struct diff_options *o,
583583
int nofirst;
584584
FILE *file = o->file;
585585

586-
if (first)
587-
fputs(diff_line_prefix(o), file);
588-
else if (!len)
589-
return;
586+
fputs(diff_line_prefix(o), file);
590587

591588
if (len == 0) {
592589
has_trailing_newline = (first == '\n');
@@ -606,13 +603,17 @@ static void emit_line_0(struct diff_options *o,
606603
if (len || !nofirst) {
607604
if (reverse && want_color(o->use_color))
608605
fputs(GIT_COLOR_REVERSE, file);
609-
if (set_sign && set_sign[0])
610-
fputs(set_sign, file);
606+
if (set_sign || set)
607+
fputs(set_sign ? set_sign : set, file);
611608
if (first && !nofirst)
612609
fputc(first, file);
613-
if (set)
614-
fputs(set, file);
615-
fwrite(line, len, 1, file);
610+
if (len) {
611+
if (set_sign && set && set != set_sign)
612+
fputs(reset, file);
613+
if (set)
614+
fputs(set, file);
615+
fwrite(line, len, 1, file);
616+
}
616617
fputs(reset, file);
617618
}
618619
if (has_trailing_carriage_return)
@@ -999,16 +1000,13 @@ static void emit_line_ws_markup(struct diff_options *o,
9991000
if (!ws && !set_sign)
10001001
emit_line_0(o, set, NULL, 0, reset, sign, line, len);
10011002
else if (!ws) {
1002-
/* Emit just the prefix, then the rest. */
1003-
emit_line_0(o, set_sign, NULL, !!set_sign, reset, sign, "", 0);
1004-
emit_line_0(o, set, NULL, 0, reset, 0, line, len);
1003+
emit_line_0(o, set_sign, set, !!set_sign, reset, sign, line, len);
10051004
} else if (blank_at_eof)
10061005
/* Blank line at EOF - paint '+' as well */
10071006
emit_line_0(o, ws, NULL, 0, reset, sign, line, len);
10081007
else {
10091008
/* Emit just the prefix, then the rest. */
1010-
emit_line_0(o, set_sign ? set_sign : set, NULL, !!set_sign, reset,
1011-
sign, "", 0);
1009+
emit_line_0(o, set_sign, set, !!set_sign, reset, sign, "", 0);
10121010
ws_check_emit(line, len, ws_rule,
10131011
o->file, set, reset, ws);
10141012
}

0 commit comments

Comments
 (0)