D7823: workingctx: move setparents() logic from localrepo to mirror overlayworkingctx

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Sat Jan 11 06:47:55 UTC 2020


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  It would be nice to later be able to call `wctx.setparents()` whether
  `wctx` is a `workingctx` or an `overlayworkingctx`.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D7823

AFFECTED FILES
  mercurial/context.py
  mercurial/localrepo.py

CHANGE DETAILS

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1886,20 +1886,7 @@
         return self.vfs.reljoin(self.root, f, *insidef)
 
     def setparents(self, p1, p2=nullid):
-        with self.dirstate.parentchange():
-            copies = self.dirstate.setparents(p1, p2)
-            pctx = self[p1]
-            if copies:
-                # Adjust copy records, the dirstate cannot do it, it
-                # requires access to parents manifests. Preserve them
-                # only for entries added to first parent.
-                for f in copies:
-                    if f not in pctx and copies[f] in pctx:
-                        self.dirstate.copy(copies[f], f)
-            if p2 == nullid:
-                for f, s in sorted(self.dirstate.copies().items()):
-                    if f not in pctx and s not in pctx:
-                        self.dirstate.copy(None, f)
+        self[None].setparents(p1, p2)
 
     def filectx(self, path, changeid=None, fileid=None, changectx=None):
         """changeid must be a changeset revision, if specified.
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1528,6 +1528,23 @@
             for n in p
         ]
 
+    def setparents(self, p1node, p2node=nullid):
+        dirstate = self._repo.dirstate
+        with dirstate.parentchange():
+            copies = dirstate.setparents(p1node, p2node)
+            pctx = self._repo[p1node]
+            if copies:
+                # Adjust copy records, the dirstate cannot do it, it
+                # requires access to parents manifests. Preserve them
+                # only for entries added to first parent.
+                for f in copies:
+                    if f not in pctx and copies[f] in pctx:
+                        dirstate.copy(copies[f], f)
+            if p2node == nullid:
+                for f, s in sorted(dirstate.copies().items()):
+                    if f not in pctx and s not in pctx:
+                        dirstate.copy(None, f)
+
     def _fileinfo(self, path):
         # populate __dict__['_manifest'] as workingctx has no _manifestdelta
         self._manifest



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list