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>
Stefan Beller committed
Jun 29, 2017 at 17:06 UTC
ff958679cdb10fea9fbea07587b6bf9eff7411c0
1 file changed
+26
-16
diff.c
+26
-16
@@ -561,6 +561,8 @@ static void emit_line(struct diff_options *o, const char *set, const char *reset
561
}
562
563
enum diff_symbol {
564
+ DIFF_SYMBOL_WORDS_PORCELAIN,
565
+ DIFF_SYMBOL_WORDS,
566
DIFF_SYMBOL_CONTEXT,
567
DIFF_SYMBOL_PLUS,
568
DIFF_SYMBOL_MINUS,
@@ -649,6 +651,26 @@ static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
651
emit_line_ws_markup(o, set, reset, line, len, '-',
652
flags & DIFF_SYMBOL_CONTENT_WS_MASK, 0);
653
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;
674
default:
675
die("BUG: unknown diff symbol");
676
}
@@ -1342,7 +1364,6 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
1364
{
1365
struct emit_callback *ecbdata = priv;
1366
const char *meta = diff_get_color(ecbdata->color_diff, DIFF_METAINFO);
1345
- const char *context = diff_get_color(ecbdata->color_diff, DIFF_CONTEXT);
1367
const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
1368
struct diff_options *o = ecbdata->opt;
1369
const char *line_prefix = diff_line_prefix(o);
@@ -1384,6 +1405,9 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
1405
}
1406
1407
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;
1411
if (line[0] == '-') {
1412
diff_words_append(line, len,
1413
&ecbdata->diff_words->minus);
@@ -1403,21 +1427,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
1427
return;
1428
}
1429
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);
1431
return;
1432
}
1433