evolve: use util.acceptintervention() for closing transactions
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 19 Apr 2019 11:02:35 -0700
changeset 4594 fed1435757ba
parent 4593 f6b9c409c12e
child 4595 3a3be1378634
evolve: use util.acceptintervention() for closing transactions util.acceptintervention() will close the transaction on InterventionRequired.
hgext3rd/evolve/evolvecmd.py
--- a/hgext3rd/evolve/evolvecmd.py	Fri Apr 19 10:32:32 2019 -0700
+++ b/hgext3rd/evolve/evolvecmd.py	Fri Apr 19 11:02:35 2019 -0700
@@ -71,21 +71,23 @@
     else:
         displayer = compat.changesetdisplayer(ui, repo,
                                               {'template': shorttemplate})
-    with repo.wlock(), repo.lock(), repo.transaction("evolve"):
-        if 'orphan' == category:
-            result = _solveunstable(ui, repo, ctx, evolvestate, displayer,
-                                    dryrun, confirm, progresscb,
-                                    lastsolved=lastsolved)
-        elif 'phasedivergent' == category:
-            result = _solvephasedivergence(ui, repo, ctx, evolvestate,
-                                           displayer, dryrun, confirm,
-                                           progresscb)
-        elif 'contentdivergent' == category:
-            result = _solvedivergent(ui, repo, ctx, evolvestate, displayer,
-                                     dryrun, confirm, progresscb)
-        else:
-            assert False, "unknown trouble category: %s" % (category)
-        return result
+    with repo.wlock(), repo.lock():
+        tr = repo.transaction("evolve")
+        with util.acceptintervention(tr):
+            if 'orphan' == category:
+                result = _solveunstable(ui, repo, ctx, evolvestate, displayer,
+                                        dryrun, confirm, progresscb,
+                                        lastsolved=lastsolved)
+            elif 'phasedivergent' == category:
+                result = _solvephasedivergence(ui, repo, ctx, evolvestate,
+                                               displayer, dryrun, confirm,
+                                               progresscb)
+            elif 'contentdivergent' == category:
+                result = _solvedivergent(ui, repo, ctx, evolvestate, displayer,
+                                         dryrun, confirm, progresscb)
+            else:
+                assert False, "unknown trouble category: %s" % (category)
+            return result
 
 def _solveunstable(ui, repo, orig, evolvestate, displayer, dryrun=False,
                    confirm=False, progresscb=None, lastsolved=None):
@@ -576,8 +578,6 @@
 
     # conflicts while merging content-divergent changesets
     if compat.hasconflict(stats):
-        tr = repo.currenttransaction()
-        tr.close()
         evolvestate.save()
         raise error.InterventionRequired(_("fix conflicts and see `hg help "
                                            "evolve.interrupted`"))
@@ -984,7 +984,6 @@
             copies.duplicatecopies(repo, repo[None], dest.rev(),
                                    orig.p1().rev())
             dirstatedance(repo, dest, orig.node(), None)
-            tr.close() # to keep changes in this transaction (e.g. dirstate)
         raise error.InterventionRequired(_("fix conflicts and see `hg help "
                                            "evolve.interrupted`"))
     nodenew = _relocatecommit(repo, orig, commitmsg)
@@ -1952,7 +1951,8 @@
 
 def _continuecontentdivergent(ui, repo, evolvestate, progresscb):
     """function to continue the interrupted content-divergence resolution."""
-    with repo.transaction('evolve'):
+    tr = repo.transaction('evolve')
+    with util.acceptintervention(tr):
         divergent = evolvestate['divergent']
         base = evolvestate['base']
         repo = repo.unfiltered()