prev: extract the function performing the update
authorPierre-Yves David <pierre-yves.david@octobus.net>
Fri, 14 Jul 2017 01:12:20 +0200
changeset 2736 3c87d5276394
parent 2735 28087c173534
child 2737 66278c4d9c07
prev: extract the function performing the update That code is fairly independant so let us isolate it to simplify the rest of the code.
hgext3rd/evolve/__init__.py
--- a/hgext3rd/evolve/__init__.py	Fri Jul 14 01:01:22 2017 +0200
+++ b/hgext3rd/evolve/__init__.py	Fri Jul 14 01:12:20 2017 +0200
@@ -1979,6 +1979,31 @@
 
 shorttemplate = "[{label('evolve.rev', rev)}] {desc|firstline}\n"
 
+def _prevupdate(repo, displayer, target, bookmark, dryrun):
+    if dryrun:
+        repo.ui.write(('hg update %s;\n' % target.rev()))
+        if bookmark is not None:
+            repo.ui.write(('hg bookmark %s -r %s;\n'
+                           % (bookmark, target.rev())))
+    else:
+        ret = hg.update(repo, target.rev())
+        if not ret:
+            tr = lock = None
+            try:
+                lock = repo.lock()
+                tr = repo.transaction('previous')
+                if bookmark is not None:
+                    repo._bookmarks[bookmark] = target.node()
+                    repo._bookmarks.recordchange(tr)
+                else:
+                    bookmarksmod.deactivate(repo)
+                tr.close()
+            finally:
+                lockmod.release(tr, lock)
+
+    displayer.show(target)
+    return 0
+
 @eh.command(
     '^previous',
     [('B', 'move-bookmark', False,
@@ -2021,29 +2046,7 @@
             bookmark = None
             if opts.get('move_bookmark'):
                 bookmark = repo._activebookmark
-            if dryrunopt:
-                ui.write(('hg update %s;\n' % target.rev()))
-                if bookmark is not None:
-                    ui.write(('hg bookmark %s -r %s;\n'
-                              % (bookmark, target.rev())))
-            else:
-                ret = hg.update(repo, target.rev())
-                if not ret:
-                    tr = lock = None
-                    try:
-                        lock = repo.lock()
-                        tr = repo.transaction('previous')
-                        if bookmark is not None:
-                            repo._bookmarks[bookmark] = target.node()
-                            repo._bookmarks.recordchange(tr)
-                        else:
-                            bookmarksmod.deactivate(repo)
-                        tr.close()
-                    finally:
-                        lockmod.release(tr, lock)
-
-            displayer.show(target)
-            return 0
+            return _prevupdate(repo, displayer, target, bookmark, dryrunopt)
         else:
             for p in parents:
                 displayer.show(p)