Skip to content

Commit a0919ce

Browse files
committed
Avoid "diff-index --cached" optimization under --find-copies-harder
When find-copies-harder is in effect, the diff frontends are expected to feed all paths, not just changed paths, to the diffcore, so that copy sources can be picked up. In such a case, not descending into subtrees using the cache-tree information is simply wrong. Signed-off-by: Junio C Hamano <[email protected]>
1 parent b65982b commit a0919ce

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

diff-lib.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ int run_diff_index(struct rev_info *revs, int cached)
446446
memset(&opts, 0, sizeof(opts));
447447
opts.head_idx = 1;
448448
opts.index_only = cached;
449-
opts.diff_index_cached = cached;
449+
opts.diff_index_cached = (cached &&
450+
!DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER));
450451
opts.merge = 1;
451452
opts.fn = oneway_diff;
452453
opts.unpack_data = revs;
@@ -503,7 +504,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
503504
memset(&opts, 0, sizeof(opts));
504505
opts.head_idx = 1;
505506
opts.index_only = 1;
506-
opts.diff_index_cached = 1;
507+
opts.diff_index_cached = !DIFF_OPT_TST(opt, FIND_COPIES_HARDER);
507508
opts.merge = 1;
508509
opts.fn = oneway_diff;
509510
opts.unpack_data = &revs;

t/t4007-rename-3.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ test_expect_success 'copy detection' '
3535
compare_diff_raw current expected
3636
'
3737

38+
test_expect_success 'copy detection, cached' '
39+
git diff-index -C --find-copies-harder --cached $tree >current &&
40+
compare_diff_raw current expected
41+
'
42+
3843
# In the tree, there is only path0/COPYING. In the cache, path0 and
3944
# path1 both have COPYING and the latter is a copy of path0/COPYING.
4045
# However when we say we care only about path1, we should just see

0 commit comments

Comments
 (0)