changeset 32920:8dbcb66ac160

strip: use context manager for locking and transaction in stripcmd()
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 19 Jun 2017 11:20:29 -0700
parents daceeed34ad2
children 5694311db6ed
files hgext/strip.py
diffstat 1 files changed, 3 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/strip.py	Mon Jun 19 11:17:31 2017 -0700
+++ b/hgext/strip.py	Mon Jun 19 11:20:29 2017 -0700
@@ -156,18 +156,12 @@
                     rsrevs = repair.stripbmrevset(repo, marks[0])
                     revs.update(set(rsrevs))
             if not revs:
-                lock = tr = None
-                try:
-                    lock = repo.lock()
-                    tr = repo.transaction('bookmark')
+                with repo.lock(), repo.transaction('bookmark') as tr:
                     for bookmark in bookmarks:
                         del repomarks[bookmark]
                     repomarks.recordchange(tr)
-                    tr.close()
-                    for bookmark in sorted(bookmarks):
-                        ui.write(_("bookmark '%s' deleted\n") % bookmark)
-                finally:
-                    release(lock, tr)
+                for bookmark in sorted(bookmarks):
+                    ui.write(_("bookmark '%s' deleted\n") % bookmark)
 
         if not revs:
             raise error.Abort(_('empty revision set'))