diff.c: add --output-indicator-{new, old, context}
This will prove useful in range-diff in a later patch as we will be able to differentiate between adding a new file (that line is starting with +++ and then the file name) and regular new lines. It could also be useful for experimentation in new patch formats, i.e. we could teach git to emit moved lines with lines other than +/-. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Aug 17, 2018 at 13:43 UTC
7648b79eeefc23e773a41b24e3ecdadb9fe93643
2 files changed
+23
-3
diff.c
+18
-3
@@ -1281,7 +1281,9 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
1281
else if (c == '-')
1282
set = diff_get_color_opt(o, DIFF_FILE_OLD);
1283
}
1284
- emit_line_ws_markup(o, set_sign, set, reset, ' ', line, len,
1284
+ emit_line_ws_markup(o, set_sign, set, reset,
1285
+ o->output_indicators[OUTPUT_INDICATOR_CONTEXT],
1286
+ line, len,
1287
flags & (DIFF_SYMBOL_CONTENT_WS_MASK), 0);
1288
break;
1289
case DIFF_SYMBOL_PLUS:
@@ -1324,7 +1326,9 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
1326
set = diff_get_color_opt(o, DIFF_CONTEXT_BOLD);
1327
flags &= ~DIFF_SYMBOL_CONTENT_WS_MASK;
1328
}
1327
- emit_line_ws_markup(o, set_sign, set, reset, '+', line, len,
1329
+ emit_line_ws_markup(o, set_sign, set, reset,
1330
+ o->output_indicators[OUTPUT_INDICATOR_NEW],
1331
+ line, len,
1332
flags & DIFF_SYMBOL_CONTENT_WS_MASK,
1333
flags & DIFF_SYMBOL_CONTENT_BLANK_LINE_EOF);
1334
break;
@@ -1367,7 +1371,9 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
1371
else
1372
set = diff_get_color_opt(o, DIFF_CONTEXT_DIM);
1373
}
1370
- emit_line_ws_markup(o, set_sign, set, reset, '-', line, len,
1374
+ emit_line_ws_markup(o, set_sign, set, reset,
1375
+ o->output_indicators[OUTPUT_INDICATOR_OLD],
1376
+ line, len,
1377
flags & DIFF_SYMBOL_CONTENT_WS_MASK, 0);
1378
break;
1379
case DIFF_SYMBOL_WORDS_PORCELAIN:
@@ -4382,6 +4388,9 @@ void diff_setup(struct diff_options *options)
4388
4389
options->file = stdout;
4390
4391
+ options->output_indicators[OUTPUT_INDICATOR_NEW] = '+';
4392
+ options->output_indicators[OUTPUT_INDICATOR_OLD] = '-';
4393
+ options->output_indicators[OUTPUT_INDICATOR_CONTEXT] = ' ';
4394
options->abbrev = DEFAULT_ABBREV;
4395
options->line_termination = '\n';
4396
options->break_opt = -1;
@@ -4869,6 +4878,12 @@ int diff_opt_parse(struct diff_options *options,
4878
options->output_format |= DIFF_FORMAT_DIFFSTAT;
4879
} else if (!strcmp(arg, "--no-compact-summary"))
4880
options->flags.stat_with_summary = 0;
4881
+ else if (skip_prefix(arg, "--output-indicator-new=", &arg))
4882
+ options->output_indicators[OUTPUT_INDICATOR_NEW] = arg[0];
4883
+ else if (skip_prefix(arg, "--output-indicator-old=", &arg))
4884
+ options->output_indicators[OUTPUT_INDICATOR_OLD] = arg[0];
4885
+ else if (skip_prefix(arg, "--output-indicator-context=", &arg))
4886
+ options->output_indicators[OUTPUT_INDICATOR_CONTEXT] = arg[0];
4887
4888
/* renames options */
4889
else if (starts_with(arg, "-B") ||
diff.h
+5
@@ -194,6 +194,11 @@ struct diff_options {
194
FILE *file;
195
int close_file;
196
197
+#define OUTPUT_INDICATOR_NEW 0
198
+#define OUTPUT_INDICATOR_OLD 1
199
+#define OUTPUT_INDICATOR_CONTEXT 2
200
+ char output_indicators[3];
201
+
202
struct pathspec pathspec;
203
pathchange_fn_t pathchange;
204
change_fn_t change;