Skip to content

Commit 33de716

Browse files
stefanbellergitster
authored andcommitted
diff: enable indent heuristic by default
The feature was included in v2.11 (released 2016-11-29) and we got no negative feedback. Quite the opposite, all feedback we got was positive. Turn it on by default. Users who dislike the feature can turn it off by setting diff.indentHeuristic (which also configures plumbing commands, see prior patches). The change to t/t4051-diff-function-context.sh is needed because the heuristic shifts the changed hunk in the patch. To get the same result regardless of the heuristic configuration, we modify the test file differently: We insert a completely new line after line 2, instead of simply duplicating it. Helped-by: Jeff King <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Marc Branchaud <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 37590ce commit 33de716

File tree

3 files changed

+116
-29
lines changed

3 files changed

+116
-29
lines changed

diff.c

Lines changed: 1 addition & 1 deletion
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;

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: 113 additions & 27 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,42 +194,73 @@ 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
214223
'
215224

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+
216232
test_expect_success 'diff-tree: nice spaces with --indent-heuristic' '
217233
git diff-tree --indent-heuristic -p old new -- spaces.txt >out-diff-tree-compacted &&
218234
compare_diff spaces-compacted-expect out-diff-tree-compacted
219235
'
220236

221-
test_expect_success 'diff-tree: nice spaces with diff.indentHeuristic' '
237+
test_expect_success 'diff-tree: nice spaces with diff.indentHeuristic=true' '
222238
git -c diff.indentHeuristic=true diff-tree -p old new -- spaces.txt >out-diff-tree-compacted2 &&
223239
compare_diff spaces-compacted-expect out-diff-tree-compacted2
224240
'
225241

226-
test_expect_success 'diff-tree: --no-indent-heuristic overrides config' '
227-
git -c diff.indentHeuristic=true diff-tree --no-indent-heuristic -p old new -- spaces.txt >out-diff-tree &&
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 &&
228244
compare_diff spaces-expect out-diff-tree
229245
'
230246

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+
231264
test_expect_success 'diff-index: nice spaces with --indent-heuristic' '
232265
git checkout -B diff-index &&
233266
git reset --soft HEAD~ &&
@@ -236,32 +269,58 @@ test_expect_success 'diff-index: nice spaces with --indent-heuristic' '
236269
git checkout -f master
237270
'
238271

239-
test_expect_success 'diff-index: nice spaces with diff.indentHeuristic' '
272+
test_expect_success 'diff-index: nice spaces with diff.indentHeuristic=true' '
240273
git checkout -B diff-index &&
241274
git reset --soft HEAD~ &&
242275
git -c diff.indentHeuristic=true diff-index -p old -- spaces.txt >out-diff-index-compacted2 &&
243276
compare_diff spaces-compacted-expect out-diff-index-compacted2 &&
244277
git checkout -f master
245278
'
246279

247-
test_expect_success 'diff-index: --no-indent-heuristic overrides config' '
280+
test_expect_success 'diff-index: ugly spaces with --no-indent-heuristic' '
248281
git checkout -B diff-index &&
249282
git reset --soft HEAD~ &&
250-
git -c diff.indentHeuristic=true diff-index --no-indent-heuristic -p old -- spaces.txt >out-diff-index &&
283+
git diff-index --no-indent-heuristic -p old -- spaces.txt >out-diff-index &&
251284
compare_diff spaces-expect out-diff-index &&
252285
git checkout -f master
253286
'
254287

255-
test_expect_success 'diff-files: nice spaces with diff.indentHeuristic' '
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' '
256315
git checkout -B diff-files &&
257316
git reset HEAD~ &&
258-
git -c diff.indentHeuristic=true diff-files -p spaces.txt >out-diff-files-raw &&
317+
git diff-files --indent-heuristic -p spaces.txt >out-diff-files-raw &&
259318
grep -v index out-diff-files-raw >out-diff-files-compacted &&
260319
compare_diff spaces-compacted-expect out-diff-files-compacted &&
261320
git checkout -f master
262321
'
263322

264-
test_expect_success 'diff-files: nice spaces with diff.indentHeuristic' '
323+
test_expect_success 'diff-files: nice spaces with diff.indentHeuristic=true' '
265324
git checkout -B diff-files &&
266325
git reset HEAD~ &&
267326
git -c diff.indentHeuristic=true diff-files -p spaces.txt >out-diff-files-raw2 &&
@@ -270,11 +329,38 @@ test_expect_success 'diff-files: nice spaces with diff.indentHeuristic' '
270329
git checkout -f master
271330
'
272331

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+
273359
test_expect_success 'diff-files: --no-indent-heuristic overrides config' '
274360
git checkout -B diff-files &&
275361
git reset HEAD~ &&
276-
git -c diff.indentHeuristic=true diff-files --no-indent-heuristic -p spaces.txt >out-diff-files-raw3 &&
277-
grep -v index out-diff-files-raw3 >out-diff-files &&
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 &&
278364
compare_diff spaces-expect out-diff-files &&
279365
git checkout -f master
280366
'

0 commit comments

Comments
 (0)