Skip to content

Commit ff95867

Browse files
stefanbellergitster
authored andcommitted
diff.c: emit_diff_symbol learns DIFF_SYMBOL_WORDS[_PORCELAIN]
Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 091f8e2 commit ff95867

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

diff.c

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

563563
enum diff_symbol {
564+
DIFF_SYMBOL_WORDS_PORCELAIN,
565+
DIFF_SYMBOL_WORDS,
564566
DIFF_SYMBOL_CONTEXT,
565567
DIFF_SYMBOL_PLUS,
566568
DIFF_SYMBOL_MINUS,
@@ -649,6 +651,26 @@ static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
649651
emit_line_ws_markup(o, set, reset, line, len, '-',
650652
flags & DIFF_SYMBOL_CONTENT_WS_MASK, 0);
651653
break;
654+
case DIFF_SYMBOL_WORDS_PORCELAIN:
655+
context = diff_get_color_opt(o, DIFF_CONTEXT);
656+
reset = diff_get_color_opt(o, DIFF_RESET);
657+
emit_line(o, context, reset, line, len);
658+
fputs("~\n", o->file);
659+
break;
660+
case DIFF_SYMBOL_WORDS:
661+
context = diff_get_color_opt(o, DIFF_CONTEXT);
662+
reset = diff_get_color_opt(o, DIFF_RESET);
663+
/*
664+
* Skip the prefix character, if any. With
665+
* diff_suppress_blank_empty, there may be
666+
* none.
667+
*/
668+
if (line[0] != '\n') {
669+
line++;
670+
len--;
671+
}
672+
emit_line(o, context, reset, line, len);
673+
break;
652674
default:
653675
die("BUG: unknown diff symbol");
654676
}
@@ -1342,7 +1364,6 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
13421364
{
13431365
struct emit_callback *ecbdata = priv;
13441366
const char *meta = diff_get_color(ecbdata->color_diff, DIFF_METAINFO);
1345-
const char *context = diff_get_color(ecbdata->color_diff, DIFF_CONTEXT);
13461367
const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
13471368
struct diff_options *o = ecbdata->opt;
13481369
const char *line_prefix = diff_line_prefix(o);
@@ -1384,6 +1405,9 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
13841405
}
13851406

13861407
if (ecbdata->diff_words) {
1408+
enum diff_symbol s =
1409+
ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN ?
1410+
DIFF_SYMBOL_WORDS_PORCELAIN : DIFF_SYMBOL_WORDS;
13871411
if (line[0] == '-') {
13881412
diff_words_append(line, len,
13891413
&ecbdata->diff_words->minus);
@@ -1403,21 +1427,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
14031427
return;
14041428
}
14051429
diff_words_flush(ecbdata);
1406-
if (ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) {
1407-
emit_line(o, context, reset, line, len);
1408-
fputs("~\n", o->file);
1409-
} else {
1410-
/*
1411-
* Skip the prefix character, if any. With
1412-
* diff_suppress_blank_empty, there may be
1413-
* none.
1414-
*/
1415-
if (line[0] != '\n') {
1416-
line++;
1417-
len--;
1418-
}
1419-
emit_line(o, context, reset, line, len);
1420-
}
1430+
emit_diff_symbol(o, s, line, len, 0);
14211431
return;
14221432
}
14231433

0 commit comments

Comments
 (0)