changeset 2736:3c87d5276394

prev: extract the function performing the update That code is fairly independant so let us isolate it to simplify the rest of the code.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 14 Jul 2017 01:12:20 +0200
parents 28087c173534
children 66278c4d9c07
files hgext3rd/evolve/__init__.py
diffstat 1 files changed, 26 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- 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)