Patchwork [4,of,9] strip: use context manager for locking and transaction in stripcmd()

login
register
mail settings
Submitter via Mercurial-devel
Date June 19, 2017, 8:47 p.m.
Message ID <d749f83970f783a18977.1497905276@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/21510/
State Accepted
Headers show

Comments

via Mercurial-devel - June 19, 2017, 8:47 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1497896429 25200
#      Mon Jun 19 11:20:29 2017 -0700
# Node ID d749f83970f783a1897705f62618a9948acbc1d0
# Parent  536ecac27d7742eb0f5a5ff5a1ad2218c6a510fb
strip: use context manager for locking and transaction in stripcmd()

Patch

diff --git a/hgext/strip.py b/hgext/strip.py
--- a/hgext/strip.py
+++ b/hgext/strip.py
@@ -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'))