Skip to content

Commit

Permalink
filter-repo: fix crash from assuming parent is an int
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
newren committed Jul 27, 2020
1 parent 4b452da commit d79ea70
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion git-filter-repo
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
22 changes: 22 additions & 0 deletions t/t9390-filter-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
(
Expand Down

0 comments on commit d79ea70

Please sign in to comment.