changeset 45821:ff7e0ca666e8

copies: make sure deleted copy info do not overwriting unrelated ones See test documentation for details. This is yet another corner case for copy tracing. Differential Revision: https://phab.mercurial-scm.org/D9200
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 13 Oct 2020 05:15:44 +0200
parents 5b6c0af021da
children 84eb4c833c41
files mercurial/copies.py tests/test-copies-chain-merge.t tests/test-copies.t
diffstat 3 files changed, 111 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/copies.py	Wed Oct 21 22:30:42 2020 +0200
+++ b/mercurial/copies.py	Tue Oct 13 05:15:44 2020 +0200
@@ -400,7 +400,10 @@
             elif changes is not None and dest in changes.merged:
                 minor[dest] = value
             elif not isancestor(new_tt, other_tt):
-                minor[dest] = value
+                if value[1] is not None:
+                    minor[dest] = value
+                elif isancestor(other_tt, new_tt):
+                    minor[dest] = value
 
 
 def _revinfo_getter_extra(repo):
--- a/tests/test-copies-chain-merge.t	Wed Oct 21 22:30:42 2020 +0200
+++ b/tests/test-copies-chain-merge.t	Tue Oct 13 05:15:44 2020 +0200
@@ -585,6 +585,50 @@
 
   $ hg up null --quiet
 
+Merging a branch where a rename was deleted with a branch where the same file was renamed
+------------------------------------------------------------------------------------------
+
+Create a "conflicting" merge where `d` get removed on one branch before its
+rename information actually conflict with the other branch.
+
+(the copy information from the branch that was not deleted should win).
+
+  $ hg up 'desc("i-0")'
+  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg mv b d
+  $ hg ci -m "h-1: b -(move)-> d"
+  created new head
+
+  $ hg up 'desc("c-1")'
+  1 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ hg merge 'desc("h-1")'
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg ci -m "mCH-delete-before-conflict-m-0"
+
+  $ hg up 'desc("h-1")'
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg merge 'desc("c-1")'
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg ci -m "mHC-delete-before-conflict-m-0"
+  created new head
+  $ hg log -G --rev '::(desc("mCH-delete-before-conflict-m")+desc("mHC-delete-before-conflict-m"))'
+  @    36 mHC-delete-before-conflict-m-0
+  |\
+  +---o  35 mCH-delete-before-conflict-m-0
+  | |/
+  | o  34 h-1: b -(move)-> d
+  | |
+  o |  6 c-1 delete d
+  | |
+  o |  2 i-2: c -move-> d
+  | |
+  o |  1 i-1: a -move-> c
+  |/
+  o  0 i-0 initial commit: a b h
+  
+
 
 Test that sidedata computations during upgrades are correct
 ===========================================================
@@ -801,6 +845,20 @@
    entry-0014 size 14
     '\x00\x00\x00\x01\x10\x00\x00\x00\x01\x00\x00\x00\x00d'
   salvaged   : d, ;
+  ##### revision 34 #####
+  1 sidedata entries
+   entry-0014 size 24
+    '\x00\x00\x00\x02\x0c\x00\x00\x00\x01\x00\x00\x00\x00\x06\x00\x00\x00\x02\x00\x00\x00\x00bd'
+  removed    : b, ;
+  added    p1: d, b;
+  ##### revision 35 #####
+  1 sidedata entries
+   entry-0014 size 4
+    '\x00\x00\x00\x00'
+  ##### revision 36 #####
+  1 sidedata entries
+   entry-0014 size 4
+    '\x00\x00\x00\x00'
 
 #endif
 
@@ -1558,3 +1616,51 @@
   A d
   $ hg status --copies --rev 'desc("b-1")' --rev 'desc("mCB-revert-m-0")'
   $ hg status --copies --rev 'desc("b-1")' --rev 'desc("mBC-revert-m-0")'
+
+
+Merging a branch where a rename was deleted with a branch where the same file was renamed
+------------------------------------------------------------------------------------------
+
+Create a "conflicting" merge where `d` get removed on one branch before its
+rename information actually conflict with the other branch.
+
+(the copy information from the branch that was not deleted should win).
+
+  $ hg log -G --rev '::(desc("mCH-delete-before-conflict-m")+desc("mHC-delete-before-conflict-m"))'
+  @    36 mHC-delete-before-conflict-m-0
+  |\
+  +---o  35 mCH-delete-before-conflict-m-0
+  | |/
+  | o  34 h-1: b -(move)-> d
+  | |
+  o |  6 c-1 delete d
+  | |
+  o |  2 i-2: c -move-> d
+  | |
+  o |  1 i-1: a -move-> c
+  |/
+  o  0 i-0 initial commit: a b h
+  
+
+  $ hg status --copies --rev 'desc("i-0")' --rev 'desc("mCH-delete-before-conflict-m")'
+  A d
+    b (no-compatibility no-changeset !)
+  R a
+  R b
+  $ hg status --copies --rev 'desc("i-0")' --rev 'desc("mHC-delete-before-conflict-m")'
+  A d
+    b
+  R a
+  R b
+  $ hg status --copies --rev 'desc("c-1")' --rev 'desc("mCH-delete-before-conflict-m")'
+  A d
+    b
+  R b
+  $ hg status --copies --rev 'desc("c-1")' --rev 'desc("mHC-delete-before-conflict-m")'
+  A d
+    b
+  R b
+  $ hg status --copies --rev 'desc("h-1")' --rev 'desc("mCH-delete-before-conflict-m")'
+  R a
+  $ hg status --copies --rev 'desc("h-1")' --rev 'desc("mHC-delete-before-conflict-m")'
+  R a
--- a/tests/test-copies.t	Wed Oct 21 22:30:42 2020 +0200
+++ b/tests/test-copies.t	Tue Oct 13 05:15:44 2020 +0200
@@ -502,7 +502,7 @@
   $ hg debugpathcopies 2 4
   x -> z (no-filelog !)
   $ hg debugpathcopies 0 4
-  x -> z (filelog !)
+  x -> z (no-changeset no-compatibility !)
   $ hg debugpathcopies 1 5
   $ hg debugpathcopies 2 5
   x -> z (no-filelog !)