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>
This commit is contained in:
Stefan Beller 2017-06-29 17:06:54 -07:00 committed by Junio C Hamano
parent 091f8e28b4
commit ff958679cd

42
diff.c
View File

@ -561,6 +561,8 @@ static void emit_line(struct diff_options *o, const char *set, const char *reset
} }
enum diff_symbol { enum diff_symbol {
DIFF_SYMBOL_WORDS_PORCELAIN,
DIFF_SYMBOL_WORDS,
DIFF_SYMBOL_CONTEXT, DIFF_SYMBOL_CONTEXT,
DIFF_SYMBOL_PLUS, DIFF_SYMBOL_PLUS,
DIFF_SYMBOL_MINUS, DIFF_SYMBOL_MINUS,
@ -649,6 +651,26 @@ static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
emit_line_ws_markup(o, set, reset, line, len, '-', emit_line_ws_markup(o, set, reset, line, len, '-',
flags & DIFF_SYMBOL_CONTENT_WS_MASK, 0); flags & DIFF_SYMBOL_CONTENT_WS_MASK, 0);
break; break;
case DIFF_SYMBOL_WORDS_PORCELAIN:
context = diff_get_color_opt(o, DIFF_CONTEXT);
reset = diff_get_color_opt(o, DIFF_RESET);
emit_line(o, context, reset, line, len);
fputs("~\n", o->file);
break;
case DIFF_SYMBOL_WORDS:
context = diff_get_color_opt(o, DIFF_CONTEXT);
reset = diff_get_color_opt(o, DIFF_RESET);
/*
* Skip the prefix character, if any. With
* diff_suppress_blank_empty, there may be
* none.
*/
if (line[0] != '\n') {
line++;
len--;
}
emit_line(o, context, reset, line, len);
break;
default: default:
die("BUG: unknown diff symbol"); die("BUG: unknown diff symbol");
} }
@ -1342,7 +1364,6 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
{ {
struct emit_callback *ecbdata = priv; struct emit_callback *ecbdata = priv;
const char *meta = diff_get_color(ecbdata->color_diff, DIFF_METAINFO); const char *meta = diff_get_color(ecbdata->color_diff, DIFF_METAINFO);
const char *context = diff_get_color(ecbdata->color_diff, DIFF_CONTEXT);
const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET); const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
struct diff_options *o = ecbdata->opt; struct diff_options *o = ecbdata->opt;
const char *line_prefix = diff_line_prefix(o); const char *line_prefix = diff_line_prefix(o);
@ -1384,6 +1405,9 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
} }
if (ecbdata->diff_words) { if (ecbdata->diff_words) {
enum diff_symbol s =
ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN ?
DIFF_SYMBOL_WORDS_PORCELAIN : DIFF_SYMBOL_WORDS;
if (line[0] == '-') { if (line[0] == '-') {
diff_words_append(line, len, diff_words_append(line, len,
&ecbdata->diff_words->minus); &ecbdata->diff_words->minus);
@ -1403,21 +1427,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
return; return;
} }
diff_words_flush(ecbdata); diff_words_flush(ecbdata);
if (ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) { emit_diff_symbol(o, s, line, len, 0);
emit_line(o, context, reset, line, len);
fputs("~\n", o->file);
} else {
/*
* Skip the prefix character, if any. With
* diff_suppress_blank_empty, there may be
* none.
*/
if (line[0] != '\n') {
line++;
len--;
}
emit_line(o, context, reset, line, len);
}
return; return;
} }