dirstate: Replace dropfile with drop_item_and_copy_source
authorSimon Sapin <simon.sapin@octobus.net>
Thu, 23 Sep 2021 15:36:43 +0200
changeset 48050 2ac0e6b23222
parent 48049 29aa633815db
child 48051 98c0408324e6
dirstate: Replace dropfile with drop_item_and_copy_source Those removing a DirstateItem and a copy source are always done together Differential Revision: https://phab.mercurial-scm.org/D11493
mercurial/dirstatemap.py
rust/hg-core/src/dirstate/dirstate_map.rs
rust/hg-core/src/dirstate_tree/dirstate_map.rs
rust/hg-core/src/dirstate_tree/dispatch.rs
rust/hg-core/src/dirstate_tree/owning_dispatch.rs
rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/mercurial/dirstatemap.py	Thu Sep 23 15:29:38 2021 +0200
+++ b/mercurial/dirstatemap.py	Thu Sep 23 15:36:43 2021 +0200
@@ -606,7 +606,7 @@
             self.copymap.pop(filename, None)
 
             if not (p1_tracked or p2_tracked or wc_tracked):
-                self.dropfile(filename)
+                self._rustmap.drop_item_and_copy_source(filename)
             elif merged:
                 # XXX might be merged and removed ?
                 entry = self.get(filename)
@@ -684,8 +684,7 @@
                 return False
             else:
                 if entry.added:
-                    self._rustmap.copymap().pop(f, None)
-                    self._rustmap.dropfile(f)
+                    self._rustmap.drop_item_and_copy_source(f)
                 else:
                     self._rustmap.removefile(f, in_merge=True)
                 return True
@@ -693,10 +692,6 @@
         def removefile(self, *args, **kwargs):
             return self._rustmap.removefile(*args, **kwargs)
 
-        def dropfile(self, f, *args, **kwargs):
-            self._rustmap.copymap().pop(f, None)
-            self._rustmap.dropfile(f, *args, **kwargs)
-
         def clearambiguoustimes(self, *args, **kwargs):
             return self._rustmap.clearambiguoustimes(*args, **kwargs)
 
--- a/rust/hg-core/src/dirstate/dirstate_map.rs	Thu Sep 23 15:29:38 2021 +0200
+++ b/rust/hg-core/src/dirstate/dirstate_map.rs	Thu Sep 23 15:36:43 2021 +0200
@@ -195,7 +195,7 @@
 
     /// Remove a file from the dirstate.
     /// Returns `true` if the file was previously recorded.
-    pub fn drop_file(
+    pub fn drop_entry_and_copy_source(
         &mut self,
         filename: &HgPath,
     ) -> Result<(), DirstateError> {
@@ -216,6 +216,8 @@
             .0
             .remove(filename);
 
+        self.copy_map.remove(filename);
+
         Ok(())
     }
 
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Thu Sep 23 15:29:38 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Thu Sep 23 15:36:43 2021 +0200
@@ -845,7 +845,10 @@
         Ok(self.add_or_remove_file(filename, old_state, entry)?)
     }
 
-    fn drop_file(&mut self, filename: &HgPath) -> Result<(), DirstateError> {
+    fn drop_entry_and_copy_source(
+        &mut self,
+        filename: &HgPath,
+    ) -> Result<(), DirstateError> {
         let was_tracked = self
             .get(filename)?
             .map_or(false, |e| e.state().is_tracked());
@@ -907,7 +910,8 @@
                     node.data = NodeData::None
                 }
                 if let Some(source) = &node.copy_source {
-                    DirstateMap::count_dropped_path(unreachable_bytes, source)
+                    DirstateMap::count_dropped_path(unreachable_bytes, source);
+                    node.copy_source = None
                 }
                 dropped = Dropped {
                     was_tracked: node
--- a/rust/hg-core/src/dirstate_tree/dispatch.rs	Thu Sep 23 15:29:38 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dispatch.rs	Thu Sep 23 15:36:43 2021 +0200
@@ -66,7 +66,10 @@
     /// Drop information about this file from the map if any.
     ///
     /// `get` will now return `None` for this filename.
-    fn drop_file(&mut self, filename: &HgPath) -> Result<(), DirstateError>;
+    fn drop_entry_and_copy_source(
+        &mut self,
+        filename: &HgPath,
+    ) -> Result<(), DirstateError>;
 
     /// Among given files, mark the stored `mtime` as ambiguous if there is one
     /// (if `state == EntryState::Normal`) equal to the given current Unix
@@ -339,8 +342,11 @@
         self.remove_file(filename, in_merge)
     }
 
-    fn drop_file(&mut self, filename: &HgPath) -> Result<(), DirstateError> {
-        self.drop_file(filename)
+    fn drop_entry_and_copy_source(
+        &mut self,
+        filename: &HgPath,
+    ) -> Result<(), DirstateError> {
+        self.drop_entry_and_copy_source(filename)
     }
 
     fn clear_ambiguous_times(
--- a/rust/hg-core/src/dirstate_tree/owning_dispatch.rs	Thu Sep 23 15:29:38 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/owning_dispatch.rs	Thu Sep 23 15:36:43 2021 +0200
@@ -55,8 +55,11 @@
         self.get_mut().remove_file(filename, in_merge)
     }
 
-    fn drop_file(&mut self, filename: &HgPath) -> Result<(), DirstateError> {
-        self.get_mut().drop_file(filename)
+    fn drop_entry_and_copy_source(
+        &mut self,
+        filename: &HgPath,
+    ) -> Result<(), DirstateError> {
+        self.get_mut().drop_entry_and_copy_source(filename)
     }
 
     fn clear_ambiguous_times(
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs	Thu Sep 23 15:29:38 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs	Thu Sep 23 15:36:43 2021 +0200
@@ -210,13 +210,13 @@
         Ok(py.None())
     }
 
-    def dropfile(
+    def drop_item_and_copy_source(
         &self,
         f: PyBytes,
     ) -> PyResult<PyNone> {
         self.inner(py)
             .borrow_mut()
-            .drop_file(HgPath::new(f.data(py)))
+            .drop_entry_and_copy_source(HgPath::new(f.data(py)))
             .map_err(|e |dirstate_error(py, e))?;
         Ok(PyNone)
     }