Patchwork [5,of,9] amend: use context manager for locking

login
register
mail settings
Submitter via Mercurial-devel
Date June 19, 2017, 8:47 p.m.
Message ID <ff0a5f83ee622acdc1f1.1497905277@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/21511/
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 1497896497 25200
#      Mon Jun 19 11:21:37 2017 -0700
# Node ID ff0a5f83ee622acdc1f1ed5f9323211044bfa78d
# Parent  d749f83970f783a1897705f62618a9948acbc1d0
amend: use context manager for locking

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -30,7 +30,6 @@ 
     error,
     formatter,
     graphmod,
-    lock as lockmod,
     match as matchmod,
     obsolete,
     patch,
@@ -2730,10 +2729,8 @@ 
     base = old.p1()
     createmarkers = obsolete.isenabled(repo, obsolete.createmarkersopt)
 
-    wlock = lock = newid = None
-    try:
-        wlock = repo.wlock()
-        lock = repo.lock()
+    newid = None
+    with repo.wlock(), repo.lock():
         with repo.transaction('amend') as tr:
             # See if we got a message from -m or -l, if not, open the editor
             # with the message of the changeset to amend
@@ -2896,8 +2893,6 @@ 
                 ui.note(_('stripping intermediate changeset %s\n') % ctx)
             ui.note(_('stripping amended changeset %s\n') % old)
             repair.strip(ui, repo, old.node(), topic='amend-backup')
-    finally:
-        lockmod.release(lock, wlock)
     return newid
 
 def commiteditor(repo, ctx, subs, editform=''):