Skip to content

Commit b9b404f

Browse files
committed
Merge branch 'en/diff-rename-follow-fix'
A corner-case bug in "git log --follow -B" has been fixed. * en/diff-rename-follow-fix: diffcore-rename: fix BUG when break detection and --follow used together
2 parents 27fe152 + 554051d commit b9b404f

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

diffcore-rename.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static struct diff_rename_dst *locate_rename_dst(struct diff_filepair *p)
3333
{
3434
/* Lookup by p->ONE->path */
3535
int idx = break_idx ? strintmap_get(break_idx, p->one->path) : -1;
36-
return (idx == -1) ? NULL : &rename_dst[idx];
36+
return (idx == -1 || idx == rename_dst_nr) ? NULL : &rename_dst[idx];
3737
}
3838

3939
/*
@@ -1669,9 +1669,10 @@ void diffcore_rename_extended(struct diff_options *options,
16691669
if (DIFF_PAIR_BROKEN(p)) {
16701670
/* broken delete */
16711671
struct diff_rename_dst *dst = locate_rename_dst(p);
1672-
if (!dst)
1673-
BUG("tracking failed somehow; failed to find associated dst for broken pair");
1674-
if (dst->is_rename)
1672+
if (options->single_follow && dst &&
1673+
strcmp(dst->p->two->path, p->two->path))
1674+
dst = NULL;
1675+
if (dst && dst->is_rename)
16751676
/* counterpart is now rename/copy */
16761677
pair_to_free = p;
16771678
}

t/t4206-log-follow-harder-copies.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,36 @@ test_expect_success 'validate the output.' '
5454
compare_diff_patch current expected
5555
'
5656

57+
test_expect_success 'log --follow -B does not BUG' '
58+
git switch --orphan break_and_follow_are_icky_so_use_both &&
59+
60+
test_seq 1 127 >numbers &&
61+
git add numbers &&
62+
git commit -m "numbers" &&
63+
64+
printf "%s\n" A B C D E F G H I J K L M N O Q R S T U V W X Y Z >pool &&
65+
echo changed >numbers &&
66+
git add pool numbers &&
67+
git commit -m "pool" &&
68+
69+
git log -1 -B --raw --follow -- "p*"
70+
'
71+
72+
test_expect_success 'log --follow -B does not die or use uninitialized memory' '
73+
printf "%s\n" A B C D E F G H I J K L M N O P Q R S T U V W X Y Z >z &&
74+
git add z &&
75+
git commit -m "Initial" &&
76+
77+
test_seq 1 130 >z &&
78+
echo lame >somefile &&
79+
git add z somefile &&
80+
git commit -m "Rewrite z, introduce lame somefile" &&
81+
82+
echo Content >somefile &&
83+
git add somefile &&
84+
git commit -m "Rewrite somefile" &&
85+
86+
git log -B --follow somefile
87+
'
88+
5789
test_done

0 commit comments

Comments
 (0)