evolve: use context manager for transactions
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 19 Apr 2019 10:32:32 -0700
changeset 4593 f6b9c409c12e
parent 4592 e489c10add37
child 4594 fed1435757ba
evolve: use context manager for transactions
hgext3rd/evolve/evolvecmd.py
--- a/hgext3rd/evolve/evolvecmd.py	Fri Apr 19 10:52:16 2019 -0700
+++ b/hgext3rd/evolve/evolvecmd.py	Fri Apr 19 10:32:32 2019 -0700
@@ -1882,16 +1882,11 @@
                 # no backup of evolved cset versions needed
                 repair.strip(repo.ui, repo, strippoints, False)
 
-            tr = None
-            try:
-                tr = repo.transaction('evolve')
+            with repo.transaction('evolve') as tr:
                 # restoring bookmarks at there original place
                 bmchanges = evolvestate['bookmarkchanges']
                 if bmchanges:
                     repo._bookmarks.applychanges(repo, tr, bmchanges)
-                tr.close()
-            finally:
-                tr.release()
 
             evolvestate.delete()
             ui.status(_('evolve aborted\n'))
@@ -1957,9 +1952,7 @@
 
 def _continuecontentdivergent(ui, repo, evolvestate, progresscb):
     """function to continue the interrupted content-divergence resolution."""
-    tr = None
-    try:
-        tr = repo.transaction('evolve')
+    with repo.transaction('evolve'):
         divergent = evolvestate['divergent']
         base = evolvestate['base']
         repo = repo.unfiltered()
@@ -2002,10 +1995,7 @@
                 prec = repo[publicnode]
                 bumped = repo[newnode]
                 ret = _resolvephasedivergent(ui, repo, prec=prec, bumped=bumped)
-        tr.close()
         return ret
-    finally:
-        tr.release()
 
 def _completephasedivergent(ui, repo, evolvestate):
     """function to complete the interrupted phase-divergence resolution.
@@ -2013,10 +2003,8 @@
     First completes the relocation of the commit and then process resolving
     phase-divergence"""
 
-    tr = None
-    try:
-        # need to start transaction for bookmark changes
-        tr = repo.transaction('evolve')
+    # need to start transaction for bookmark changes
+    with repo.transaction('evolve'):
         node = _completerelocation(ui, repo, evolvestate)
         evolvestate['temprevs'].append(node)
         # resolving conflicts can lead to empty wdir and node can be None in
@@ -2029,9 +2017,6 @@
         prec = repo[evolvestate['precursor']]
         retvalue = _resolvephasedivergent(ui, repo, prec, newctx)
         evolvestate['replacements'][ctx.node()] = retvalue[1]
-        tr.close()
-    finally:
-        tr.release()
 
 def _completeorphan(ui, repo, evolvestate):
     """function to complete the interrupted orphan resolution"""