next: factor out the logic to update to changeset in another function
authorPulkit Goyal <7895pulkit@gmail.com>
Fri, 16 Mar 2018 11:24:35 +0530
changeset 3539 9bd64091e880
parent 3538 b314c64f336b
child 3540 0624732c92f7
next: factor out the logic to update to changeset in another function This patch moves the logic to update to children changeset during `hg next` in a separate function because we want to re-use the logic when we will prompt user to choose a changeset in case of multiple childrens.
hgext3rd/evolve/__init__.py
--- a/hgext3rd/evolve/__init__.py	Wed Mar 14 17:59:53 2018 +0530
+++ b/hgext3rd/evolve/__init__.py	Fri Mar 16 11:24:35 2018 +0530
@@ -1107,30 +1107,7 @@
                                               {'template': shorttemplate})
         if len(children) == 1:
             c = children[0]
-            bm = repo._activebookmark
-            shouldmove = opts.get('move_bookmark') and bm is not None
-            if dryrunopt:
-                ui.write(('hg update %s;\n' % c.rev()))
-                if shouldmove:
-                    ui.write(('hg bookmark %s -r %s;\n' % (bm, c.rev())))
-            else:
-                ret = hg.update(repo, c.rev())
-                if not ret:
-                    lock = tr = None
-                    try:
-                        lock = repo.lock()
-                        tr = repo.transaction('next')
-                        if shouldmove:
-                            bmchanges = [(bm, c.node())]
-                            compat.bookmarkapplychanges(repo, tr, bmchanges)
-                        else:
-                            bookmarksmod.deactivate(repo)
-                        tr.close()
-                    finally:
-                        lockmod.release(tr, lock)
-            if not ui.quiet:
-                displayer.show(c)
-            result = 0
+            result = _updatetonext(ui, repo, c, displayer, opts)
         elif children:
             ui.warn(_("ambiguous next changeset:\n"))
             for c in children:
@@ -1177,6 +1154,34 @@
     finally:
         lockmod.release(wlock)
 
+def _updatetonext(ui, repo, children, displayer, opts):
+    """ logic for `hg next` command to update to children and move bookmarks if
+    required """
+    bm = repo._activebookmark
+    shouldmove = opts.get('move_bookmark') and bm is not None
+    if opts.get('dry_run'):
+        ui.write(('hg update %s;\n' % children.rev()))
+        if shouldmove:
+            ui.write(('hg bookmark %s -r %s;\n' % (bm, children.rev())))
+    else:
+        ret = hg.update(repo, children.rev())
+        if not ret:
+            lock = tr = None
+            try:
+                lock = repo.lock()
+                tr = repo.transaction('next')
+                if shouldmove:
+                    bmchanges = [(bm, children.node())]
+                    compat.bookmarkapplychanges(repo, tr, bmchanges)
+                else:
+                    bookmarksmod.deactivate(repo)
+                tr.close()
+            finally:
+                lockmod.release(tr, lock)
+    if not ui.quiet:
+        displayer.show(children)
+    return 0
+
 @eh.wrapcommand('commit')
 def commitwrapper(orig, ui, repo, *arg, **kwargs):
     tr = None