Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 79bc4ef

Browse files
hashplinggitster
authored andcommitted
filter-branch: eliminate duplicate mapped parents
When multiple parents of a merge commit get mapped to the same commit, filter-branch used to pass all instances of the parent commit to the parent and commit filters and to "git commit-tree" or "git_commit_non_empty_tree". This can often happen when extracting a small project from a large repository; merges can join history with no commits on any branch which affect the paths being retained. Once the intermediate commits have been filtered out, all the immediate parents of the merge commit can end up being mapped to the same commit - either the original merge-base or an ancestor of it. "git commit-tree" would display an error but write the commit with the normalized parents in any case. "git_commit_non_empty_tree" would fail to notice that the commit being made was in fact a non-merge commit and would retain it even if a further pass with "--prune-empty" would discard the commit as empty. Ensure that duplicate parents are pruned before the parent filter to make "--prune-empty" idempotent, removing all empty non-merge commits in a singe pass. Signed-off-by: Charles Bailey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 341e7e8 commit 79bc4ef

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

git-filter-branch.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,13 @@ while read commit parents; do
332332
parentstr=
333333
for parent in $parents; do
334334
for reparent in $(map "$parent"); do
335-
parentstr="$parentstr -p $reparent"
335+
case "$parentstr " in
336+
*" -p $reparent "*)
337+
;;
338+
*)
339+
parentstr="$parentstr -p $reparent"
340+
;;
341+
esac
336342
done
337343
done
338344
if [ "$filter_parent" ]; then

t/t7003-filter-branch.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,17 @@ test_expect_success 'Prune empty commits' '
308308
test_cmp expect actual
309309
'
310310

311+
test_expect_success 'prune empty collapsed merges' '
312+
test_config merge.ff false &&
313+
git rev-list HEAD >expect &&
314+
test_commit to_remove_2 &&
315+
git reset --hard HEAD^ &&
316+
test_merge non-ff to_remove_2 &&
317+
git filter-branch -f --index-filter "git update-index --remove to_remove_2.t" --prune-empty HEAD &&
318+
git rev-list HEAD >actual &&
319+
test_cmp expect actual
320+
'
321+
311322
test_expect_success '--remap-to-ancestor with filename filters' '
312323
git checkout master &&
313324
git reset --hard A &&

0 commit comments

Comments
 (0)