Skip to content

Commit d79ea70

Browse files
committed
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 <[email protected]> Signed-off-by: Elijah Newren <[email protected]>
1 parent 4b452da commit d79ea70

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

git-filter-repo

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3191,7 +3191,10 @@ class RepoFilter(object):
31913191
for change in commit.file_changes:
31923192
parent = new_1st_parent or commit.parents[0] # exists due to above checks
31933193
quoted_filename = PathQuoting.enquote(change.filename)
3194-
self._output.write(b"ls :%d %s\n" % (parent, quoted_filename))
3194+
if isinstance(parent, int):
3195+
self._output.write(b"ls :%d %s\n" % (parent, quoted_filename))
3196+
else:
3197+
self._output.write(b"ls %s %s\n" % (parent, quoted_filename))
31953198
self._output.flush()
31963199
parent_version = fi_output.readline().split()
31973200
if change.type == b'D':

t/t9390-filter-repo.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,28 @@ test_expect_success '--refs' '
13241324
test_cmp refs/expect refs/actual
13251325
'
13261326

1327+
test_expect_success '--refs and --replace-text' '
1328+
# This test exists to make sure we do not assume that parents in
1329+
# filter-repo code are always represented by integers (or marks);
1330+
# they sometimes are represented as hashes.
1331+
setup_path_rename &&
1332+
(
1333+
git clone file://"$(pwd)"/path_rename refs_and_replace_text &&
1334+
cd refs_and_replace_text &&
1335+
git rev-parse --short=10 HEAD~1 >myparent &&
1336+
git filter-repo --force --replace-text <(echo "10==>TEN") --refs $(cat myparent)..master &&
1337+
cat <<-EOF >expect &&
1338+
TEN11
1339+
EOF
1340+
test_cmp expect sequences/medium &&
1341+
git rev-list --count HEAD >actual &&
1342+
echo 4 >expect &&
1343+
test_cmp expect actual &&
1344+
git rev-parse --short=10 HEAD~1 >actual &&
1345+
test_cmp myparent actual
1346+
)
1347+
'
1348+
13271349
test_expect_success 'reset to specific refs' '
13281350
test_create_repo reset_to_specific_refs &&
13291351
(

0 commit comments

Comments
 (0)