Commit 462f8322 authored by Sushil Khanchi's avatar Sushil Khanchi 🐨
Browse files

evolve: add pre-check logic for creation of phase divergence locally

Changes in tests reflect the added behaviour.
parent edd40c8b3dc1
Pipeline #2066 passed with stage
in 5 minutes and 13 seconds
......@@ -22,6 +22,7 @@ from mercurial import (
node,
obsolete,
obsutil,
phases,
revset,
util,
)
......@@ -79,12 +80,18 @@ def precheck(repo, revs, action=b'rewrite'):
divrisk = revs_hascontentdivrisk(repo, revs)
allowdivergence = repo.ui.configbool(b'experimental',
b'evolution.allowdivergence')
divhint = _(b"For more, see 'hg help evolution.instability'")
if divrisk and not allowdivergence:
msg = _(b"revision being rewritten or one of its precursor was "
b"rewritten as %s, performing '%s' will create "
b"content-divergence") % (repo[divrisk[0]], action)
hint = _(b"For more, see 'hg help evolution.instability'")
raise error.Abort(msg, hint=hint)
raise error.Abort(msg, hint=divhint)
pdivrisk = phasedivrisk(repo, revs)
if pdivrisk and not allowdivergence:
msg = _(b"revision being rewritten has a public predecessor %s, "
b"performing '%s' will create phase-divergence")
msg = msg % (repo[pdivrisk[0]], action)
raise error.Abort(msg, hint=divhint)
def bookmarksupdater(repo, oldid, tr):
"""Return a callable update(newid) updating the current bookmark
......@@ -294,3 +301,24 @@ def contentdivrisk(repo, ctx):
else:
divergent.append(sset[0][0])
return divergent
def phasedivrisk(repo, revs):
"""return public predecessor of a revision if rewriting that revision will
create phase-divergence.
this method has similar logic as obsolete._computephasedivergentset
except that here we are looking into obsolete revs"""
obsrevs = repo.revs(b'%ld and obsolete()', revs)
obsstore = repo.obsstore
phase = repo._phasecache.phase
public = phases.public
cl = repo.changelog
torev = compat.getgetrev(cl)
tonode = cl.node
obsnodes = list(map(tonode, obsrevs))
for pnode in obsutil.allpredecessors(obsstore, obsnodes):
prev = torev(pnode)
if (prev is not None) and (phase(repo, prev) <= public):
# we have a public predecessor
return [prev]
return []
......@@ -2032,4 +2032,6 @@ phase-divergent cset.
1 changesets pruned
$ hg touch --hidden -r 2
1 new phase-divergent changesets
abort: revision being rewritten has a public predecessor 7c3bad9141dc, performing 'touch' will create phase-divergence
(For more, see 'hg help evolution.instability')
[255]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment