diff: have the diff-* builtins configure diff before initializing revisions

This matches how the diff Porcelain works. It makes the plumbing commands respect diff's configuration options, such as indentHeuristic, because init_revisions() calls diff_setup() which fills in the diff_options struct. Signed-off-by: Marc Branchaud <marcnarc@xiplink.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Marc Branchaud committed May 8, 2017 at 12:03 UTC 37590ce3c535f92e28da83893f843cc0099873bf
4 files changed +69 -3
builtin/diff-files.c
+1 -1
@@ -20,9 +20,9 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
20 int result;
21 unsigned options = 0;
22
23 + git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
24 init_revisions(&rev, prefix);
25 gitmodules_config();
25 - git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
26 rev.abbrev = 0;
27 precompose_argv(argc, argv);
28
builtin/diff-index.c
+1 -1
@@ -17,9 +17,9 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
17 int i;
18 int result;
19
20 + git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
21 init_revisions(&rev, prefix);
22 gitmodules_config();
22 - git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
23 rev.abbrev = 0;
24 precompose_argv(argc, argv);
25
builtin/diff-tree.c
+1 -1
@@ -105,9 +105,9 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
105 struct setup_revision_opt s_r_opt;
106 int read_stdin = 0;
107
108 + git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
109 init_revisions(opt, prefix);
110 gitmodules_config();
110 - git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
111 opt->abbrev = 0;
112 opt->diff = 1;
113 opt->disable_stdin = 1;
t/t4061-diff-indent.sh
+66
@@ -213,4 +213,70 @@ test_expect_success 'blame: --no-indent-heuristic overrides config' '
213 compare_blame spaces-expect out-blame2
214 '
215
216 +test_expect_success 'diff-tree: nice spaces with --indent-heuristic' '
217 + git diff-tree --indent-heuristic -p old new -- spaces.txt >out-diff-tree-compacted &&
218 + compare_diff spaces-compacted-expect out-diff-tree-compacted
219 +'
220 +
221 +test_expect_success 'diff-tree: nice spaces with diff.indentHeuristic' '
222 + git -c diff.indentHeuristic=true diff-tree -p old new -- spaces.txt >out-diff-tree-compacted2 &&
223 + compare_diff spaces-compacted-expect out-diff-tree-compacted2
224 +'
225 +
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 &&
228 + compare_diff spaces-expect out-diff-tree
229 +'
230 +
231 +test_expect_success 'diff-index: nice spaces with --indent-heuristic' '
232 + git checkout -B diff-index &&
233 + git reset --soft HEAD~ &&
234 + git diff-index --indent-heuristic -p old -- spaces.txt >out-diff-index-compacted &&
235 + compare_diff spaces-compacted-expect out-diff-index-compacted &&
236 + git checkout -f master
237 +'
238 +
239 +test_expect_success 'diff-index: nice spaces with diff.indentHeuristic' '
240 + git checkout -B diff-index &&
241 + git reset --soft HEAD~ &&
242 + git -c diff.indentHeuristic=true diff-index -p old -- spaces.txt >out-diff-index-compacted2 &&
243 + compare_diff spaces-compacted-expect out-diff-index-compacted2 &&
244 + git checkout -f master
245 +'
246 +
247 +test_expect_success 'diff-index: --no-indent-heuristic overrides config' '
248 + git checkout -B diff-index &&
249 + git reset --soft HEAD~ &&
250 + git -c diff.indentHeuristic=true diff-index --no-indent-heuristic -p old -- spaces.txt >out-diff-index &&
251 + compare_diff spaces-expect out-diff-index &&
252 + git checkout -f master
253 +'
254 +
255 +test_expect_success 'diff-files: nice spaces with diff.indentHeuristic' '
256 + git checkout -B diff-files &&
257 + git reset HEAD~ &&
258 + git -c diff.indentHeuristic=true diff-files -p spaces.txt >out-diff-files-raw &&
259 + grep -v index out-diff-files-raw >out-diff-files-compacted &&
260 + compare_diff spaces-compacted-expect out-diff-files-compacted &&
261 + git checkout -f master
262 +'
263 +
264 +test_expect_success 'diff-files: nice spaces with diff.indentHeuristic' '
265 + git checkout -B diff-files &&
266 + git reset HEAD~ &&
267 + git -c diff.indentHeuristic=true diff-files -p spaces.txt >out-diff-files-raw2 &&
268 + grep -v index out-diff-files-raw2 >out-diff-files-compacted2 &&
269 + compare_diff spaces-compacted-expect out-diff-files-compacted2 &&
270 + git checkout -f master
271 +'
272 +
273 +test_expect_success 'diff-files: --no-indent-heuristic overrides config' '
274 + git checkout -B diff-files &&
275 + 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 &&
278 + compare_diff spaces-expect out-diff-files &&
279 + git checkout -f master
280 +'
281 +
282 test_done