evolve: add pre-check logic for creation of phase divergence locally draft
authorSushil khanchi <sushilkhanchi97@gmail.com>
Sun, 10 Nov 2019 16:32:34 +0530
changeset 5233 efd1aa8c313c
parent 5232 edd40c8b3dc1
child 5234 ea3f9e171b9a
evolve: add pre-check logic for creation of phase divergence locally Changes in tests reflect the added behaviour.
hgext3rd/evolve/rewriteutil.py
tests/test-evolve-phase-divergence.t
--- a/hgext3rd/evolve/rewriteutil.py	Sun Nov 10 18:08:57 2019 +0530
+++ b/hgext3rd/evolve/rewriteutil.py	Sun Nov 10 16:32:34 2019 +0530
@@ -22,6 +22,7 @@
     node,
     obsolete,
     obsutil,
+    phases,
     revset,
     util,
 )
@@ -79,12 +80,18 @@
     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 @@
     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 []
--- a/tests/test-evolve-phase-divergence.t	Sun Nov 10 18:08:57 2019 +0530
+++ b/tests/test-evolve-phase-divergence.t	Sun Nov 10 16:32:34 2019 +0530
@@ -2032,4 +2032,6 @@
   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]