evolve: use utility._singlesuccessor() in _solveunstable()
authorSushil khanchi <sushilkhanchi97@gmail.com>
Sat, 07 Dec 2019 23:13:40 +0530
changeset 5050 f29bd1c7e457
parent 5049 1b393870c6b9
child 5051 9346f0e934be
evolve: use utility._singlesuccessor() in _solveunstable()
hgext3rd/evolve/evolvecmd.py
hgext3rd/evolve/utility.py
--- a/hgext3rd/evolve/evolvecmd.py	Wed Dec 18 16:21:37 2019 +0100
+++ b/hgext3rd/evolve/evolvecmd.py	Sat Dec 07 23:13:40 2019 +0530
@@ -122,23 +122,22 @@
         ui.warn(_(b"cannot solve instability of %s, skipping\n") % orig)
         return (False, b".")
     obs = pctx
-    if True:
-        newer = obsutil.successorssets(repo, obs.node())
-        # search of a parent which is not killed, but also isn't the orig
-        while not newer or newer[0][0] == orig.node():
-            ui.debug(b"stabilize target %s is plain dead,"
-                     b" trying to stabilize on its parent\n" %
-                     obs)
-            obs = obs.p1()
-            newer = obsutil.successorssets(repo, obs.node())
-        if len(newer) > 1:
+    try:
+        newer = utility._singlesuccessor(repo, obs)
+        # search of a parent which isn't the orig
+        while repo[newer].node() == orig.node():
+            obs = obs.parents()[0]
+            newer = utility._singlesuccessor(repo, obs)
+        target = newer
+    except utility.MultipleSuccessorsError as exc:
+        if exc.divergenceflag:
             msg = _(b"skipping %s: divergent rewriting. can't choose "
                     b"destination\n") % obs
             ui.write_err(msg)
             return (False, b".")
-        targets = newer[0]
+        targets = exc.successorssets[0]
         assert targets
-        if len(targets) > 1:
+        if exc.splitflag:
             # split target, figure out which one to pick, are they all in line?
             targetrevs = [repo[r].rev() for r in targets]
             roots = repo.revs(b'roots(%ld)', targetrevs)
--- a/hgext3rd/evolve/utility.py	Wed Dec 18 16:21:37 2019 +0100
+++ b/hgext3rd/evolve/utility.py	Sat Dec 07 23:13:40 2019 +0530
@@ -75,6 +75,8 @@
 
     def __init__(self, successorssets):
         self.successorssets = successorssets
+        self.divergenceflag = len(successorssets) > 1
+        self.splitflag = len(successorssets[0]) > 1
 
 def builddependencies(repo, revs):
     """returns dependency graphs giving an order to solve instability of revs