diff: activate diff.renames by default

Rename detection is a very convenient feature, and new users shouldn't have to dig in the documentation to benefit from it. Potential objections to activating rename detection are that it sometimes fail, and it is sometimes slow. But rename detection is already activated by default in several cases like "git status" and "git merge", so activating diff.renames does not fundamentally change the situation. When the rename detection fails, it now fails consistently between "git diff" and "git status". This setting does not affect plumbing commands, hence well-written scripts will not be affected. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matthieu Moy committed Feb 25, 2016 at 09:59 UTC 5404c116aa921d7e2f9408e103c80b7801735d08
12 files changed +22 -9
Documentation/diff-config.txt
+1 -1
@@ -111,7 +111,7 @@ diff.renames::
111 Whether and how Git detects renames. If set to "false",
112 rename detection is disabled. If set to "true", basic rename
113 detection is enabled. If set to "copies" or "copy", Git will
114 - detect copies, as well. Defaults to false. Note that this
114 + detect copies, as well. Defaults to true. Note that this
115 affects only 'git diff' Porcelain like linkgit:git-diff[1] and
116 linkgit:git-log[1], and not lower level commands such as
117 linkgit:git-diff-files[1].
builtin/commit.c
+1
@@ -186,6 +186,7 @@ static void status_init_config(struct wt_status *s, config_fn_t fn)
186 gitmodules_config();
187 git_config(fn, s);
188 determine_whence(s);
189 + init_diff_ui_defaults();
190 s->hints = advice_status_hints; /* must come after git_config() */
191 }
192
builtin/diff.c
+1
@@ -318,6 +318,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
318
319 if (!no_index)
320 gitmodules_config();
321 + init_diff_ui_defaults();
322 git_config(git_diff_ui_config, NULL);
323
324 init_revisions(&rev, prefix);
builtin/log.c
+1
@@ -103,6 +103,7 @@ static int log_line_range_callback(const struct option *option, const char *arg,
103 static void init_log_defaults(void)
104 {
105 init_grep_defaults();
106 + init_diff_ui_defaults();
107 }
108
109 static void cmd_log_init_defaults(struct rev_info *rev)
builtin/merge.c
+1
@@ -1187,6 +1187,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1187 else
1188 head_commit = lookup_commit_or_die(head_sha1, "HEAD");
1189
1190 + init_diff_ui_defaults();
1191 git_config(git_merge_config, NULL);
1192
1193 if (branch_mergeoptions)
diff.c
+5
@@ -168,6 +168,11 @@ long parse_algorithm_value(const char *value)
168 * never be affected by the setting of diff.renames
169 * the user happens to have in the configuration file.
170 */
171 +void init_diff_ui_defaults(void)
172 +{
173 + diff_detect_rename_default = 1;
174 +}
175 +
176 int git_diff_ui_config(const char *var, const char *value, void *cb)
177 {
178 if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
diff.h
+1
@@ -266,6 +266,7 @@ extern int parse_long_opt(const char *opt, const char **argv,
266 const char **optarg);
267
268 extern int git_diff_basic_config(const char *var, const char *value, void *cb);
269 +extern void init_diff_ui_defaults(void);
270 extern int git_diff_ui_config(const char *var, const char *value, void *cb);
271 extern void diff_setup(struct diff_options *);
272 extern int diff_opt_parse(struct diff_options *, const char **, int, const char *);
t/t4001-diff-rename.sh
+1 -1
@@ -124,7 +124,7 @@ test_expect_success 'test diff.renames=false' '
124
125 test_expect_success 'test diff.renames unset' '
126 git diff --cached $tree >current &&
127 - compare_diff_patch current no-rename
127 + compare_diff_patch current expected
128 '
129
130 test_expect_success 'favour same basenames over different ones' '
t/t4013-diff-various.sh
+2
@@ -90,6 +90,8 @@ test_expect_success setup '
90 git commit -m "Rearranged lines in dir/sub" &&
91 git checkout master &&
92
93 + git config diff.renames false &&
94 +
95 git show-branch
96 '
97
t/t4014-format-patch.sh
+2 -2
@@ -549,7 +549,7 @@ test_expect_success 'cover-letter inherits diff options' '
549
550 git mv file foo &&
551 git commit -m foo &&
552 - git format-patch --cover-letter -1 &&
552 + git format-patch --no-renames --cover-letter -1 &&
553 check_patch 0000-cover-letter.patch &&
554 ! grep "file => foo .* 0 *\$" 0000-cover-letter.patch &&
555 git format-patch --cover-letter -1 -M &&
@@ -703,7 +703,7 @@ test_expect_success 'options no longer allowed for format-patch' '
703
704 test_expect_success 'format-patch --numstat should produce a patch' '
705 git format-patch --numstat --stdout master..side > output &&
706 - test 6 = $(grep "^diff --git a/" output | wc -l)'
706 + test 5 = $(grep "^diff --git a/" output | wc -l)'
707
708 test_expect_success 'format-patch -- <path>' '
709 git format-patch master..side -- file 2>error &&
t/t4047-diff-dirstat.sh
+2 -1
@@ -248,7 +248,8 @@ EOF
248 git rm -r src/move/unchanged &&
249 git rm -r src/move/changed &&
250 git rm -r src/move/rearranged &&
251 - git commit -m "changes"
251 + git commit -m "changes" &&
252 + git config diff.renames false
253 '
254
255 cat <<EOF >expect_diff_stat
t/t4202-log.sh
+4 -4
@@ -101,8 +101,8 @@ test_expect_success 'oneline' '
101
102 test_expect_success 'diff-filter=A' '
103
104 - git log --pretty="format:%s" --diff-filter=A HEAD > actual &&
105 - git log --pretty="format:%s" --diff-filter A HEAD > actual-separate &&
104 + git log --no-renames --pretty="format:%s" --diff-filter=A HEAD > actual &&
105 + git log --no-renames --pretty="format:%s" --diff-filter A HEAD > actual-separate &&
106 printf "fifth\nfourth\nthird\ninitial" > expect &&
107 test_cmp expect actual &&
108 test_cmp expect actual-separate
@@ -119,7 +119,7 @@ test_expect_success 'diff-filter=M' '
119
120 test_expect_success 'diff-filter=D' '
121
122 - actual=$(git log --pretty="format:%s" --diff-filter=D HEAD) &&
122 + actual=$(git log --no-renames --pretty="format:%s" --diff-filter=D HEAD) &&
123 expect=$(echo sixth ; echo third) &&
124 verbose test "$actual" = "$expect"
125
@@ -848,7 +848,7 @@ sanitize_output () {
848 }
849
850 test_expect_success 'log --graph with diff and stats' '
851 - git log --graph --pretty=short --stat -p >actual &&
851 + git log --no-renames --graph --pretty=short --stat -p >actual &&
852 sanitize_output >actual.sanitized <actual &&
853 test_i18ncmp expect actual.sanitized
854 '