filter-repo: fix crash from assuming parent is an int

When filtering with --refs, parents can be a hash rather than an
integer.  There was a code path in RepoFilter._prunable() that was
written assuming the first parent would always be an integer; fix it to
handle a hash as well.

Reported-by: Niklas Hambüchen <mail@nh2.me>
Signed-off-by: Elijah Newren <newren@gmail.com>
pull/135/head v2.28.0
Elijah Newren 4 years ago
parent 4b452da4ef
commit d79ea709b7

@ -3191,7 +3191,10 @@ class RepoFilter(object):
for change in commit.file_changes:
parent = new_1st_parent or commit.parents[0] # exists due to above checks
quoted_filename = PathQuoting.enquote(change.filename)
self._output.write(b"ls :%d %s\n" % (parent, quoted_filename))
if isinstance(parent, int):
self._output.write(b"ls :%d %s\n" % (parent, quoted_filename))
else:
self._output.write(b"ls %s %s\n" % (parent, quoted_filename))
self._output.flush()
parent_version = fi_output.readline().split()
if change.type == b'D':

@ -1324,6 +1324,28 @@ test_expect_success '--refs' '
test_cmp refs/expect refs/actual
'
test_expect_success '--refs and --replace-text' '
# This test exists to make sure we do not assume that parents in
# filter-repo code are always represented by integers (or marks);
# they sometimes are represented as hashes.
setup_path_rename &&
(
git clone file://"$(pwd)"/path_rename refs_and_replace_text &&
cd refs_and_replace_text &&
git rev-parse --short=10 HEAD~1 >myparent &&
git filter-repo --force --replace-text <(echo "10==>TEN") --refs $(cat myparent)..master &&
cat <<-EOF >expect &&
TEN11
EOF
test_cmp expect sequences/medium &&
git rev-list --count HEAD >actual &&
echo 4 >expect &&
test_cmp expect actual &&
git rev-parse --short=10 HEAD~1 >actual &&
test_cmp myparent actual
)
'
test_expect_success 'reset to specific refs' '
test_create_repo reset_to_specific_refs &&
(

Loading…
Cancel
Save