evolvecmd: introduce a new module to handle `hg evolve` related code
authorPulkit Goyal <7895pulkit@gmail.com>
Fri, 19 Jan 2018 14:42:46 +0530
changeset 3461 6475d2046f87
parent 3460 ada7fb453034
child 3462 e147c18ed064
evolvecmd: introduce a new module to handle `hg evolve` related code __init__.py is to cluttered with wrapping and all, it's better to move code related to evolve command to new a module which will help us in great refactoring and introducing nice and better flow of data through functions. There is a temporary import cycle is introduced which will be fixed in the series.
hgext3rd/evolve/__init__.py
hgext3rd/evolve/evolvecmd.py
--- a/hgext3rd/evolve/__init__.py	Thu Jan 18 16:57:19 2018 +0530
+++ b/hgext3rd/evolve/__init__.py	Fri Jan 19 14:42:46 2018 +0530
@@ -311,6 +311,7 @@
     debugcmd,
     cmdrewrite,
     state,
+    evolvecmd,
     exthelper,
     metadata,
     obscache,
@@ -1028,34 +1029,6 @@
     _deprecatealias('gup', 'next')
     _deprecatealias('gdown', 'previous')
 
-def _solveone(ui, repo, ctx, dryrun, confirm, progresscb, category):
-    """Resolve the troubles affecting one revision
-
-    returns a tuple (bool, newnode) where,
-        bool: a boolean value indicating whether the instability was solved
-        newnode: if bool is True, then the newnode of the resultant commit
-                 formed. newnode can be node, when resolution led to no new
-                 commit. If bool is False, this is ''.
-    """
-    wlock = lock = tr = None
-    try:
-        wlock = repo.wlock()
-        lock = repo.lock()
-        tr = repo.transaction("evolve")
-        if 'orphan' == category:
-            result = _solveunstable(ui, repo, ctx, dryrun, confirm, progresscb)
-        elif 'phasedivergent' == category:
-            result = _solvebumped(ui, repo, ctx, dryrun, confirm, progresscb)
-        elif 'contentdivergent' == category:
-            result = _solvedivergent(ui, repo, ctx, dryrun, confirm,
-                                     progresscb)
-        else:
-            assert False, "unknown trouble category: %s" % (category)
-        tr.close()
-        return result
-    finally:
-        lockmod.release(tr, lock, wlock)
-
 def _handlenotrouble(ui, repo, allopt, revopt, anyopt, targetcat):
     """Used by the evolve function to display an error message when
     no troubles can be resolved"""
@@ -1627,8 +1600,8 @@
     for rev in revs:
         curctx = repo[rev]
         progresscb()
-        ret = _solveone(ui, repo, curctx, dryrunopt, confirmopt,
-                         progresscb, targetcat)
+        ret = evolvecmd._solveone(ui, repo, curctx, dryrunopt, confirmopt,
+                                  progresscb, targetcat)
         seen += 1
         if ret[0]:
             replacements[curctx.node()] = [ret[1]]
@@ -1796,8 +1769,8 @@
         progresscb()
     todo = 'hg rebase -r %s -d %s\n' % (orig, target)
     if dryrun:
+        repo.ui.write(todo)
         return (False, '')
-        repo.ui.write(todo)
     else:
         repo.ui.note(todo)
         if progresscb:
@@ -2282,8 +2255,9 @@
                 return 1
             else:
                 cmdutil.bailifchanged(repo)
-                result = _solveone(ui, repo, repo[aspchildren[0]], dryrunopt,
-                                   False, lambda: None, category='orphan')
+                result = evolvecmd._solveone(ui, repo, repo[aspchildren[0]],
+                                             dryrunopt, False, lambda: None,
+                                             category='orphan')
                 # making sure a next commit is formed
                 if result[0] and result[1]:
                     ui.status(_('working directory now at %s\n')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hgext3rd/evolve/evolvecmd.py	Fri Jan 19 14:42:46 2018 +0530
@@ -0,0 +1,43 @@
+# Copyright 2011 Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
+#                Logilab SA        <contact@logilab.fr>
+#                Pierre-Yves David <pierre-yves.david@ens-lyon.org>
+#                Patrick Mezard <patrick@mezard.eu>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+"""logic related to hg evolve command"""
+
+from mercurial import (
+    lock as lockmod,
+)
+
+from . import _solveunstable, _solvebumped, _solvedivergent
+
+def _solveone(ui, repo, ctx, dryrun, confirm, progresscb, category):
+    """Resolve the troubles affecting one revision
+
+    returns a tuple (bool, newnode) where,
+        bool: a boolean value indicating whether the instability was solved
+        newnode: if bool is True, then the newnode of the resultant commit
+                 formed. newnode can be node, when resolution led to no new
+                 commit. If bool is False, this is ''.
+    """
+    wlock = lock = tr = None
+    try:
+        wlock = repo.wlock()
+        lock = repo.lock()
+        tr = repo.transaction("evolve")
+        if 'orphan' == category:
+            result = _solveunstable(ui, repo, ctx, dryrun, confirm, progresscb)
+        elif 'phasedivergent' == category:
+            result = _solvebumped(ui, repo, ctx, dryrun, confirm, progresscb)
+        elif 'contentdivergent' == category:
+            result = _solvedivergent(ui, repo, ctx, dryrun, confirm,
+                                     progresscb)
+        else:
+            assert False, "unknown trouble category: %s" % (category)
+        tr.close()
+        return result
+    finally:
+        lockmod.release(tr, lock, wlock)