Patchwork [3,of,9] strip: use context manager for locking in strip()

login
register
mail settings
Submitter via Mercurial-devel
Date June 19, 2017, 8:47 p.m.
Message ID <536ecac27d7742eb0f5a.1497905275@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/21509/
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 1497896251 25200
#      Mon Jun 19 11:17:31 2017 -0700
# Node ID 536ecac27d7742eb0f5a5ff5a1ad2218c6a510fb
# Parent  34b34f533358a963f30cb9d4d6487631f367e46e
strip: use context manager for locking in strip()

Patch

diff --git a/hgext/strip.py b/hgext/strip.py
--- a/hgext/strip.py
+++ b/hgext/strip.py
@@ -59,10 +59,7 @@ 
     return s
 
 def strip(ui, repo, revs, update=True, backup=True, force=None, bookmarks=None):
-    wlock = lock = None
-    try:
-        wlock = repo.wlock()
-        lock = repo.lock()
+    with repo.wlock(), repo.lock():
 
         if update:
             checklocalchanges(repo, force=force)
@@ -86,9 +83,6 @@ 
                 repomarks.recordchange(tr)
             for bookmark in sorted(bookmarks):
                 ui.write(_("bookmark '%s' deleted\n") % bookmark)
-    finally:
-        release(lock, wlock)
-
 
 @command("strip",
          [