with: use context manager in unshelveabort
authorBryan O'Sullivan <bryano@fb.com>
Fri, 15 Jan 2016 13:14:50 -0800
changeset 27841 83995fdde225
parent 27840 dc237afacbd4
child 27842 002108b219e3
with: use context manager in unshelveabort
hgext/shelve.py
--- 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