copies-rust: record "overwritten" information from both side on delete
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 16 Dec 2020 11:06:58 +0100
changeset 46620 d6d57bfc1a1b
parent 46619 2076df13d00f
child 46621 b0a3ca02d17a
copies-rust: record "overwritten" information from both side on delete With this change, we can ensure every (`dest`, `rev`) points to the same value, making a lots of comparison simpler. Differential Revision: https://phab.mercurial-scm.org/D9652
rust/hg-core/src/copy_tracing.rs
--- a/rust/hg-core/src/copy_tracing.rs	Wed Dec 16 10:59:00 2020 +0100
+++ b/rust/hg-core/src/copy_tracing.rs	Wed Dec 16 11:06:58 2020 +0100
@@ -75,6 +75,19 @@
         self.path = None;
     }
 
+    /// Mark pre-existing copy information as "dropped" by a file deletion
+    ///
+    /// Use this when recording copy information from  parent → child edges
+    fn mark_delete_with_pair(&mut self, rev: Revision, other: &Self) {
+        self.overwritten.insert(self.rev);
+        if other.rev != rev {
+            self.overwritten.insert(other.rev);
+        }
+        self.overwritten.extend(other.overwritten.iter().copied());
+        self.rev = rev;
+        self.path = None;
+    }
+
     fn is_overwritten_by(&self, other: &Self) -> bool {
         other.overwritten.contains(&self.rev)
     }
@@ -535,8 +548,10 @@
                         e.get_mut().mark_delete(current_rev)
                     }
                     (Some(mut e1), Some(mut e2)) => {
-                        e1.get_mut().mark_delete(current_rev);
-                        e2.get_mut().mark_delete(current_rev);
+                        let cs1 = e1.get_mut();
+                        let cs2 = e2.get();
+                        cs1.mark_delete_with_pair(current_rev, &cs2);
+                        e2.insert(cs1.clone());
                     }
                 }
             }