# HG changeset patch # User Martin von Zweigbergk # Date 1601658554 25200 # Node ID 7f8055eb07c719e7ee27f37d50492bcab8be220d # Parent d72ef23a42914543bc0734fe4c2526b65fb64d7f 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 d72ef23a4291 -r 7f8055eb07c7 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 @@ scmutil.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) @@ -1497,7 +1497,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 d72ef23a4291 -r 7f8055eb07c7 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, @@ -394,3 +395,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 d72ef23a4291 -r 7f8055eb07c7 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 @@ -594,7 +594,7 @@ if local not in repo[None].parents(): repo.ui.note(_(b"updating to \"local\" side of the conflict: %s\n") % local.hex()[:12]) - hg.updaterepo(repo, local.node(), False) + compat.update(local) # merging the two content-divergent changesets repo.ui.note(_(b"merging \"other\" %s changeset '%s'\n") % (TROUBLES['CONTENTDIVERGENT'], other.hex()[:12])) @@ -689,7 +689,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 haspublicdiv and publicdiv == divergent: bypassphase(repo, (divergent, new), operation=b'evolve') else: @@ -1419,7 +1419,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'.']) @@ -1637,7 +1637,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]) @@ -1788,20 +1788,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) @@ -1862,7 +1862,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: @@ -1890,7 +1890,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 d72ef23a4291 -r 7f8055eb07c7 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, node as nodemod, obsolete, obsutil, @@ -132,7 +131,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(). @@ -169,7 +168,7 @@ else: cmdutil.revert(repo.ui, repo, oldctx, **revertopts) else: - hg.updaterepo(repo, update_target, False) + compat.update(repo[update_target]) ui.status(_(b'rewound to %d changesets\n') % len(targets)) if relationships: