diff: introduce diff.wsErrorHighlight option

With the preparatory steps, it has become trivial to teach the
system a new diff.wsErrorHighlight configuration that gives the
default value for --ws-error-highlight command line option.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano 2016-10-04 15:26:27 -07:00
Родитель 0b4b42e7fe
Коммит a17505f262
4 изменённых файлов: 53 добавлений и 1 удалений

Просмотреть файл

@ -182,3 +182,9 @@ diff.algorithm::
low-occurrence common elements".
--
+
diff.wsErrorHighlight::
A comma separated list of `old`, `new`, `context`, that
specifies how whitespace errors on lines are highlighted
with `color.diff.whitespace`. Can be overridden by the
command line option `--ws-error-highlight=<kind>`

Просмотреть файл

@ -303,6 +303,8 @@ ifndef::git-format-patch[]
lines are highlighted. E.g. `--ws-error-highlight=new,old`
highlights whitespace errors on both deleted and added lines.
`all` can be used as a short-hand for `old,new,context`.
The `diff.wsErrorHighlight` configuration variable can be
used to specify the default behaviour.
endif::git-format-patch[]

11
diff.c
Просмотреть файл

@ -41,6 +41,7 @@ static int diff_stat_graph_width;
static int diff_dirstat_permille_default = 30;
static struct diff_options default_diff_options;
static long diff_algorithm;
static unsigned ws_error_highlight_default = WSEH_NEW;
static char diff_colors[][COLOR_MAXLEN] = {
GIT_COLOR_RESET,
@ -262,6 +263,14 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
return 0;
}
if (!strcmp(var, "diff.wserrorhighlight")) {
int val = parse_ws_error_highlight(value);
if (val < 0)
return -1;
ws_error_highlight_default = val;
return 0;
}
if (git_color_config(var, value, cb) < 0)
return -1;
@ -3306,7 +3315,7 @@ void diff_setup(struct diff_options *options)
options->rename_limit = -1;
options->dirstat_permille = diff_dirstat_permille_default;
options->context = diff_context_default;
options->ws_error_highlight = WSEH_NEW;
options->ws_error_highlight = ws_error_highlight_default;
DIFF_OPT_SET(options, RENAME_EMPTY);
/* pathchange left =NULL by default */

Просмотреть файл

@ -937,4 +937,39 @@ test_expect_success 'test --ws-error-highlight option' '
'
test_expect_success 'test diff.wsErrorHighlight config' '
git -c color.diff=always -c diff.wsErrorHighlight=default,old diff |
test_decode_color >current &&
test_cmp expect.default-old current &&
git -c color.diff=always -c diff.wsErrorHighlight=all diff |
test_decode_color >current &&
test_cmp expect.all current &&
git -c color.diff=always -c diff.wsErrorHighlight=none diff |
test_decode_color >current &&
test_cmp expect.none current
'
test_expect_success 'option overrides diff.wsErrorHighlight' '
git -c color.diff=always -c diff.wsErrorHighlight=none \
diff --ws-error-highlight=default,old |
test_decode_color >current &&
test_cmp expect.default-old current &&
git -c color.diff=always -c diff.wsErrorHighlight=default \
diff --ws-error-highlight=all |
test_decode_color >current &&
test_cmp expect.all current &&
git -c color.diff=always -c diff.wsErrorHighlight=all \
diff --ws-error-highlight=none |
test_decode_color >current &&
test_cmp expect.none current
'
test_done