diff mercurial/context.py @ 44052:b74270da5eee

workingctx: move setparents() logic from localrepo to mirror overlayworkingctx It would be nice to later be able to call `wctx.setparents()` whether `wctx` is a `workingctx` or an `overlayworkingctx`. Differential Revision: https://phab.mercurial-scm.org/D7823
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 10 Jan 2020 13:24:25 -0800
parents 436d106de670
children 85c4cd73996b
line wrap: on
line diff
--- a/mercurial/context.py	Fri Jan 10 21:41:28 2020 -0800
+++ b/mercurial/context.py	Fri Jan 10 13:24:25 2020 -0800
@@ -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