Skip to content

Commit 1e3fb46

Browse files
committed
Merge branch 'en/diff-rename-follow-fix' into seen
* en/diff-rename-follow-fix: diffcore-rename: fix BUG when break detection and --follow used together
2 parents 90b5c8b + 05f9b59 commit 1e3fb46

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,22 @@ test_expect_success 'validate the output.' '
5454
compare_diff_patch current expected
5555
'
5656

57+
test_expect_success 'log --follow -B does not die or use uninitialized memory' '
58+
git switch --orphan break_and_follow_are_icky_so_use_both &&
59+
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 &&
60+
git add z &&
61+
git commit -m "Initial" &&
62+
63+
test_seq 1 130 >z &&
64+
echo lame >somefile &&
65+
git add z somefile &&
66+
git commit -m "Rewrite z, introduce lame somefile" &&
67+
68+
echo Content >somefile &&
69+
git add somefile &&
70+
git commit -m "Rewrite somefile" &&
71+
72+
git log -B --follow somefile
73+
'
74+
5775
test_done

0 commit comments

Comments
 (0)