Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit aba4727

Browse files
trastgitster
authored andcommitted
diff: do not reuse_worktree_file for submodules
The GIT_EXTERNAL_DIFF calling code attempts to reuse existing worktree files for the worktree side of diffs, for performance reasons. However, that code also tries to do the same with submodules. This results in calls to $GIT_EXTERNAL_DIFF where the old-file is a file of the form "Submodule commit $sha1", but the new-file is a directory in the worktree. Fix it by never reusing a worktree "file" in the submodule case. Reported-by: Grégory Pakosz <[email protected]> Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2f93541 commit aba4727

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

diff.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,8 +2842,9 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
28422842
remove_tempfile_installed = 1;
28432843
}
28442844

2845-
if (!one->sha1_valid ||
2846-
reuse_worktree_file(name, one->sha1, 1)) {
2845+
if (!S_ISGITLINK(one->mode) &&
2846+
(!one->sha1_valid ||
2847+
reuse_worktree_file(name, one->sha1, 1))) {
28472848
struct stat st;
28482849
if (lstat(name, &st) < 0) {
28492850
if (errno == ENOENT)

t/t4020-diff-external.sh

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,45 @@ keep_only_cr () {
213213
}
214214

215215
test_expect_success 'external diff with autocrlf = true' '
216-
git config core.autocrlf true &&
216+
test_config core.autocrlf true &&
217217
GIT_EXTERNAL_DIFF=./fake-diff.sh git diff &&
218218
test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)
219219
'
220220

221221
test_expect_success 'diff --cached' '
222+
test_config core.autocrlf true &&
222223
git add file &&
223224
git update-index --assume-unchanged file &&
224225
echo second >file &&
225226
git diff --cached >actual &&
226227
test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
227228
'
228229

230+
test_expect_success 'clean up crlf leftovers' '
231+
git update-index --no-assume-unchanged file &&
232+
rm -f file* &&
233+
git reset --hard
234+
'
235+
236+
test_expect_success 'submodule diff' '
237+
git init sub &&
238+
( cd sub && test_commit sub1 ) &&
239+
git add sub &&
240+
test_tick &&
241+
git commit -m "add submodule" &&
242+
( cd sub && test_commit sub2 ) &&
243+
write_script gather_pre_post.sh <<-\EOF &&
244+
echo "$1 $4" # path, mode
245+
cat "$2" # old file
246+
cat "$5" # new file
247+
EOF
248+
GIT_EXTERNAL_DIFF=./gather_pre_post.sh git diff >actual &&
249+
cat >expected <<-EOF &&
250+
sub 160000
251+
Subproject commit $(git rev-parse HEAD:sub)
252+
Subproject commit $(cd sub && git rev-parse HEAD)
253+
EOF
254+
test_cmp expected actual
255+
'
256+
229257
test_done

0 commit comments

Comments
 (0)