# HG changeset patch # User Martin von Zweigbergk # Date 1601658554 25200 # Node ID 947820d4b476452cacfbe54cb68eacf71a9b9dd0 # Parent 24a1ff0677a7bc74ec1ced0d89df2396f4758b02 compat: add implementations of new merge.update() and merge.clean_update() This adds `compat.update()`, `compat.clean_update()`, which will delegate to the same functions from `mercurial.merge` when they are available, or fall back to calling `hg.updaterepo()` when they're not. diff -r 24a1ff0677a7 -r 947820d4b476 hgext3rd/evolve/cmdrewrite.py --- a/hgext3rd/evolve/cmdrewrite.py Fri Oct 02 09:51:45 2020 -0700 +++ b/hgext3rd/evolve/cmdrewrite.py Fri Oct 02 10:09:14 2020 -0700 @@ -173,7 +173,7 @@ compat.cleanupnodes(repo, replacements, operation=b'amend', metadata=metadata) phases.retractboundary(repo, tr, old.phase(), [newnode]) - hg.updaterepo(repo, newnode, True) + compat.clean_update(repo[newnode]) def _editandapply(ui, repo, pats, old, p1, fp, diffopts): newnode = None @@ -513,7 +513,7 @@ metadata=metadata) phases.retractboundary(repo, tr, oldphase, [newid]) if opts.get('revert'): - hg.updaterepo(repo, newid, True) + compat.clean_update(repo[newid]) else: with repo.dirstate.parentchange(), compat.parentchange(repo): movedirstate(repo, repo[newid], match) @@ -1478,7 +1478,7 @@ pctxnode = pickstate[b'oldpctx'] ui.status(_(b"aborting pick, updating to %s\n") % node.hex(pctxnode)[:12]) - hg.updaterepo(repo, pctxnode, True) + compat.clean_update(repo[pctxnode]) pickstate.delete() return 0 diff -r 24a1ff0677a7 -r 947820d4b476 hgext3rd/evolve/compat.py --- a/hgext3rd/evolve/compat.py Fri Oct 02 09:51:45 2020 -0700 +++ b/hgext3rd/evolve/compat.py Fri Oct 02 10:09:14 2020 -0700 @@ -12,6 +12,7 @@ from mercurial import ( context, copies, + hg, merge as mergemod, obsolete, pycompat, @@ -409,3 +410,19 @@ # hg <= 5.5 (2c86b9587740) def _update(*args, **kwargs): return mergemod.update(*args, **kwargs) + +if (util.safehasattr(mergemod, '_update') + and util.safehasattr(mergemod, 'update')): + + def update(ctx): + mergemod.update(ctx) + + def clean_update(ctx): + mergemod.clean_update(ctx) +else: + # hg <= 5.5 (c1b603cdc95a) + def update(ctx): + hg.updaterepo(ctx.repo(), ctx.node(), overwrite=False) + + def clean_update(ctx): + hg.updaterepo(ctx.repo(), ctx.node(), overwrite=True) diff -r 24a1ff0677a7 -r 947820d4b476 hgext3rd/evolve/evolvecmd.py --- a/hgext3rd/evolve/evolvecmd.py Fri Oct 02 09:51:45 2020 -0700 +++ b/hgext3rd/evolve/evolvecmd.py Fri Oct 02 10:09:14 2020 -0700 @@ -596,7 +596,7 @@ if divergent not in repo[None].parents(): repo.ui.note(_(b"updating to \"local\" side of the conflict: %s\n") % divergent.hex()[:12]) - hg.updaterepo(repo, divergent.node(), False) + compat.update(divergent) # merging the two content-divergent changesets repo.ui.note(_(b"merging \"other\" %s changeset '%s'\n") % (TROUBLES['CONTENTDIVERGENT'], other.hex()[:12])) @@ -690,7 +690,7 @@ } newnode = repo.commit(text=desc, user=user, date=date, extra=extra) new = repo[newnode] - hg.updaterepo(repo, new.rev(), False) + compat.update(new) if haspubdiv and publicdiv == divergent: bypassphase(repo, (divergent, new), operation=b'evolve') else: @@ -1420,7 +1420,7 @@ # obsolete (perhaps made obsolete by the current `hg evolve`) unfi = repo.unfiltered() succ = utility._singlesuccessor(repo, unfi[startnode]) - hg.updaterepo(repo, repo[succ].node(), False) + compat.update(repo[succ]) if repo[b'.'].node() != startnode: ui.status(_(b'working directory is now at %s\n') % repo[b'.']) @@ -1638,7 +1638,7 @@ # `hg next --evolve` in play if evolvestate[b'command'] != b'evolve': pctx = repo[b'.'] - hg.updaterepo(repo, pctx.node(), True) + compat.clean_update(pctx) ui.status(_(b'evolve aborted\n')) ui.status(_(b'working directory is now at %s\n') % pctx.hex()[:12]) @@ -1795,20 +1795,20 @@ if olddiv: with repo.wlock(), repo.lock(): repo = repo.unfiltered() - hg.updaterepo(repo, olddiv, True) + pctx = repo[olddiv] + compat.clean_update(pctx) repair.strip(ui, repo, strips, False) updated = True - pctx = repo[olddiv] elif oldother: with repo.wlock(), repo.lock(): repo = repo.unfiltered() - hg.updaterepo(repo, oldother, True) + pctx = repo[oldother] + compat.clean_update(pctx) repair.strip(ui, repo, strips, False) updated = True - pctx = repo[oldother] if not updated: pctx = repo[b'.'] - hg.updaterepo(repo, pctx.node(), True) + compat.clean_update(pctx) ui.status(_(b'stopped the interrupted evolve\n')) ui.status(_(b'working directory is now at %s\n') % pctx) @@ -1869,7 +1869,7 @@ for c in repo.set(b'roots(%ld)', evolvedrevs)] # updating the working directory - hg.updaterepo(repo, startnode, True) + compat.clean_update(repo[startnode]) # Strip from the first evolved revision if evolvedrevs: @@ -1897,7 +1897,7 @@ evolvestate.load() if evolvestate[b'command'] != b'evolve': pctx = repo[b'.'] - hg.updaterepo(repo, pctx.node(), True) + compat.clean_update(pctx) ui.status(_(b'evolve aborted\n')) ui.status(_(b'working directory is now at %s\n') % pctx.hex()[:12]) diff -r 24a1ff0677a7 -r 947820d4b476 hgext3rd/evolve/rewind.py --- a/hgext3rd/evolve/rewind.py Fri Oct 02 09:51:45 2020 -0700 +++ b/hgext3rd/evolve/rewind.py Fri Oct 02 10:09:14 2020 -0700 @@ -6,7 +6,6 @@ from mercurial import ( cmdutil, error, - hg, obsolete, obsutil, scmutil, @@ -123,7 +122,7 @@ obsolete.createmarkers(unfi, relationships, operation=b'rewind') if update_target is not None: if opts.get('keep'): - hg.updaterepo(repo, oldctx, True) + compat.clean_update(oldctx) # This is largely the same as the implementation in # strip.stripcmd() and cmdrewrite.cmdprune(). @@ -160,7 +159,7 @@ else: cmdutil.revert(repo.ui, repo, oldctx, **revertopts) else: - hg.updaterepo(repo, update_target, False) + compat.update(repo[update_target]) repo.ui.status(_(b'rewinded to %d changesets\n') % len(rewinded)) if relationships: