From d79ea709b7a3cbe1540cc95d90f012d337778f83 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 27 Jul 2020 10:23:04 -0700 Subject: [PATCH] filter-repo: fix crash from assuming parent is an int MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Elijah Newren --- git-filter-repo | 5 ++++- t/t9390-filter-repo.sh | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/git-filter-repo b/git-filter-repo index 83c55cb..ac039ec 100755 --- a/git-filter-repo +++ b/git-filter-repo @@ -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': diff --git a/t/t9390-filter-repo.sh b/t/t9390-filter-repo.sh index 8f9d099..14bdeaa 100755 --- a/t/t9390-filter-repo.sh +++ b/t/t9390-filter-repo.sh @@ -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 && (