Patchwork D1840: bookmarks: use context managers for locks and transaction in pushbookmark()

login
register
mail settings
Submitter phabricator
Date Jan. 10, 2018, 11:03 p.m.
Message ID <1ba21a345af0b879bceea8766ae333b4@localhost.localdomain>
Download mbox | patch
Permalink /patch/26652/
State Not Applicable
Headers show

Comments

phabricator - Jan. 10, 2018, 11:03 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGac7ee75ee664: bookmarks: use context managers for locks and transaction in pushbookmark() (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1840?vs=4760&id=4770

REVISION DETAIL
  https://phab.mercurial-scm.org/D1840

AFFECTED FILES
  mercurial/bookmarks.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers, durin42
Cc: mercurial-devel

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -20,7 +20,6 @@ 
 from . import (
     encoding,
     error,
-    lock as lockmod,
     obsutil,
     pycompat,
     scmutil,
@@ -414,11 +413,7 @@ 
     return d
 
 def pushbookmark(repo, key, old, new):
-    w = l = tr = None
-    try:
-        w = repo.wlock()
-        l = repo.lock()
-        tr = repo.transaction('bookmarks')
+    with repo.wlock(), repo.lock(), repo.transaction('bookmarks') as tr:
         marks = repo._bookmarks
         existing = hex(marks.get(key, ''))
         if existing != old and existing != new:
@@ -430,10 +425,7 @@ 
                 return False
             changes = [(key, repo[new].node())]
         marks.applychanges(repo, tr, changes)
-        tr.close()
         return True
-    finally:
-        lockmod.release(tr, l, w)
 
 def comparebookmarks(repo, srcmarks, dstmarks, targets=None):
     '''Compare bookmarks between srcmarks and dstmarks