context: filter out invalid copies from workingctx.p[12]copies()
authorMartin von Zweigbergk <martinvonz@google.com>
Mon, 19 Aug 2019 15:43:27 -0700
changeset 42859 2b869a515ba6
parent 42858 170b070ec6a5
child 42860 6f0273558c4b
context: filter out invalid copies from workingctx.p[12]copies() workingctx normally gets its lists of modified, added, removed files etc. based on the dirstate status. Its constructor also accepts a "changes" argument to override the status from the dirstate. This is used for partial commits. If a "changed" argument was passed, we should clearly also filter out copies to those paths, which I had previously missed. This patch adds that filtering and fixes the bugs demonstrated in the previous patch. Differential Revision: https://phab.mercurial-scm.org/D6750
mercurial/context.py
tests/test-copies-in-changeset.t
--- a/mercurial/context.py	Mon Aug 19 12:30:02 2019 -0700
+++ b/mercurial/context.py	Mon Aug 19 15:43:27 2019 -0700
@@ -1558,9 +1558,10 @@
         parents = self._repo.dirstate.parents()
         p1manifest = self._repo[parents[0]].manifest()
         p2manifest = self._repo[parents[1]].manifest()
+        changedset = set(self.added()) | set(self.modified())
         narrowmatch = self._repo.narrowmatch()
         for dst, src in self._repo.dirstate.copies().items():
-            if not narrowmatch(dst):
+            if dst not in changedset or not narrowmatch(dst):
                 continue
             if src in p1manifest:
                 p1copies[dst] = src
--- a/tests/test-copies-in-changeset.t	Mon Aug 19 12:30:02 2019 -0700
+++ b/tests/test-copies-in-changeset.t	Mon Aug 19 15:43:27 2019 -0700
@@ -197,13 +197,37 @@
   $ echo a2 > a
   $ hg mv b c
   $ hg ci -m 'modify a, move b to c'
-  $ (hg --config ui.interactive=yes split 2>&1 | grep mercurial.error) <<EOF
+  $ hg --config ui.interactive=yes split <<EOF
   > y
   > y
   > n
   > y
   > EOF
-  mercurial.error.ProgrammingError: some copy targets missing from file list
+  diff --git a/a b/a
+  1 hunks, 1 lines changed
+  examine changes to 'a'?
+  (enter ? for help) [Ynesfdaq?] y
+  
+  @@ -1,1 +1,1 @@
+  -a
+  +a2
+  record this change to 'a'?
+  (enter ? for help) [Ynesfdaq?] y
+  
+  diff --git a/b b/c
+  rename from b
+  rename to c
+  examine changes to 'b' and 'c'?
+  (enter ? for help) [Ynesfdaq?] n
+  
+  created new head
+  diff --git a/b b/c
+  rename from b
+  rename to c
+  examine changes to 'b' and 'c'?
+  (enter ? for help) [Ynesfdaq?] y
+  
+  saved backup bundle to $TESTTMP/split/.hg/strip-backup/9a396d463e04-2d9e6864-split.hg
   $ cd ..
 
 Test committing half a rename
@@ -213,6 +237,5 @@
   $ echo a > a
   $ hg ci -Aqm 'add a'
   $ hg mv a b
-  $ hg ci -m 'remove a' a 2>&1 | grep mercurial.error
-  mercurial.error.ProgrammingError: some copy targets missing from file list
+  $ hg ci -m 'remove a' a
   $ cd ..