changeset 35575:dda3cae3c9c5

phase: use context managers for lock and transaction Differential Revision: https://phab.mercurial-scm.org/D1838
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 10 Jan 2018 10:44:21 -0800
parents 09285733ad71
children b9a0de08110e
files mercurial/commands.py
diffstat 1 files changed, 1 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Wed Jan 10 10:33:11 2018 -0800
+++ b/mercurial/commands.py	Wed Jan 10 10:44:21 2018 -0800
@@ -3854,7 +3854,6 @@
 
     revs = scmutil.revrange(repo, revs)
 
-    lock = None
     ret = 0
     if targetphase is None:
         # display
@@ -3862,10 +3861,7 @@
             ctx = repo[r]
             ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr()))
     else:
-        tr = None
-        lock = repo.lock()
-        try:
-            tr = repo.transaction("phase")
+        with repo.lock(), repo.transaction("phase") as tr:
             # set phase
             if not revs:
                 raise error.Abort(_('empty revision set'))
@@ -3878,11 +3874,6 @@
             phases.advanceboundary(repo, tr, targetphase, nodes)
             if opts['force']:
                 phases.retractboundary(repo, tr, targetphase, nodes)
-            tr.close()
-        finally:
-            if tr is not None:
-                tr.release()
-            lock.release()
         getphase = unfi._phasecache.phase
         newdata = [getphase(unfi, r) for r in unfi]
         changes = sum(newdata[r] != olddata[r] for r in unfi)