diff: add diff.orderfile configuration variable

diff.orderfile acts as a default for the -O command line option. [sb: split up aw's original patch; rework tests and docs, treat option as pathname] Signed-off-by: Anders Waldenborg <anders@0x63.nu> Signed-off-by: Samuel Bronson <naesten@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Samuel Bronson committed Dec 18, 2013 at 19:08 UTC 6d8940b562adc5e43068868109dffe1b9bff7f78
4 files changed +23
Documentation/diff-config.txt
+5
@@ -98,6 +98,11 @@ diff.mnemonicprefix::
98 diff.noprefix::
99 If set, 'git diff' does not show any source or destination prefix.
100
101 +diff.orderfile::
102 + File indicating how to order files within a diff, using
103 + one shell glob pattern per line.
104 + Can be overridden by the '-O' option to linkgit:git-diff[1].
105 +
106 diff.renameLimit::
107 The number of files to consider when performing the copy/rename
108 detection; equivalent to the 'git diff' option '-l'.
Documentation/diff-options.txt
+3
@@ -432,6 +432,9 @@ endif::git-format-patch[]
432 -O<orderfile>::
433 Output the patch in the order specified in the
434 <orderfile>, which has one shell glob pattern per line.
435 + This overrides the `diff.orderfile` configuration variable
436 + (see linkgit:git-config[1]). To cancel `diff.orderfile`,
437 + use `-O/dev/null`.
438
439 ifndef::git-format-patch[]
440 -R::
diff.c
+5
@@ -30,6 +30,7 @@ static int diff_use_color_default = -1;
30 static int diff_context_default = 3;
31 static const char *diff_word_regex_cfg;
32 static const char *external_diff_cmd_cfg;
33 +static const char *diff_order_file_cfg;
34 int diff_auto_refresh_index = 1;
35 static int diff_mnemonic_prefix;
36 static int diff_no_prefix;
@@ -201,6 +202,8 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
202 return git_config_string(&external_diff_cmd_cfg, var, value);
203 if (!strcmp(var, "diff.wordregex"))
204 return git_config_string(&diff_word_regex_cfg, var, value);
205 + if (!strcmp(var, "diff.orderfile"))
206 + return git_config_pathname(&diff_order_file_cfg, var, value);
207
208 if (!strcmp(var, "diff.ignoresubmodules"))
209 handle_ignore_submodules_arg(&default_diff_options, value);
@@ -3207,6 +3210,8 @@ void diff_setup(struct diff_options *options)
3210 options->detect_rename = diff_detect_rename_default;
3211 options->xdl_opts |= diff_algorithm;
3212
3213 + options->orderfile = diff_order_file_cfg;
3214 +
3215 if (diff_no_prefix) {
3216 options->a_prefix = options->b_prefix = "";
3217 } else if (!diff_mnemonic_prefix) {
t/t4056-diff-order.sh
+10
@@ -89,6 +89,16 @@ do
89 wait &&
90 test_cmp expect_$i actual
91 '
92 +
93 + test_expect_success "orderfile using config ($i)" '
94 + git -c diff.orderfile=order_file_$i diff --name-only HEAD^..HEAD >actual &&
95 + test_cmp expect_$i actual
96 + '
97 +
98 + test_expect_success "cancelling configured orderfile ($i)" '
99 + git -c diff.orderfile=order_file_$i diff -O/dev/null --name-only HEAD^..HEAD >actual &&
100 + test_cmp expect_none actual
101 + '
102 done
103
104 test_done