--- a/hgext3rd/evolve/evolvecmd.py Mon Sep 16 12:42:50 2019 -0700
+++ b/hgext3rd/evolve/evolvecmd.py Mon Sep 16 12:44:38 2019 -0700
@@ -178,15 +178,10 @@
repo.ui.note(todo)
if progresscb:
progresscb()
- try:
+ with state.saver(evolvestate, {b'current': orig.node()}):
newid = relocate(repo, orig, target, evolvestate, pctx,
keepbranch, b'orphan')
return (True, newid)
- except error.InterventionRequired:
- ops = {b'current': orig.node()}
- evolvestate.addopts(ops)
- evolvestate.save()
- raise
def _solvephasedivergence(ui, repo, bumped, evolvestate, displayer,
dryrun=False, confirm=False, progresscb=None):
@@ -241,7 +236,8 @@
# Need to rebase the changeset at the right place
repo.ui.status(
_(b'rebasing to destination parent: %s\n') % prec.p1())
- try:
+ with state.saver(evolvestate, {b'current': bumped.hex(),
+ b'precursor': prec.hex()}):
newnode = relocate(repo, bumped, prec.p1(), evolvestate,
category=b'phasedivergent')
if newnode is not None:
@@ -250,11 +246,6 @@
operation=b'evolve')
bumped = new
evolvestate[b'temprevs'].append(newnode)
- except error.InterventionRequired:
- evolvestate[b'current'] = bumped.hex()
- evolvestate[b'precursor'] = prec.hex()
- evolvestate.save()
- raise
return _resolvephasedivergent(ui, repo, prec, bumped)
@@ -511,13 +502,9 @@
evolvestate[b'relocating'] = True
ui.status(_(b'rebasing "other" content-divergent changeset %s on'
b' %s\n' % (other, divergent.p1())))
- try:
+ with state.saver(evolvestate, {b'current': other.node()}):
newother = relocate(repo, other, divergent.p1(), evolvestate,
keepbranch=True)
- except error.InterventionRequired:
- evolvestate[b'current'] = other.node()
- evolvestate.save()
- raise
evolvestate[b'old-other'] = other.node()
other = repo[newother]
evolvestate[b'relocating'] = False
@@ -567,21 +554,22 @@
(TROUBLES['CONTENTDIVERGENT'], other.hex()[:12]))
if progresscb:
progresscb()
- mergeancestor = repo.changelog.isancestor(divergent.node(), other.node())
- stats = merge.update(repo,
- other.node(),
- branchmerge=True,
- force=False,
- ancestor=base.node(),
- mergeancestor=mergeancestor)
- hg._showstats(repo, stats)
+ with state.saver(evolvestate):
+ mergeancestor = repo.changelog.isancestor(divergent.node(),
+ other.node())
+ stats = merge.update(repo,
+ other.node(),
+ branchmerge=True,
+ force=False,
+ ancestor=base.node(),
+ mergeancestor=mergeancestor)
+ hg._showstats(repo, stats)
- # conflicts while merging content-divergent changesets
- if compat.hasconflict(stats):
- evolvestate.save()
- hint = _(b"see 'hg help evolve.interrupted'")
- raise error.InterventionRequired(_(b"unresolved merge conflicts"),
- hint=hint)
+ # conflicts while merging content-divergent changesets
+ if compat.hasconflict(stats):
+ hint = _(b"see 'hg help evolve.interrupted'")
+ raise error.InterventionRequired(_(b"unresolved merge conflicts"),
+ hint=hint)
def _completecontentdivergent(ui, repo, progresscb, divergent, other,
base, evolvestate):
--- a/hgext3rd/evolve/state.py Mon Sep 16 12:42:50 2019 -0700
+++ b/hgext3rd/evolve/state.py Mon Sep 16 12:44:38 2019 -0700
@@ -15,6 +15,7 @@
from __future__ import absolute_import
+import contextlib
import errno
import struct
@@ -143,3 +144,16 @@
return state
finally:
f.close()
+
+@contextlib.contextmanager
+def saver(state, opts=None):
+ """ensure the state is saved on disk during the duration of the context
+
+ The state is preserved if the context is exited through an exception.
+ """
+ if opts:
+ state.addopts(opts)
+ state.save()
+ yield
+ # delete only if no exception where raised
+ state.delete()