Skip to content

Commit 6d8940b

Browse files
SamBgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Samuel Bronson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a21bae3 commit 6d8940b

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

Documentation/diff-config.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ diff.mnemonicprefix::
9898
diff.noprefix::
9999
If set, 'git diff' does not show any source or destination prefix.
100100

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+
101106
diff.renameLimit::
102107
The number of files to consider when performing the copy/rename
103108
detection; equivalent to the 'git diff' option '-l'.

Documentation/diff-options.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ endif::git-format-patch[]
432432
-O<orderfile>::
433433
Output the patch in the order specified in the
434434
<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`.
435438

436439
ifndef::git-format-patch[]
437440
-R::

diff.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ static int diff_use_color_default = -1;
3030
static int diff_context_default = 3;
3131
static const char *diff_word_regex_cfg;
3232
static const char *external_diff_cmd_cfg;
33+
static const char *diff_order_file_cfg;
3334
int diff_auto_refresh_index = 1;
3435
static int diff_mnemonic_prefix;
3536
static int diff_no_prefix;
@@ -201,6 +202,8 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
201202
return git_config_string(&external_diff_cmd_cfg, var, value);
202203
if (!strcmp(var, "diff.wordregex"))
203204
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);
204207

205208
if (!strcmp(var, "diff.ignoresubmodules"))
206209
handle_ignore_submodules_arg(&default_diff_options, value);
@@ -3207,6 +3210,8 @@ void diff_setup(struct diff_options *options)
32073210
options->detect_rename = diff_detect_rename_default;
32083211
options->xdl_opts |= diff_algorithm;
32093212

3213+
options->orderfile = diff_order_file_cfg;
3214+
32103215
if (diff_no_prefix) {
32113216
options->a_prefix = options->b_prefix = "";
32123217
} else if (!diff_mnemonic_prefix) {

t/t4056-diff-order.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ do
8989
wait &&
9090
test_cmp expect_$i actual
9191
'
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+
'
92102
done
93103

94104
test_done

0 commit comments

Comments
 (0)