copies: detect files as `touched/salvaged` if they only existed on one side
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 15 Mar 2021 13:37:45 +0100
changeset 46814 c52c3c4cbd3f
parent 46813 316a768f2e43
child 46815 433cef8f3104
copies: detect files as `touched/salvaged` if they only existed on one side The file cannot be merged if there was content to merge on the other side. So the previous record was wrong. In the general case, the file existed only on one side and got touched during the merge. So it should detected as touched. They are a special case where the merge manually prevent the file to be deleted. In this case the file is marked as `salvaged`. The result of this `salvaged` recording, copy-tracing-wise, is the same as recording it as `merged`. This is probably why they were recorded as `merged` in the first place. Differential Revision: https://phab.mercurial-scm.org/D10219
mercurial/metadata.py
tests/test-copies-chain-merge.t
--- a/mercurial/metadata.py	Tue Mar 02 02:00:29 2021 +0100
+++ b/mercurial/metadata.py	Mon Mar 15 13:37:45 2021 +0100
@@ -322,12 +322,12 @@
     β”‚ (Some, None) β”‚      OR      β”‚πŸ„»  Deleted    β”‚       ΓΈ      β”‚      ΓΈ       β”‚
     β”‚              β”‚πŸ„·  Deleted[1] β”‚              β”‚              β”‚              β”‚
     β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
-    β”‚              β”‚πŸ„Έ  No Changes β”‚              β”‚              β”‚              β”‚
-    β”‚ (None, Some) β”‚     OR       β”‚      ΓΈ       β”‚πŸ„Ό   Added     β”‚πŸ„½   Merged    β”‚
+    β”‚              β”‚πŸ„Έ  No Changes β”‚              β”‚              β”‚   πŸ„½ Touched  β”‚
+    β”‚ (None, Some) β”‚     OR       β”‚      ΓΈ       β”‚πŸ„Ό   Added     β”‚OR πŸ…€ Salvaged β”‚
     β”‚              β”‚πŸ„Ή  Salvaged[2]β”‚              β”‚   (copied?)  β”‚   (copied?)  β”‚
     β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
-    β”‚              β”‚              β”‚              β”‚              β”‚              β”‚
-    β”‚ (Some, Some) β”‚πŸ„Ί  No Changes β”‚      ΓΈ       β”‚πŸ„Ύ   Merged    β”‚πŸ„Ώ   Merged    β”‚
+    β”‚              β”‚              β”‚              β”‚   πŸ„Ύ Touched  β”‚              β”‚
+    β”‚ (Some, Some) β”‚πŸ„Ί  No Changes β”‚      ΓΈ       β”‚OR πŸ… Salvaged β”‚πŸ„Ώ   Merged    β”‚
     β”‚              β”‚     [3]      β”‚              β”‚   (copied?)  β”‚   (copied?)  β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 
@@ -454,8 +454,16 @@
                 # case πŸ„» β€” both deleted the file.
                 md.mark_removed(filename)
             elif d1[1][0] is not None and d2[1][0] is not None:
-                # case πŸ„½ πŸ„Ύ πŸ„Ώ
-                md.mark_merged(filename)
+                if d1[0][0] is None or d2[0][0] is None:
+                    if any(_find(ma, filename) is not None for ma in mas):
+                        # case πŸ…€ or πŸ…
+                        md.mark_salvaged(filename)
+                    else:
+                        # case πŸ„½ πŸ„Ύ : touched
+                        md.mark_touched(filename)
+                else:
+                    # case πŸ„Ώ : merged
+                    md.mark_merged(filename)
                 copy_candidates.append(filename)
             else:
                 # Impossible case, the post-merge file status cannot be None on
--- a/tests/test-copies-chain-merge.t	Tue Mar 02 02:00:29 2021 +0100
+++ b/tests/test-copies-chain-merge.t	Mon Mar 15 13:37:45 2021 +0100
@@ -1987,29 +1987,13 @@
   ##### revision "mCB-change-m-0 merge explicitely revive deleted file - B side" #####
   1 sidedata entries
    entry-0014 size 14
-    '\x00\x00\x00\x01\x10\x00\x00\x00\x01\x00\x00\x00\x00d' (no-upgraded no-upgraded-parallel !)
-  salvaged   : d, ; (no-upgraded no-upgraded-parallel !)
-    '\x00\x00\x00\x01\x08\x00\x00\x00\x01\x00\x00\x00\x00d' (upgraded known-bad-output !)
-  merged     : d, ; (upgraded known-bad-output !)
-    '\x00\x00\x00\x01\x10\x00\x00\x00\x01\x00\x00\x00\x00d' (upgraded missing-correct-output !)
-  salvaged   : d, ; (upgraded missing-correct-output !)
-    '\x00\x00\x00\x01\x08\x00\x00\x00\x01\x00\x00\x00\x00d' (upgraded-parallel known-bad-output !)
-  merged     : d, ; (upgraded-parallel known-bad-output !)
-    '\x00\x00\x00\x01\x10\x00\x00\x00\x01\x00\x00\x00\x00d' (upgraded-parallel missing-correct-output !)
-  salvaged   : d, ; (upgraded-parallel missing-correct-output !)
+    '\x00\x00\x00\x01\x10\x00\x00\x00\x01\x00\x00\x00\x00d'
+  salvaged   : d, ;
   ##### revision "mBC-change-m-0 merge explicitely revive deleted file - B side" #####
   1 sidedata entries
    entry-0014 size 14
-    '\x00\x00\x00\x01\x10\x00\x00\x00\x01\x00\x00\x00\x00d' (no-upgraded no-upgraded-parallel !)
-  salvaged   : d, ; (no-upgraded no-upgraded-parallel !)
-    '\x00\x00\x00\x01\x08\x00\x00\x00\x01\x00\x00\x00\x00d' (upgraded known-bad-output !)
-  merged     : d, ; (upgraded known-bad-output !)
-    '\x00\x00\x00\x01\x10\x00\x00\x00\x01\x00\x00\x00\x00d' (upgraded missing-correct-output !)
-  salvaged   : d, ; (upgraded missing-correct-output !)
-    '\x00\x00\x00\x01\x08\x00\x00\x00\x01\x00\x00\x00\x00d' (upgraded-parallel known-bad-output !)
-  merged     : d, ; (upgraded-parallel known-bad-output !)
-    '\x00\x00\x00\x01\x10\x00\x00\x00\x01\x00\x00\x00\x00d' (upgraded-parallel missing-correct-output !)
-  salvaged   : d, ; (upgraded-parallel missing-correct-output !)
+    '\x00\x00\x00\x01\x10\x00\x00\x00\x01\x00\x00\x00\x00d'
+  salvaged   : d, ;
   ##### revision "j-1" #####
   1 sidedata entries
    entry-0014 size 24
@@ -2031,21 +2015,13 @@
   ##### revision "mEA,Jm" #####
   1 sidedata entries
    entry-0014 size 24
-    '\x00\x00\x00\x01\x14\x00\x00\x00\x0b\x00\x00\x00\x00unrelated-j' (no-upgraded no-upgraded-parallel !)
-  touched    : unrelated-j, ; (no-upgraded no-upgraded-parallel !)
-    '\x00\x00\x00\x01\x08\x00\x00\x00\x0b\x00\x00\x00\x00unrelated-j' (upgraded known-bad-output !)
-  merged     : unrelated-j, ; (upgraded known-bad-output !)
-    '\x00\x00\x00\x01\x08\x00\x00\x00\x0b\x00\x00\x00\x00unrelated-j' (upgraded-parallel known-bad-output !)
-  merged     : unrelated-j, ; (upgraded-parallel known-bad-output !)
+    '\x00\x00\x00\x01\x14\x00\x00\x00\x0b\x00\x00\x00\x00unrelated-j'
+  touched    : unrelated-j, ;
   ##### revision "mJ,EAm" #####
   1 sidedata entries
    entry-0014 size 24
-    '\x00\x00\x00\x01\x14\x00\x00\x00\x0b\x00\x00\x00\x00unrelated-j' (no-upgraded no-upgraded-parallel !)
-  touched    : unrelated-j, ; (no-upgraded no-upgraded-parallel !)
-    '\x00\x00\x00\x01\x08\x00\x00\x00\x0b\x00\x00\x00\x00unrelated-j' (upgraded known-bad-output !)
-  merged     : unrelated-j, ; (upgraded known-bad-output !)
-    '\x00\x00\x00\x01\x08\x00\x00\x00\x0b\x00\x00\x00\x00unrelated-j' (upgraded-parallel known-bad-output !)
-  merged     : unrelated-j, ; (upgraded-parallel known-bad-output !)
+    '\x00\x00\x00\x01\x14\x00\x00\x00\x0b\x00\x00\x00\x00unrelated-j'
+  touched    : unrelated-j, ;
   ##### revision "s-1" #####
   1 sidedata entries
    entry-0014 size 24
@@ -3560,9 +3536,7 @@
   $ hg status --copies --rev 'desc("i-0")' --rev 'desc("mCB-change-m-0")'
   M b
   A d
-    a (no-compatibility no-changeset no-upgraded no-upgraded-parallel !)
-    a (upgraded missing-correct-output !)
-    a (upgraded-parallel missing-correct-output !)
+    a (no-compatibility no-changeset !)
   A t
     p
   R a