Skip to content

Commit dce49bb

Browse files
stefanbellergitster
authored andcommitted
diff.c: add set_sign to emit_line_0
For now just change the signature, we'll reason about the actual change in a follow up patch. Pass 'set_sign' (which is output before the sign) and 'set' which controls the color after the first character. Hence, promote any 'set's to 'set_sign' as we want to have color before the sign for now. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 15af0d3 commit dce49bb

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

diff.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ static void check_blank_at_eof(mmfile_t *mf1, mmfile_t *mf2,
576576
}
577577

578578
static void emit_line_0(struct diff_options *o,
579-
const char *set, unsigned reverse, const char *reset,
579+
const char *set_sign, const char *set, unsigned reverse, const char *reset,
580580
int first, const char *line, int len)
581581
{
582582
int has_trailing_newline, has_trailing_carriage_return;
@@ -606,9 +606,12 @@ static void emit_line_0(struct diff_options *o,
606606
if (len || !nofirst) {
607607
if (reverse && want_color(o->use_color))
608608
fputs(GIT_COLOR_REVERSE, file);
609-
fputs(set, file);
609+
if (set_sign && set_sign[0])
610+
fputs(set_sign, file);
610611
if (first && !nofirst)
611612
fputc(first, file);
613+
if (set)
614+
fputs(set, file);
612615
fwrite(line, len, 1, file);
613616
fputs(reset, file);
614617
}
@@ -621,7 +624,7 @@ static void emit_line_0(struct diff_options *o,
621624
static void emit_line(struct diff_options *o, const char *set, const char *reset,
622625
const char *line, int len)
623626
{
624-
emit_line_0(o, set, 0, reset, line[0], line+1, len-1);
627+
emit_line_0(o, set, NULL, 0, reset, line[0], line+1, len-1);
625628
}
626629

627630
enum diff_symbol {
@@ -994,17 +997,17 @@ static void emit_line_ws_markup(struct diff_options *o,
994997
}
995998

996999
if (!ws && !set_sign)
997-
emit_line_0(o, set, 0, reset, sign, line, len);
1000+
emit_line_0(o, set, NULL, 0, reset, sign, line, len);
9981001
else if (!ws) {
9991002
/* Emit just the prefix, then the rest. */
1000-
emit_line_0(o, set_sign, !!set_sign, reset, sign, "", 0);
1001-
emit_line_0(o, set, 0, reset, 0, line, len);
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);
10021005
} else if (blank_at_eof)
10031006
/* Blank line at EOF - paint '+' as well */
1004-
emit_line_0(o, ws, 0, reset, sign, line, len);
1007+
emit_line_0(o, ws, NULL, 0, reset, sign, line, len);
10051008
else {
10061009
/* Emit just the prefix, then the rest. */
1007-
emit_line_0(o, set_sign ? set_sign : set, !!set_sign, reset,
1010+
emit_line_0(o, set_sign ? set_sign : set, NULL, !!set_sign, reset,
10081011
sign, "", 0);
10091012
ws_check_emit(line, len, ws_rule,
10101013
o->file, set, reset, ws);
@@ -1028,7 +1031,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
10281031
context = diff_get_color_opt(o, DIFF_CONTEXT);
10291032
reset = diff_get_color_opt(o, DIFF_RESET);
10301033
putc('\n', o->file);
1031-
emit_line_0(o, context, 0, reset, '\\',
1034+
emit_line_0(o, context, NULL, 0, reset, '\\',
10321035
nneof, strlen(nneof));
10331036
break;
10341037
case DIFF_SYMBOL_SUBMODULE_HEADER:

0 commit comments

Comments
 (0)