[PATCH] {RFC} commands: switch to ctxmanager in phase
Bryan O'Sullivan
bos at serpentine.com
Mon Jan 11 23:34:32 UTC 2016
# HG changeset patch
# User Bryan O'Sullivan <bos at serpentine.com>
# Date 1452555256 28800
# Mon Jan 11 15:34:16 2016 -0800
# Node ID e909e11e2d42cf419f2205e632f23a206a66d2f1
# Parent 03e3c89b14b24b99e63ec985e71d9ddd0ef7fcf1
{RFC} commands: switch to ctxmanager in phase
This is a small example of the kind of simplification that the ctxmanager class in the previous patch makes possible.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5438,7 +5438,6 @@ def phase(ui, repo, *revs, **opts):
revs = scmutil.revrange(repo, revs)
- lock = None
ret = 0
if targetphase is None:
# display
@@ -5446,10 +5445,8 @@ def phase(ui, repo, *revs, **opts):
ctx = repo[r]
ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr()))
else:
- tr = None
- lock = repo.lock()
- try:
- tr = repo.transaction("phase")
+ with util.ctxmanager(repo.lock, repo.translambda('phase')) as c:
+ tr = c()[1]
# set phase
if not revs:
raise error.Abort(_('empty revision set'))
@@ -5463,10 +5460,6 @@ def phase(ui, repo, *revs, **opts):
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)
More information about the Mercurial-devel
mailing list