changeset 5984:f408cc176bef stable

evolve: move movedirstate() to compat
author Anton Shestakov <av6@dwimlabs.net>
date Wed, 04 Aug 2021 00:44:23 +0300
parents bfa47d370b2c
children b7cb6e46c9c6
files hgext3rd/evolve/cmdrewrite.py hgext3rd/evolve/compat.py hgext3rd/evolve/evolvecmd.py
diffstat 3 files changed, 51 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- 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"))
--- 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)
--- 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)