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

login
register
mail settings
Submitter Matt Harbison
Date June 23, 2018, 3:36 a.m.
Message ID <c68fcc8aa06b71d87439.1529724996@Envy>
Download mbox | patch
Permalink /patch/32386/
State Accepted
Headers show

Comments

Matt Harbison - June 23, 2018, 3:36 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@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
Yuya Nishihara - June 23, 2018, 7:11 a.m.
On Fri, 22 Jun 2018 23:36:36 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@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

Queued, thanks.

Patch

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: