Skip to content

Commit cee6c5b

Browse files
committed
Merge branch 'jk/diff-do-not-reuse-wtf-needs-cleaning' into maint
There is an optimization used in "git diff $treeA $treeB" to borrow an already checked-out copy in the working tree when it is known to be the same as the blob being compared, expecting that open/mmap of such a file is faster than reading it from the object store, which involves inflating and applying delta. This however kicked in even when the checked-out copy needs to go through the convert-to-git conversion (including the clean filter), which defeats the whole point of the optimization. The optimization has been disabled when the conversion is necessary. * jk/diff-do-not-reuse-wtf-needs-cleaning: diff: do not reuse worktree files that need "clean" conversion
2 parents d1d9c3c + 06dec43 commit cee6c5b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

diff.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,6 +2682,13 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
26822682
if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(sha1))
26832683
return 0;
26842684

2685+
/*
2686+
* Similarly, if we'd have to convert the file contents anyway, that
2687+
* makes the optimization not worthwhile.
2688+
*/
2689+
if (!want_file && would_convert_to_git(name))
2690+
return 0;
2691+
26852692
len = strlen(name);
26862693
pos = cache_name_pos(name, len);
26872694
if (pos < 0)

t/t0021-conversion.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,15 @@ test_expect_success 'disable filter with empty override' '
268268
test_must_be_empty err
269269
'
270270

271+
test_expect_success 'diff does not reuse worktree files that need cleaning' '
272+
test_config filter.counter.clean "echo . >>count; sed s/^/clean:/" &&
273+
echo "file filter=counter" >.gitattributes &&
274+
test_commit one file &&
275+
test_commit two file &&
276+
277+
>count &&
278+
git diff-tree -p HEAD &&
279+
test_line_count = 0 count
280+
'
281+
271282
test_done

0 commit comments

Comments
 (0)