evolve: use context managers for locks and transaction
authorMartin von Zweigbergk <martinvonz@google.com>
Tue, 22 Jan 2019 22:36:29 -0800
changeset 4375 07ccf1686024
parent 4374 86bf0b106949
child 4376 0fbf895ce160
evolve: use context managers for locks and transaction
hgext3rd/evolve/evolvecmd.py
--- a/hgext3rd/evolve/evolvecmd.py	Tue Jan 22 10:17:58 2019 -0800
+++ b/hgext3rd/evolve/evolvecmd.py	Tue Jan 22 22:36:29 2019 -0800
@@ -19,7 +19,6 @@
     copies,
     error,
     hg,
-    lock as lockmod,
     merge,
     mergeutil,
     node as nodemod,
@@ -71,11 +70,7 @@
     else:
         displayer = compat.changesetdisplayer(ui, repo,
                                               {'template': shorttemplate})
-    wlock = lock = tr = None
-    try:
-        wlock = repo.wlock()
-        lock = repo.lock()
-        tr = repo.transaction("evolve")
+    with repo.wlock(), repo.lock(), repo.transaction("evolve"):
         if 'orphan' == category:
             result = _solveunstable(ui, repo, ctx, evolvestate, displayer,
                                     dryrun, confirm, progresscb,
@@ -89,10 +84,7 @@
                                      dryrun, confirm, progresscb)
         else:
             assert False, "unknown trouble category: %s" % (category)
-        tr.close()
         return result
-    finally:
-        lockmod.release(tr, lock, wlock)
 
 def _solveunstable(ui, repo, orig, evolvestate, displayer, dryrun=False,
                    confirm=False, progresscb=None, lastsolved=None):