changeset 27841:83995fdde225

with: use context manager in unshelveabort
author Bryan O'Sullivan <bryano@fb.com>
date Fri, 15 Jan 2016 13:14:50 -0800
parents dc237afacbd4
children 002108b219e3
files hgext/shelve.py
diffstat 1 files changed, 18 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/shelve.py	Fri Jan 15 13:14:47 2016 -0800
+++ b/hgext/shelve.py	Fri Jan 15 13:14:50 2016 -0800
@@ -461,30 +461,27 @@
 
 def unshelveabort(ui, repo, state, opts):
     """subcommand that abort an in-progress unshelve"""
-    lock = None
-    try:
-        checkparents(repo, state)
-
-        util.rename(repo.join('unshelverebasestate'),
-                    repo.join('rebasestate'))
+    with repo.lock():
         try:
-            rebase.rebase(ui, repo, **{
-                'abort' : True
-            })
-        except Exception:
-            util.rename(repo.join('rebasestate'),
-                        repo.join('unshelverebasestate'))
-            raise
+            checkparents(repo, state)
 
-        lock = repo.lock()
-
-        mergefiles(ui, repo, state.wctx, state.pendingctx)
+            util.rename(repo.join('unshelverebasestate'),
+                        repo.join('rebasestate'))
+            try:
+                rebase.rebase(ui, repo, **{
+                    'abort' : True
+                })
+            except Exception:
+                util.rename(repo.join('rebasestate'),
+                            repo.join('unshelverebasestate'))
+                raise
 
-        repair.strip(ui, repo, state.stripnodes, backup=False, topic='shelve')
-    finally:
-        shelvedstate.clear(repo)
-        ui.warn(_("unshelve of '%s' aborted\n") % state.name)
-        lockmod.release(lock)
+            mergefiles(ui, repo, state.wctx, state.pendingctx)
+            repair.strip(ui, repo, state.stripnodes, backup=False,
+                         topic='shelve')
+        finally:
+            shelvedstate.clear(repo)
+            ui.warn(_("unshelve of '%s' aborted\n") % state.name)
 
 def mergefiles(ui, repo, wctx, shelvectx):
     """updates to wctx and merges the changes from shelvectx into the