# HG changeset patch # User Anton Shestakov # Date 1628027063 -10800 # Node ID f408cc176befd6ea61b99e253839082036742fd1 # Parent bfa47d370b2cd75da6fc119b2339245449fb7ea6 evolve: move movedirstate() to compat diff -r bfa47d370b2c -r f408cc176bef hgext3rd/evolve/cmdrewrite.py --- a/hgext3rd/evolve/cmdrewrite.py Tue May 04 09:39:45 2021 -0700 +++ b/hgext3rd/evolve/cmdrewrite.py Wed Aug 04 00:44:23 2021 +0300 @@ -340,52 +340,6 @@ newid = repo.commitctx(new) return newid -# TODO: call core's version once we've dropped support for hg <= 4.9 -def movedirstate(repo, newctx, match=None): - """Move the dirstate to newctx and adjust it as necessary. - - A matcher can be provided as an optimization. It is probably a bug to pass - a matcher that doesn't match all the differences between the parent of the - working copy and newctx. - """ - oldctx = repo[b'.'] - ds = repo.dirstate - dscopies = dict(ds.copies()) - ds.setparents(newctx.node(), node.nullid) - s = newctx.status(oldctx, match=match) - for f in s.modified: - if ds[f] == b'r': - # modified + removed -> removed - continue - ds.normallookup(f) - - for f in s.added: - if ds[f] == b'r': - # added + removed -> unknown - ds.drop(f) - elif ds[f] != b'a': - ds.add(f) - - for f in s.removed: - if ds[f] == b'a': - # removed + added -> normal - ds.normallookup(f) - elif ds[f] != b'r': - ds.remove(f) - - # Merge old parent and old working dir copies - oldcopies = copies.pathcopies(newctx, oldctx, match) - oldcopies.update(dscopies) - newcopies = { - dst: oldcopies.get(src, src) - for dst, src in oldcopies.items() - } - # Adjust the dirstate copies - for dst, src in newcopies.items(): - if src not in newctx or dst in newctx or ds[dst] != b'a': - src = None - ds.copy(src, dst) - @eh.command( b'uncommit', [(b'a', b'all', None, _(b'uncommit all changes when no arguments given')), @@ -515,7 +469,7 @@ compat.clean_update(repo[newid]) else: with repo.dirstate.parentchange(), compat.parentchange(repo): - movedirstate(repo, repo[newid], match) + compat.movedirstate(repo, repo[newid], match) if not repo[newid].files(): ui.warn(_(b"new changeset is empty\n")) ui.status(_(b"(use 'hg prune .' to remove it)\n")) diff -r bfa47d370b2c -r f408cc176bef hgext3rd/evolve/compat.py --- a/hgext3rd/evolve/compat.py Tue May 04 09:39:45 2021 -0700 +++ b/hgext3rd/evolve/compat.py Wed Aug 04 00:44:23 2021 +0300 @@ -15,6 +15,7 @@ hg, logcmdutil, merge as mergemod, + node, obsolete, registrar, repair, @@ -432,3 +433,50 @@ def format_changeset_summary_fn(ui, repo, command, default_spec): return logcmdutil.changesetdisplayer(ui, repo, {b'template': default_spec}).show + +if True: + # TODO: call core's version once we've dropped support for hg <= 4.9 + def movedirstate(repo, newctx, match=None): + """Move the dirstate to newctx and adjust it as necessary. + + A matcher can be provided as an optimization. It is probably a bug to pass + a matcher that doesn't match all the differences between the parent of the + working copy and newctx. + """ + oldctx = repo[b'.'] + ds = repo.dirstate + dscopies = dict(ds.copies()) + ds.setparents(newctx.node(), node.nullid) + s = newctx.status(oldctx, match=match) + for f in s.modified: + if ds[f] == b'r': + # modified + removed -> removed + continue + ds.normallookup(f) + + for f in s.added: + if ds[f] == b'r': + # added + removed -> unknown + ds.drop(f) + elif ds[f] != b'a': + ds.add(f) + + for f in s.removed: + if ds[f] == b'a': + # removed + added -> normal + ds.normallookup(f) + elif ds[f] != b'r': + ds.remove(f) + + # Merge old parent and old working dir copies + oldcopies = copies.pathcopies(newctx, oldctx, match) + oldcopies.update(dscopies) + newcopies = { + dst: oldcopies.get(src, src) + for dst, src in oldcopies.items() + } + # Adjust the dirstate copies + for dst, src in newcopies.items(): + if src not in newctx or dst in newctx or ds[dst] != b'a': + src = None + ds.copy(src, dst) diff -r bfa47d370b2c -r f408cc176bef hgext3rd/evolve/evolvecmd.py --- a/hgext3rd/evolve/evolvecmd.py Tue May 04 09:39:45 2021 -0700 +++ b/hgext3rd/evolve/evolvecmd.py Wed Aug 04 00:44:23 2021 +0300 @@ -37,7 +37,6 @@ from mercurial.i18n import _ from . import ( - cmdrewrite, compat, exthelper, rewriteutil, @@ -618,7 +617,7 @@ otherdiv = other if other.mutable() else divergent with repo.dirstate.parentchange(), compat.parentchange(repo): - cmdrewrite.movedirstate(repo, repo[publicnode]) + compat.movedirstate(repo, repo[publicnode]) # check if node to be committed has changes same as public one s = publicdiv.status() if not (s.added or s.removed or s.deleted or s.modified): @@ -631,7 +630,7 @@ return (True, publicnode) with repo.dirstate.parentchange(), compat.parentchange(repo): - cmdrewrite.movedirstate(repo, repo[resparent]) + compat.movedirstate(repo, repo[resparent]) # merge the branches mergebranches(repo, divergent, other, base)