filter-repo: fix --prune-degenerate=never with path filtering

When combining `--prune-degenerate never` with a `--path` specification,
we could end up trying to write a parent out to the fast-import stream
whose value was actually None.  The problem occurs when the parents of
a merge commit are filtered out by the path specification, leaving us
only with no-longer-extant parents.  In such a case, we need to filter
out these 'None' (i.e. invalid) parents.  The point of
`--prune-degenerate never` is to avoid removing parents that are either
the same as or an ancestor of another parent, not to avoid removing
non-existent parents.  Remove the non-existent parent(s).

Reported-by: Gaurav Kanoongo (@gauravkanoongo on GitHub)
Signed-off-by: Elijah Newren <newren@gmail.com>
pull/101/head
Elijah Newren 4 years ago
parent df6c8652a2
commit 7b18e6d7f5

@ -3025,8 +3025,6 @@ class RepoFilter(object):
Returns a tuple:
(parents, new_first_parent_if_would_become_non_merge)'''
if self._args.prune_degenerate == 'never':
return parents, None
always_prune = (self._args.prune_degenerate == 'always')
# Pruning of empty commits means multiple things:
@ -3051,6 +3049,10 @@ class RepoFilter(object):
if len(parents) < 2:
return parents, None
# Don't remove redundant parents if user doesn't want us to
if self._args.prune_degenerate == 'never':
return parents, None
# Remove duplicate parents (if both sides of history have lots of commits
# which become empty due to pruning, the most recent ancestor on both
# sides may be the same commit), except only remove parents that have

Loading…
Cancel
Save