Skip to content

Commit 5404c11

Browse files
moygitster
authored andcommitted
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>
1 parent 9501d19 commit 5404c11

12 files changed

+22
-9
lines changed

Documentation/diff-config.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ diff.renames::
111111
Whether and how Git detects renames. If set to "false",
112112
rename detection is disabled. If set to "true", basic rename
113113
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
115115
affects only 'git diff' Porcelain like linkgit:git-diff[1] and
116116
linkgit:git-log[1], and not lower level commands such as
117117
linkgit:git-diff-files[1].

builtin/commit.c

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ static void status_init_config(struct wt_status *s, config_fn_t fn)
186186
gitmodules_config();
187187
git_config(fn, s);
188188
determine_whence(s);
189+
init_diff_ui_defaults();
189190
s->hints = advice_status_hints; /* must come after git_config() */
190191
}
191192

builtin/diff.c

+1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
318318

319319
if (!no_index)
320320
gitmodules_config();
321+
init_diff_ui_defaults();
321322
git_config(git_diff_ui_config, NULL);
322323

323324
init_revisions(&rev, prefix);

builtin/log.c

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ static int log_line_range_callback(const struct option *option, const char *arg,
103103
static void init_log_defaults(void)
104104
{
105105
init_grep_defaults();
106+
init_diff_ui_defaults();
106107
}
107108

108109
static void cmd_log_init_defaults(struct rev_info *rev)

builtin/merge.c

+1
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
11871187
else
11881188
head_commit = lookup_commit_or_die(head_sha1, "HEAD");
11891189

1190+
init_diff_ui_defaults();
11901191
git_config(git_merge_config, NULL);
11911192

11921193
if (branch_mergeoptions)

diff.c

+5
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ long parse_algorithm_value(const char *value)
168168
* never be affected by the setting of diff.renames
169169
* the user happens to have in the configuration file.
170170
*/
171+
void init_diff_ui_defaults(void)
172+
{
173+
diff_detect_rename_default = 1;
174+
}
175+
171176
int git_diff_ui_config(const char *var, const char *value, void *cb)
172177
{
173178
if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {

diff.h

+1
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ extern int parse_long_opt(const char *opt, const char **argv,
266266
const char **optarg);
267267

268268
extern int git_diff_basic_config(const char *var, const char *value, void *cb);
269+
extern void init_diff_ui_defaults(void);
269270
extern int git_diff_ui_config(const char *var, const char *value, void *cb);
270271
extern void diff_setup(struct diff_options *);
271272
extern int diff_opt_parse(struct diff_options *, const char **, int, const char *);

t/t4001-diff-rename.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ test_expect_success 'test diff.renames=false' '
124124

125125
test_expect_success 'test diff.renames unset' '
126126
git diff --cached $tree >current &&
127-
compare_diff_patch current no-rename
127+
compare_diff_patch current expected
128128
'
129129

130130
test_expect_success 'favour same basenames over different ones' '

t/t4013-diff-various.sh

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ test_expect_success setup '
9090
git commit -m "Rearranged lines in dir/sub" &&
9191
git checkout master &&
9292
93+
git config diff.renames false &&
94+
9395
git show-branch
9496
'
9597

t/t4014-format-patch.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ test_expect_success 'cover-letter inherits diff options' '
549549
550550
git mv file foo &&
551551
git commit -m foo &&
552-
git format-patch --cover-letter -1 &&
552+
git format-patch --no-renames --cover-letter -1 &&
553553
check_patch 0000-cover-letter.patch &&
554554
! grep "file => foo .* 0 *\$" 0000-cover-letter.patch &&
555555
git format-patch --cover-letter -1 -M &&
@@ -703,7 +703,7 @@ test_expect_success 'options no longer allowed for format-patch' '
703703

704704
test_expect_success 'format-patch --numstat should produce a patch' '
705705
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)'
707707

708708
test_expect_success 'format-patch -- <path>' '
709709
git format-patch master..side -- file 2>error &&

t/t4047-diff-dirstat.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ EOF
248248
git rm -r src/move/unchanged &&
249249
git rm -r src/move/changed &&
250250
git rm -r src/move/rearranged &&
251-
git commit -m "changes"
251+
git commit -m "changes" &&
252+
git config diff.renames false
252253
'
253254

254255
cat <<EOF >expect_diff_stat

t/t4202-log.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ test_expect_success 'oneline' '
101101

102102
test_expect_success 'diff-filter=A' '
103103
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 &&
106106
printf "fifth\nfourth\nthird\ninitial" > expect &&
107107
test_cmp expect actual &&
108108
test_cmp expect actual-separate
@@ -119,7 +119,7 @@ test_expect_success 'diff-filter=M' '
119119

120120
test_expect_success 'diff-filter=D' '
121121
122-
actual=$(git log --pretty="format:%s" --diff-filter=D HEAD) &&
122+
actual=$(git log --no-renames --pretty="format:%s" --diff-filter=D HEAD) &&
123123
expect=$(echo sixth ; echo third) &&
124124
verbose test "$actual" = "$expect"
125125
@@ -848,7 +848,7 @@ sanitize_output () {
848848
}
849849

850850
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 &&
852852
sanitize_output >actual.sanitized <actual &&
853853
test_i18ncmp expect actual.sanitized
854854
'

0 commit comments

Comments
 (0)