Mercurial > hg
diff hgext/rebase.py @ 35058:a68c3420be41
rebase: exclude descendants of obsoletes w/o a successor in dest (issue5300)
.. feature::
Let 'hg rebase' avoid content-divergence by skipping obsolete
changesets (and their descendants) when they are present in the rebase
set along with one of their successors but none of their successors is
in destination.
In the following example, when trying to rebase 3:: onto 2, the rebase
will abort with "this rebase will cause divergence from: 4":
o 7 f
|
| o 6 e
| |
| o 5 d'
| |
x | 4 d (rewritten as 5)
|/
o 3 c
|
| o 2 x
| |
o | 1 b
|/
o 0 a
By excluding obsolete changesets without a successor in destination (4
in the example above) and their descendants, we make rebase work in this
case, thus giving:
o 11 e
|
o 10 d'
|
o 9 c
|
o 8 b
|
| o 7 f
| |
| | x 6 e (rewritten using rebase as 11)
| | |
| | x 5 d' (rewritten using rebase as 10)
| | |
| x | 4 d
| |/
| x 3 c (rewritten using rebase as 9)
| |
o | 2 x
| |
| x 1 b (rewritten using rebase as 8)
|/
o 0 a
where branch 4:: is left behind while branch 5:: is rebased as expected.
The rationale is that users may not be interested in rebasing orphan
changesets when specifying a rebase set that include them but would
still want "stable" ones to be rebased. Currently, the user is suggested
to allow divergence (but probably does not want it) or they must specify
a rebase set excluding problematic changesets (which might be a bit
cumbersome). The approach proposed here corresponds to "Option 2" in
https://www.mercurial-scm.org/wiki/CEDRebase.
We extend _computeobsoletenotrebased() so that it also return a set of
obsolete changesets in rebase set without a successor in destination but
with at least one successor in rebase set. This
'obsoletewithoutsuccessorindestination' is then stored as an attribute
of rebaseruntime and used in _performrebasesubset() to:
* filter out descendants of these changesets from the revisions to
rebase;
* issue a message about these revisions being skipped.
This only occurs if 'evolution.allowdivergence' option is off and
'rebaseskipobsolete' is on.
author | Denis Laxalde <denis@laxalde.org> |
---|---|
date | Tue, 14 Nov 2017 22:46:10 +0100 |
parents | 1a07f9187831 |
children | f56a30b844aa |
line wrap: on
line diff
--- a/hgext/rebase.py Sat Nov 11 19:25:32 2017 +0100 +++ b/hgext/rebase.py Tue Nov 14 22:46:10 2017 +0100 @@ -179,6 +179,7 @@ # other extensions self.keepopen = opts.get('keepopen', False) self.obsoletenotrebased = {} + self.obsoletewithoutsuccessorindestination = set() @property def repo(self): @@ -311,9 +312,10 @@ if not self.ui.configbool('experimental', 'rebaseskipobsolete'): return obsoleteset = set(obsoleterevs) - self.obsoletenotrebased = _computeobsoletenotrebased(self.repo, - obsoleteset, destmap) + self.obsoletenotrebased, self.obsoletewithoutsuccessorindestination = \ + _computeobsoletenotrebased(self.repo, obsoleteset, destmap) skippedset = set(self.obsoletenotrebased) + skippedset.update(self.obsoletewithoutsuccessorindestination) _checkobsrebase(self.repo, self.ui, obsoleteset, skippedset) def _prepareabortorcontinue(self, isabort): @@ -419,12 +421,26 @@ def _performrebasesubset(self, tr, subset, pos, total): repo, ui, opts = self.repo, self.ui, self.opts sortedrevs = repo.revs('sort(%ld, -topo)', subset) + allowdivergence = self.ui.configbool( + 'experimental', 'evolution.allowdivergence') + if not allowdivergence: + sortedrevs -= repo.revs( + 'descendants(%ld) and not %ld', + self.obsoletewithoutsuccessorindestination, + self.obsoletewithoutsuccessorindestination, + ) for rev in sortedrevs: dest = self.destmap[rev] ctx = repo[rev] desc = _ctxdesc(ctx) if self.state[rev] == rev: ui.status(_('already rebased %s\n') % desc) + elif (not allowdivergence + and rev in self.obsoletewithoutsuccessorindestination): + msg = _('note: not rebasing %s and its descendants as ' + 'this would cause divergence\n') % desc + repo.ui.status(msg) + self.skipped.add(rev) elif rev in self.obsoletenotrebased: succ = self.obsoletenotrebased[rev] if succ is None: @@ -1616,11 +1632,16 @@ return set(r for r in revs if repo[r].obsolete()) def _computeobsoletenotrebased(repo, rebaseobsrevs, destmap): - """return a mapping obsolete => successor for all obsolete nodes to be - rebased that have a successors in the destination + """Return (obsoletenotrebased, obsoletewithoutsuccessorindestination). + + `obsoletenotrebased` is a mapping mapping obsolete => successor for all + obsolete nodes to be rebased given in `rebaseobsrevs`. - obsolete => None entries in the mapping indicate nodes with no successor""" + `obsoletewithoutsuccessorindestination` is a set with obsolete revisions + without a successor in destination. + """ obsoletenotrebased = {} + obsoletewithoutsuccessorindestination = set([]) assert repo.filtername is None cl = repo.changelog @@ -1641,8 +1662,15 @@ if cl.isancestor(succnode, destnode): obsoletenotrebased[srcrev] = nodemap[succnode] break + else: + # If 'srcrev' has a successor in rebase set but none in + # destination (which would be catched above), we shall skip it + # and its descendants to avoid divergence. + if any(nodemap[s] in destmap + for s in successors if s != srcnode): + obsoletewithoutsuccessorindestination.add(srcrev) - return obsoletenotrebased + return obsoletenotrebased, obsoletewithoutsuccessorindestination def summaryhook(ui, repo): if not repo.vfs.exists('rebasestate'):