Patchwork D1838: phase: use context managers for lock and transaction

login
register
mail settings
Submitter phabricator
Date Jan. 10, 2018, 11:03 p.m.
Message ID <f3bd9fdfdde7e2a3b4efdece8ab78505@localhost.localdomain>
Download mbox | patch
Permalink /patch/26658/
State Not Applicable
Headers show

Comments

phabricator - Jan. 10, 2018, 11:03 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGdda3cae3c9c5: phase: use context managers for lock and transaction (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1838?vs=4758&id=4768

REVISION DETAIL
  https://phab.mercurial-scm.org/D1838

AFFECTED FILES
  mercurial/commands.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers, durin42
Cc: mercurial-devel

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3854,18 +3854,14 @@ 
 
     revs = scmutil.revrange(repo, revs)
 
-    lock = None
     ret = 0
     if targetphase is None:
         # display
         for r in revs:
             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)