changeset 46159:929054848d6c

copies: properly match result during changeset centric copy tracing By filtering "during" the iteration we were excluding rename information that were not in the matched set but that file served as base information for the matched set. We now do all copy tracing matching at the end of the process to ensure we raise proper result. If we were aggregating information top down instead of bottom up we could do filtering during processing. However, we don't. Differential Revision: https://phab.mercurial-scm.org/D9585
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 13 Dec 2020 20:16:34 +0100
parents 1fcfff09cac5
children 1d6aac94e6d5
files mercurial/copies.py tests/test-copies-chain-merge.t
diffstat 2 files changed, 19 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/copies.py	Sun Dec 13 20:26:27 2020 +0100
+++ b/mercurial/copies.py	Sun Dec 13 20:16:34 2020 +0100
@@ -196,9 +196,7 @@
 
     changelogrevision = cl.changelogrevision
 
-    alwaysmatch = match.always()
-
-    if rustmod is not None and alwaysmatch:
+    if rustmod is not None:
 
         def revinfo(rev):
             p1, p2 = parents(rev)
@@ -356,7 +354,7 @@
 
     alwaysmatch = match.always()
 
-    if rustmod is not None and alwaysmatch:
+    if rustmod is not None:
         final_copies = rustmod.combine_changeset_copies(
             list(revs), children_count, targetrev, revinfo, isancestor
         )
@@ -396,12 +394,6 @@
                     elif parent == 2:
                         childcopies = changes.copied_from_p2
 
-                    if not alwaysmatch:
-                        childcopies = {
-                            dst: src
-                            for dst, src in childcopies.items()
-                            if match(dst)
-                        }
                     if childcopies:
                         newcopies = copies.copy()
                         for dest, source in pycompat.iteritems(childcopies):
@@ -447,6 +439,10 @@
         for dest, (tt, source) in all_copies[targetrev].items():
             if source is not None:
                 final_copies[dest] = source
+    if not alwaysmatch:
+        for filename in list(final_copies.keys()):
+            if not match(filename):
+                del final_copies[filename]
     return final_copies
 
 
--- a/tests/test-copies-chain-merge.t	Sun Dec 13 20:26:27 2020 +0100
+++ b/tests/test-copies-chain-merge.t	Sun Dec 13 20:16:34 2020 +0100
@@ -872,6 +872,19 @@
 Test copy information chaining
 ==============================
 
+Check that matching only affect the destination and not intermediate path
+-------------------------------------------------------------------------
+
+The two status call should give the same value for f
+
+  $ hg status --copies --rev 'desc("i-0")' --rev 'desc("a-2")'
+  A f
+    a
+  R a
+  $ hg status --copies --rev 'desc("i-0")' --rev 'desc("a-2")' f
+  A f
+    a (no-changeset no-compatibility !)
+
 merging with unrelated change does not interfere with the renames
 ---------------------------------------------------------------