summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Stefan Beller <sbeller@google.com>2017-06-29 17:06:54 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-06-30 13:13:01 -0700
commitff958679cdb10fea9fbea07587b6bf9eff7411c0 (patch)
treed2f938a72578a8233a62ea2717cb0c6780aa1231
parentdiff.c: migrate emit_line_checked to use emit_diff_symbol (diff)
downloadtgif-ff958679cdb10fea9fbea07587b6bf9eff7411c0.tar.xz
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>
-rw-r--r--diff.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/diff.c b/diff.c
index e5430d56da..85bfd9310d 100644
--- a/diff.c
+++ b/diff.c
@@ -561,6 +561,8 @@ static void emit_line(struct diff_options *o, const char *set, const char *reset
}
enum diff_symbol {
+ DIFF_SYMBOL_WORDS_PORCELAIN,
+ DIFF_SYMBOL_WORDS,
DIFF_SYMBOL_CONTEXT,
DIFF_SYMBOL_PLUS,
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, '-',
flags & DIFF_SYMBOL_CONTENT_WS_MASK, 0);
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:
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;
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);
struct diff_options *o = ecbdata->opt;
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) {
+ enum diff_symbol s =
+ ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN ?
+ DIFF_SYMBOL_WORDS_PORCELAIN : DIFF_SYMBOL_WORDS;
if (line[0] == '-') {
diff_words_append(line, len,
&ecbdata->diff_words->minus);
@@ -1403,21 +1427,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
return;
}
diff_words_flush(ecbdata);
- if (ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) {
- 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);
- }
+ emit_diff_symbol(o, s, line, len, 0);
return;
}