diff.c: add set_sign to emit_line_0
Split the meaning of the `set` parameter that is passed to emit_line_0()` to separate between the color of the "sign" (i.e. the diff marker '+', '-' or ' ' that is passed in as the `first` parameter) and the color of the rest of the line. This changes the meaning of the `set` parameter to no longer refer to the color of the diff marker, but instead to refer to the color of the rest of the line. A value of `NULL` indicates that the rest of the line wants to be colored the same as the diff marker. Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Aug 13, 2018 at 18:41 UTC
017ac45e87074a51e7bf926b8f87152a1af9a441
1 file changed
+15
-9
diff.c
+15
-9
@@ -622,7 +622,7 @@ static void check_blank_at_eof(mmfile_t *mf1, mmfile_t *mf2,
622
}
623
624
static void emit_line_0(struct diff_options *o,
625
- const char *set, unsigned reverse, const char *reset,
625
+ const char *set_sign, const char *set, unsigned reverse, const char *reset,
626
int first, const char *line, int len)
627
{
628
int has_trailing_newline, has_trailing_carriage_return;
@@ -652,9 +652,15 @@ static void emit_line_0(struct diff_options *o,
652
if (len || !nofirst) {
653
if (reverse && want_color(o->use_color))
654
fputs(GIT_COLOR_REVERSE, file);
655
- fputs(set, file);
655
+ if (set_sign)
656
+ fputs(set_sign, file);
657
if (first && !nofirst)
658
fputc(first, file);
659
+ if (set && set != set_sign) {
660
+ if (set_sign)
661
+ fputs(reset, file);
662
+ fputs(set, file);
663
+ }
664
fwrite(line, len, 1, file);
665
fputs(reset, file);
666
}
@@ -667,7 +673,7 @@ static void emit_line_0(struct diff_options *o,
673
static void emit_line(struct diff_options *o, const char *set, const char *reset,
674
const char *line, int len)
675
{
670
- emit_line_0(o, set, 0, reset, line[0], line+1, len-1);
676
+ emit_line_0(o, set, NULL, 0, reset, line[0], line+1, len-1);
677
}
678
679
enum diff_symbol {
@@ -1199,17 +1205,17 @@ static void emit_line_ws_markup(struct diff_options *o,
1205
}
1206
1207
if (!ws && !set_sign)
1202
- emit_line_0(o, set, 0, reset, sign, line, len);
1208
+ emit_line_0(o, set, NULL, 0, reset, sign, line, len);
1209
else if (!ws) {
1210
/* Emit just the prefix, then the rest. */
1205
- emit_line_0(o, set_sign, !!set_sign, reset, sign, "", 0);
1206
- emit_line_0(o, set, 0, reset, 0, line, len);
1211
+ emit_line_0(o, set_sign, NULL, !!set_sign, reset, sign, "", 0);
1212
+ emit_line_0(o, set, NULL, 0, reset, 0, line, len);
1213
} else if (blank_at_eof)
1214
/* Blank line at EOF - paint '+' as well */
1209
- emit_line_0(o, ws, 0, reset, sign, line, len);
1215
+ emit_line_0(o, ws, NULL, 0, reset, sign, line, len);
1216
else {
1217
/* Emit just the prefix, then the rest. */
1212
- emit_line_0(o, set_sign ? set_sign : set, !!set_sign, reset,
1218
+ emit_line_0(o, set_sign ? set_sign : set, NULL, !!set_sign, reset,
1219
sign, "", 0);
1220
ws_check_emit(line, len, ws_rule,
1221
o->file, set, reset, ws);
@@ -1233,7 +1239,7 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
1239
context = diff_get_color_opt(o, DIFF_CONTEXT);
1240
reset = diff_get_color_opt(o, DIFF_RESET);
1241
putc('\n', o->file);
1236
- emit_line_0(o, context, 0, reset, '\\',
1242
+ emit_line_0(o, context, NULL, 0, reset, '\\',
1243
nneof, strlen(nneof));
1244
break;
1245
case DIFF_SYMBOL_SUBMODULE_HEADER: