changeset 27836:1c2408c28aff

with: use context manager for wlock in shelve deletecmd
author Bryan O'Sullivan <bryano@fb.com>
date Fri, 15 Jan 2016 13:14:47 -0800
parents c448d7e00bf9
children 496ca4deddc5
files hgext/shelve.py
diffstat 1 files changed, 10 insertions(+), 12 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:47 2016 -0800
@@ -365,18 +365,16 @@
     """subcommand that deletes a specific shelve"""
     if not pats:
         raise error.Abort(_('no shelved changes specified!'))
-    wlock = repo.wlock()
-    try:
-        for name in pats:
-            for suffix in 'hg patch'.split():
-                shelvedfile(repo, name, suffix).movetobackup()
-        cleanupoldbackups(repo)
-    except OSError as err:
-        if err.errno != errno.ENOENT:
-            raise
-        raise error.Abort(_("shelved change '%s' not found") % name)
-    finally:
-        lockmod.release(wlock)
+    with repo.wlock():
+        try:
+            for name in pats:
+                for suffix in 'hg patch'.split():
+                    shelvedfile(repo, name, suffix).movetobackup()
+            cleanupoldbackups(repo)
+        except OSError as err:
+            if err.errno != errno.ENOENT:
+                raise
+            raise error.Abort(_("shelved change '%s' not found") % name)
 
 def listshelves(repo):
     """return all shelves in repo as list of (time, filename)"""