Mercurial > evolve
changeset 6375:fcbca44dd0df
compat: implement changing_parents context manager
It combines the compatibility layer for the recently renamed changing_parents
(was parentchange) on dirstate class with _quick_access_* handling code into
one context manager, which should be slightly more pleasant to use.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Mon, 30 Jan 2023 19:19:52 +0400 |
parents | 28355b173fd5 |
children | 5c8196a550b6 |
files | hgext3rd/evolve/cmdrewrite.py hgext3rd/evolve/compat.py hgext3rd/evolve/evolvecmd.py |
diffstat | 3 files changed, 17 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/cmdrewrite.py Fri Jan 27 18:43:11 2023 +0400 +++ b/hgext3rd/evolve/cmdrewrite.py Mon Jan 30 19:19:52 2023 +0400 @@ -473,7 +473,7 @@ if opts.get('revert'): compat.clean_update(repo[newid]) else: - with repo.dirstate.parentchange(), compat.parentchange(repo): + with compat.changing_parents(repo): compat.movedirstate(repo, repo[newid], match) if not repo[newid].files(): ui.warn(_(b"new changeset is empty\n")) @@ -1329,7 +1329,7 @@ tr = repo.currenttransaction() phases.retractboundary(repo, tr, ctx.phase(), [new]) if ctx in repo[None].parents(): - with repo.dirstate.parentchange(), compat.parentchange(repo): + with compat.changing_parents(repo): repo.dirstate.setparents(new, node.nullid) @eh.command(
--- a/hgext3rd/evolve/compat.py Fri Jan 27 18:43:11 2023 +0400 +++ b/hgext3rd/evolve/compat.py Mon Jan 30 19:19:52 2023 +0400 @@ -337,9 +337,15 @@ return cl.nodemap.get @contextlib.contextmanager -def parentchange(repo): +def changing_parents(repo): + if util.safehasattr(repo.dirstate, 'changing_parents'): + changing_parents = repo.dirstate.changing_parents(repo) + else: + # hg <= 6.3 (7a8bfc05b691) + changing_parents = repo.dirstate.parentchange() try: - yield + with changing_parents: + yield finally: # hg <= 5.2 (85c4cd73996b) if util.safehasattr(repo, '_quick_access_changeid_invalidate'):
--- a/hgext3rd/evolve/evolvecmd.py Fri Jan 27 18:43:11 2023 +0400 +++ b/hgext3rd/evolve/evolvecmd.py Mon Jan 30 19:19:52 2023 +0400 @@ -282,7 +282,7 @@ flag=obsolete.bumpedfix, operation=b'evolve') bmupdate(newid) # reroute the working copy parent to the new changeset - with repo.dirstate.parentchange(), compat.parentchange(repo): + with compat.changing_parents(repo): repo.dirstate.setparents(newid, nodemod.nullid) return (True, replacementnode) @@ -615,7 +615,7 @@ publicdiv = repo[publicnode] otherdiv = other if other.mutable() else divergent - with repo.dirstate.parentchange(), compat.parentchange(repo): + with compat.changing_parents(repo): compat.movedirstate(repo, repo[publicnode]) # check if node to be committed has changes same as public one s = publicdiv.status() @@ -628,7 +628,7 @@ compat.mergestate.clean(repo) return (True, publicnode) - with repo.dirstate.parentchange(), compat.parentchange(repo): + with compat.changing_parents(repo): compat.movedirstate(repo, repo[resparent]) # merge the branches @@ -2223,14 +2223,14 @@ # p1 is obsolete and p2 is not obsolete, current working # directory parent should be successor of p1, so we should # set dirstate parents to (succ of p1, p2) - with repo.dirstate.parentchange(), compat.parentchange(repo): + with compat.changing_parents(repo): repo.dirstate.setparents(currentp1, ctxparents[1].node()) elif p2obs and not p1obs: # p2 is obsolete and p1 is not obsolete, current working # directory parent should be successor of p2, so we should # set dirstate parents to (succ of p2, p1) - with repo.dirstate.parentchange(), compat.parentchange(repo): + with compat.changing_parents(repo): repo.dirstate.setparents(ctxparents[0].node(), currentp1) @@ -2238,12 +2238,12 @@ # both the parents were obsoleted, if orphanmerge is set, we # are processing the second parent first (to keep parent order) if evolvestate.get(b'orphanmerge'): - with repo.dirstate.parentchange(), compat.parentchange(repo): + with compat.changing_parents(repo): repo.dirstate.setparents(ctxparents[0].node(), currentp1) pass else: - with repo.dirstate.parentchange(), compat.parentchange(repo): + with compat.changing_parents(repo): repo.dirstate.setparents(repo.dirstate.p1(), nodemod.nullid) with repo.ui.configoverride(overrides, b'evolve-continue'):