bookmarks: use context managers for lock and transaction in update()
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 10 Jan 2018 10:47:13 -0800
changeset 41429 b9a0de08110eb1a4abf53a8785f36469374d89c7
parent 41428 dda3cae3c9c5dddcddc2c24d49d40325a982a1d8
child 41430 ac7ee75ee6644a6ccb23cf3202aaabe57f1bc090
push id641
push usergszorc@mozilla.com
push dateThu, 11 Jan 2018 02:24:53 +0000
bookmarks: use context managers for lock and transaction in update() Differential Revision: https://phab.mercurial-scm.org/D1839
mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -387,24 +387,18 @@ def update(repo, parents, node):
         deletefrom = [b.node() for b in divs if b.rev() in anc or b == new]
         if validdest(repo, repo[marks[active]], new):
             bmchanges.append((active, new.node()))
 
     for bm in divergent2delete(repo, deletefrom, active):
         bmchanges.append((bm, None))
 
     if bmchanges:
-        lock = tr = None
-        try:
-            lock = repo.lock()
-            tr = repo.transaction('bookmark')
+        with repo.lock(), repo.transaction('bookmark') as tr:
             marks.applychanges(repo, tr, bmchanges)
-            tr.close()
-        finally:
-            lockmod.release(tr, lock)
     return bool(bmchanges)
 
 def listbinbookmarks(repo):
     # We may try to list bookmarks on a repo type that does not
     # support it (e.g., statichttprepository).
     marks = getattr(repo, '_bookmarks', {})
 
     hasnode = repo.changelog.hasnode