[PATCH 1 of 2] censor: use context manager for lock management

Matt Harbison mharbison72 at gmail.com
Sat Jun 23 03:36:36 UTC 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1490329951 14400
#      Fri Mar 24 00:32:31 2017 -0400
# Node ID c68fcc8aa06b71d87439efceeea3c0ac55b93614
# Parent  3813c6b7337c9aadac7a5ff5f03ae3ea3d61da9b
censor: use context manager for lock management

diff --git a/hgext/censor.py b/hgext/censor.py
--- a/hgext/censor.py
+++ b/hgext/censor.py
@@ -32,7 +32,6 @@ from mercurial.node import short
 
 from mercurial import (
     error,
-    lock as lockmod,
     registrar,
     revlog,
     scmutil,
@@ -52,13 +51,8 @@ testedwith = 'ships-with-hg-core'
      ('t', 'tombstone', '', _('replacement tombstone data'), _('TEXT'))],
     _('-r REV [-t TEXT] [FILE]'))
 def censor(ui, repo, path, rev='', tombstone='', **opts):
-    wlock = lock = None
-    try:
-        wlock = repo.wlock()
-        lock = repo.lock()
+    with repo.wlock(), repo.lock():
         return _docensor(ui, repo, path, rev, tombstone, **opts)
-    finally:
-        lockmod.release(lock, wlock)
 
 def _docensor(ui, repo, path, rev='', tombstone='', **opts):
     if not path:


More information about the Mercurial-devel mailing list