Skip to content

Commit 53083f8

Browse files
committed
Merge branch 'mb/diff-default-to-indent-heuristics'
Make the "indent" heuristics the default in "diff" and diff.indentHeuristics configuration variable an escape hatch for those who do no want it. * mb/diff-default-to-indent-heuristics: add--interactive: drop diff.indentHeuristic handling diff: enable indent heuristic by default diff: have the diff-* builtins configure diff before initializing revisions diff: make the indent heuristic part of diff's basic configuration
2 parents 70f8ba5 + 1fa8a66 commit 53083f8

File tree

7 files changed

+177
-28
lines changed

7 files changed

+177
-28
lines changed

builtin/diff-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
2020
int result;
2121
unsigned options = 0;
2222

23+
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2324
init_revisions(&rev, prefix);
2425
gitmodules_config();
25-
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2626
rev.abbrev = 0;
2727
precompose_argv(argc, argv);
2828

builtin/diff-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
1717
int i;
1818
int result;
1919

20+
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2021
init_revisions(&rev, prefix);
2122
gitmodules_config();
22-
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2323
rev.abbrev = 0;
2424
precompose_argv(argc, argv);
2525

builtin/diff-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
105105
struct setup_revision_opt s_r_opt;
106106
int read_stdin = 0;
107107

108+
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
108109
init_revisions(opt, prefix);
109110
gitmodules_config();
110-
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
111111
opt->abbrev = 0;
112112
opt->diff = 1;
113113
opt->disable_stdin = 1;

diff.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#endif
2828

2929
static int diff_detect_rename_default;
30-
static int diff_indent_heuristic; /* experimental */
30+
static int diff_indent_heuristic = 1;
3131
static int diff_rename_limit_default = 400;
3232
static int diff_suppress_blank_empty;
3333
static int diff_use_color_default = -1;
@@ -290,9 +290,6 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
290290
return 0;
291291
}
292292

293-
if (git_diff_heuristic_config(var, value, cb) < 0)
294-
return -1;
295-
296293
if (!strcmp(var, "diff.wserrorhighlight")) {
297294
int val = parse_ws_error_highlight(value);
298295
if (val < 0)
@@ -351,6 +348,9 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
351348
if (starts_with(var, "submodule."))
352349
return parse_submodule_config_option(var, value);
353350

351+
if (git_diff_heuristic_config(var, value, cb) < 0)
352+
return -1;
353+
354354
return git_default_config(var, value, cb);
355355
}
356356

git-add--interactive.perl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
my $normal_color = $repo->get_color("", "reset");
4747

4848
my $diff_algorithm = $repo->config('diff.algorithm');
49-
my $diff_indent_heuristic = $repo->config_bool('diff.indentheuristic');
5049
my $diff_filter = $repo->config('interactive.difffilter');
5150

5251
my $use_readkey = 0;
@@ -730,9 +729,6 @@ sub parse_diff {
730729
if (defined $diff_algorithm) {
731730
splice @diff_cmd, 1, 0, "--diff-algorithm=${diff_algorithm}";
732731
}
733-
if ($diff_indent_heuristic) {
734-
splice @diff_cmd, 1, 0, "--indent-heuristic";
735-
}
736732
if (defined $patch_mode_revision) {
737733
push @diff_cmd, get_diff_reference($patch_mode_revision);
738734
}

t/t4051-diff-function-context.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ test_expect_success 'setup' '
7272
7373
# overlap function context of 1st change and -u context of 2nd change
7474
grep -v "delete me from hello" <"$dir/hello.c" >file.c &&
75-
sed 2p <"$dir/dummy.c" >>file.c &&
75+
sed "2a\\
76+
extra line" <"$dir/dummy.c" >>file.c &&
7677
commit_and_tag changed_hello_dummy file.c &&
7778
7879
git checkout initial &&

t/t4061-diff-indent.sh

Lines changed: 168 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,26 +152,28 @@ test_expect_success 'prepare' '
152152
EOF
153153
'
154154

155+
# --- diff tests ----------------------------------------------------------
156+
155157
test_expect_success 'diff: ugly spaces' '
156-
git diff old new -- spaces.txt >out &&
158+
git diff --no-indent-heuristic old new -- spaces.txt >out &&
157159
compare_diff spaces-expect out
158160
'
159161

162+
test_expect_success 'diff: --no-indent-heuristic overrides config' '
163+
git -c diff.indentHeuristic=true diff --no-indent-heuristic old new -- spaces.txt >out2 &&
164+
compare_diff spaces-expect out2
165+
'
166+
160167
test_expect_success 'diff: nice spaces with --indent-heuristic' '
161-
git diff --indent-heuristic old new -- spaces.txt >out-compacted &&
168+
git -c diff.indentHeuristic=false diff --indent-heuristic old new -- spaces.txt >out-compacted &&
162169
compare_diff spaces-compacted-expect out-compacted
163170
'
164171

165-
test_expect_success 'diff: nice spaces with diff.indentHeuristic' '
172+
test_expect_success 'diff: nice spaces with diff.indentHeuristic=true' '
166173
git -c diff.indentHeuristic=true diff old new -- spaces.txt >out-compacted2 &&
167174
compare_diff spaces-compacted-expect out-compacted2
168175
'
169176

170-
test_expect_success 'diff: --no-indent-heuristic overrides config' '
171-
git -c diff.indentHeuristic=true diff --no-indent-heuristic old new -- spaces.txt >out2 &&
172-
compare_diff spaces-expect out2
173-
'
174-
175177
test_expect_success 'diff: --indent-heuristic with --patience' '
176178
git diff --indent-heuristic --patience old new -- spaces.txt >out-compacted3 &&
177179
compare_diff spaces-compacted-expect out-compacted3
@@ -183,7 +185,7 @@ test_expect_success 'diff: --indent-heuristic with --histogram' '
183185
'
184186

185187
test_expect_success 'diff: ugly functions' '
186-
git diff old new -- functions.c >out &&
188+
git diff --no-indent-heuristic old new -- functions.c >out &&
187189
compare_diff functions-expect out
188190
'
189191

@@ -192,25 +194,175 @@ test_expect_success 'diff: nice functions with --indent-heuristic' '
192194
compare_diff functions-compacted-expect out-compacted
193195
'
194196

195-
test_expect_success 'blame: ugly spaces' '
196-
git blame old..new -- spaces.txt >out-blame &&
197-
compare_blame spaces-expect out-blame
198-
'
197+
# --- blame tests ---------------------------------------------------------
199198

200199
test_expect_success 'blame: nice spaces with --indent-heuristic' '
201200
git blame --indent-heuristic old..new -- spaces.txt >out-blame-compacted &&
202201
compare_blame spaces-compacted-expect out-blame-compacted
203202
'
204203

205-
test_expect_success 'blame: nice spaces with diff.indentHeuristic' '
204+
test_expect_success 'blame: nice spaces with diff.indentHeuristic=true' '
206205
git -c diff.indentHeuristic=true blame old..new -- spaces.txt >out-blame-compacted2 &&
207206
compare_blame spaces-compacted-expect out-blame-compacted2
208207
'
209208

209+
test_expect_success 'blame: ugly spaces with --no-indent-heuristic' '
210+
git blame --no-indent-heuristic old..new -- spaces.txt >out-blame &&
211+
compare_blame spaces-expect out-blame
212+
'
213+
214+
test_expect_success 'blame: ugly spaces with diff.indentHeuristic=false' '
215+
git -c diff.indentHeuristic=false blame old..new -- spaces.txt >out-blame2 &&
216+
compare_blame spaces-expect out-blame2
217+
'
218+
210219
test_expect_success 'blame: --no-indent-heuristic overrides config' '
211-
git -c diff.indentHeuristic=true blame --no-indent-heuristic old..new -- spaces.txt >out-blame2 &&
220+
git -c diff.indentHeuristic=true blame --no-indent-heuristic old..new -- spaces.txt >out-blame3 &&
212221
git blame old..new -- spaces.txt >out-blame &&
213-
compare_blame spaces-expect out-blame2
222+
compare_blame spaces-expect out-blame3
223+
'
224+
225+
test_expect_success 'blame: --indent-heuristic overrides config' '
226+
git -c diff.indentHeuristic=false blame --indent-heuristic old..new -- spaces.txt >out-blame-compacted3 &&
227+
compare_blame spaces-compacted-expect out-blame-compacted2
228+
'
229+
230+
# --- diff-tree tests -----------------------------------------------------
231+
232+
test_expect_success 'diff-tree: nice spaces with --indent-heuristic' '
233+
git diff-tree --indent-heuristic -p old new -- spaces.txt >out-diff-tree-compacted &&
234+
compare_diff spaces-compacted-expect out-diff-tree-compacted
235+
'
236+
237+
test_expect_success 'diff-tree: nice spaces with diff.indentHeuristic=true' '
238+
git -c diff.indentHeuristic=true diff-tree -p old new -- spaces.txt >out-diff-tree-compacted2 &&
239+
compare_diff spaces-compacted-expect out-diff-tree-compacted2
240+
'
241+
242+
test_expect_success 'diff-tree: ugly spaces with --no-indent-heuristic' '
243+
git diff-tree --no-indent-heuristic -p old new -- spaces.txt >out-diff-tree &&
244+
compare_diff spaces-expect out-diff-tree
245+
'
246+
247+
test_expect_success 'diff-tree: ugly spaces with diff.indentHeuristic=false' '
248+
git -c diff.indentHeuristic=false diff-tree -p old new -- spaces.txt >out-diff-tree2 &&
249+
compare_diff spaces-expect out-diff-tree2
250+
'
251+
252+
test_expect_success 'diff-tree: --indent-heuristic overrides config' '
253+
git -c diff.indentHeuristic=false diff-tree --indent-heuristic -p old new -- spaces.txt >out-diff-tree-compacted3 &&
254+
compare_diff spaces-compacted-expect out-diff-tree-compacted3
255+
'
256+
257+
test_expect_success 'diff-tree: --no-indent-heuristic overrides config' '
258+
git -c diff.indentHeuristic=true diff-tree --no-indent-heuristic -p old new -- spaces.txt >out-diff-tree3 &&
259+
compare_diff spaces-expect out-diff-tree3
260+
'
261+
262+
# --- diff-index tests ----------------------------------------------------
263+
264+
test_expect_success 'diff-index: nice spaces with --indent-heuristic' '
265+
git checkout -B diff-index &&
266+
git reset --soft HEAD~ &&
267+
git diff-index --indent-heuristic -p old -- spaces.txt >out-diff-index-compacted &&
268+
compare_diff spaces-compacted-expect out-diff-index-compacted &&
269+
git checkout -f master
270+
'
271+
272+
test_expect_success 'diff-index: nice spaces with diff.indentHeuristic=true' '
273+
git checkout -B diff-index &&
274+
git reset --soft HEAD~ &&
275+
git -c diff.indentHeuristic=true diff-index -p old -- spaces.txt >out-diff-index-compacted2 &&
276+
compare_diff spaces-compacted-expect out-diff-index-compacted2 &&
277+
git checkout -f master
278+
'
279+
280+
test_expect_success 'diff-index: ugly spaces with --no-indent-heuristic' '
281+
git checkout -B diff-index &&
282+
git reset --soft HEAD~ &&
283+
git diff-index --no-indent-heuristic -p old -- spaces.txt >out-diff-index &&
284+
compare_diff spaces-expect out-diff-index &&
285+
git checkout -f master
286+
'
287+
288+
test_expect_success 'diff-index: ugly spaces with diff.indentHeuristic=false' '
289+
git checkout -B diff-index &&
290+
git reset --soft HEAD~ &&
291+
git -c diff.indentHeuristic=false diff-index -p old -- spaces.txt >out-diff-index2 &&
292+
compare_diff spaces-expect out-diff-index2 &&
293+
git checkout -f master
294+
'
295+
296+
test_expect_success 'diff-index: --indent-heuristic overrides config' '
297+
git checkout -B diff-index &&
298+
git reset --soft HEAD~ &&
299+
git -c diff.indentHeuristic=false diff-index --indent-heuristic -p old -- spaces.txt >out-diff-index-compacted3 &&
300+
compare_diff spaces-compacted-expect out-diff-index-compacted3 &&
301+
git checkout -f master
302+
'
303+
304+
test_expect_success 'diff-index: --no-indent-heuristic overrides config' '
305+
git checkout -B diff-index &&
306+
git reset --soft HEAD~ &&
307+
git -c diff.indentHeuristic=true diff-index --no-indent-heuristic -p old -- spaces.txt >out-diff-index3 &&
308+
compare_diff spaces-expect out-diff-index3 &&
309+
git checkout -f master
310+
'
311+
312+
# --- diff-files tests ----------------------------------------------------
313+
314+
test_expect_success 'diff-files: nice spaces with --indent-heuristic' '
315+
git checkout -B diff-files &&
316+
git reset HEAD~ &&
317+
git diff-files --indent-heuristic -p spaces.txt >out-diff-files-raw &&
318+
grep -v index out-diff-files-raw >out-diff-files-compacted &&
319+
compare_diff spaces-compacted-expect out-diff-files-compacted &&
320+
git checkout -f master
321+
'
322+
323+
test_expect_success 'diff-files: nice spaces with diff.indentHeuristic=true' '
324+
git checkout -B diff-files &&
325+
git reset HEAD~ &&
326+
git -c diff.indentHeuristic=true diff-files -p spaces.txt >out-diff-files-raw2 &&
327+
grep -v index out-diff-files-raw2 >out-diff-files-compacted2 &&
328+
compare_diff spaces-compacted-expect out-diff-files-compacted2 &&
329+
git checkout -f master
330+
'
331+
332+
test_expect_success 'diff-files: ugly spaces with --no-indent-heuristic' '
333+
git checkout -B diff-files &&
334+
git reset HEAD~ &&
335+
git diff-files --no-indent-heuristic -p spaces.txt >out-diff-files-raw &&
336+
grep -v index out-diff-files-raw >out-diff-files &&
337+
compare_diff spaces-expect out-diff-files &&
338+
git checkout -f master
339+
'
340+
341+
test_expect_success 'diff-files: ugly spaces with diff.indentHeuristic=false' '
342+
git checkout -B diff-files &&
343+
git reset HEAD~ &&
344+
git -c diff.indentHeuristic=false diff-files -p spaces.txt >out-diff-files-raw2 &&
345+
grep -v index out-diff-files-raw2 >out-diff-files &&
346+
compare_diff spaces-expect out-diff-files &&
347+
git checkout -f master
348+
'
349+
350+
test_expect_success 'diff-files: --indent-heuristic overrides config' '
351+
git checkout -B diff-files &&
352+
git reset HEAD~ &&
353+
git -c diff.indentHeuristic=false diff-files --indent-heuristic -p spaces.txt >out-diff-files-raw3 &&
354+
grep -v index out-diff-files-raw3 >out-diff-files-compacted &&
355+
compare_diff spaces-compacted-expect out-diff-files-compacted &&
356+
git checkout -f master
357+
'
358+
359+
test_expect_success 'diff-files: --no-indent-heuristic overrides config' '
360+
git checkout -B diff-files &&
361+
git reset HEAD~ &&
362+
git -c diff.indentHeuristic=true diff-files --no-indent-heuristic -p spaces.txt >out-diff-files-raw4 &&
363+
grep -v index out-diff-files-raw4 >out-diff-files &&
364+
compare_diff spaces-expect out-diff-files &&
365+
git checkout -f master
214366
'
215367

216368
test_done

0 commit comments

Comments
 (0)