Skip to content

Commit ac4915d

Browse files
committed
Merge branch 'vn/diff-ihc-config' into next
"git diff" learned diff.interHunkContext configuration variable that gives the default value for its --inter-hunk-context option. * vn/diff-ihc-config: diff: add interhunk context config option
2 parents 2e8a38b + c488867 commit ac4915d

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

Documentation/diff-config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ diff.context::
6060
Generate diffs with <n> lines of context instead of the default
6161
of 3. This value is overridden by the -U option.
6262

63+
diff.interHunkContext::
64+
Show the context between diff hunks, up to the specified number
65+
of lines, thereby fusing the hunks that are close to each other.
66+
This value serves as the default for the `--inter-hunk-context`
67+
command line option.
68+
6369
diff.external::
6470
If this config variable is set, diff generation is not
6571
performed using the internal diff machinery, but using the

Documentation/diff-options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ endif::git-format-patch[]
511511
--inter-hunk-context=<lines>::
512512
Show the context between diff hunks, up to the specified number
513513
of lines, thereby fusing hunks that are close to each other.
514+
Defaults to `diff.interHunkContext` or 0 if the config option
515+
is unset.
514516

515517
-W::
516518
--function-context::

diff.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ static int diff_rename_limit_default = 400;
3232
static int diff_suppress_blank_empty;
3333
static int diff_use_color_default = -1;
3434
static int diff_context_default = 3;
35+
static int diff_interhunk_context_default;
3536
static const char *diff_word_regex_cfg;
3637
static const char *external_diff_cmd_cfg;
3738
static const char *diff_order_file_cfg;
@@ -239,6 +240,12 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
239240
return -1;
240241
return 0;
241242
}
243+
if (!strcmp(var, "diff.interhunkcontext")) {
244+
diff_interhunk_context_default = git_config_int(var, value);
245+
if (diff_interhunk_context_default < 0)
246+
return -1;
247+
return 0;
248+
}
242249
if (!strcmp(var, "diff.renames")) {
243250
diff_detect_rename_default = git_config_rename(var, value);
244251
return 0;
@@ -3362,6 +3369,7 @@ void diff_setup(struct diff_options *options)
33623369
options->rename_limit = -1;
33633370
options->dirstat_permille = diff_dirstat_permille_default;
33643371
options->context = diff_context_default;
3372+
options->interhunkcontext = diff_interhunk_context_default;
33653373
options->ws_error_highlight = ws_error_highlight_default;
33663374
DIFF_OPT_SET(options, RENAME_EMPTY);
33673375

t/t4032-diff-inter-hunk-context.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ f() {
1616
}
1717

1818
t() {
19+
use_config=
20+
git config --unset diff.interHunkContext
21+
1922
case $# in
2023
4) hunks=$4; cmd="diff -U$3";;
2124
5) hunks=$5; cmd="diff -U$3 --inter-hunk-context=$4";;
25+
6) hunks=$5; cmd="diff -U$3"; git config diff.interHunkContext $4; use_config="(diff.interHunkContext=$4) ";;
2226
esac
23-
label="$cmd, $1 common $2"
27+
label="$use_config$cmd, $1 common $2"
2428
file=f$1
2529
expected=expected.$file.$3.$hunks
2630

@@ -89,4 +93,25 @@ t 9 lines 3 2
8993
t 9 lines 3 2 2
9094
t 9 lines 3 3 1
9195

96+
# use diff.interHunkContext?
97+
t 1 line 0 0 2 config
98+
t 1 line 0 1 1 config
99+
t 1 line 0 2 1 config
100+
t 9 lines 3 3 1 config
101+
t 2 lines 0 0 2 config
102+
t 2 lines 0 1 2 config
103+
t 2 lines 0 2 1 config
104+
t 3 lines 1 0 2 config
105+
t 3 lines 1 1 1 config
106+
t 3 lines 1 2 1 config
107+
t 9 lines 3 2 2 config
108+
t 9 lines 3 3 1 config
109+
110+
test_expect_success 'diff.interHunkContext invalid' '
111+
git config diff.interHunkContext asdf &&
112+
test_must_fail git diff &&
113+
git config diff.interHunkContext -1 &&
114+
test_must_fail git diff
115+
'
116+
92117
test_done

0 commit comments

Comments
 (0)