[Request] [+- ] D11493: dirstate: Replace dropfile with drop_item_and_copy_source

SimonSapin phabricator at mercurial-scm.org
Thu Sep 23 17:43:38 UTC 2021


SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Those removing a DirstateItem and a copy source are always done together

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11493

AFFECTED FILES
  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

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs b/rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs
@@ -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)
     }
diff --git a/rust/hg-core/src/dirstate_tree/owning_dispatch.rs b/rust/hg-core/src/dirstate_tree/owning_dispatch.rs
--- a/rust/hg-core/src/dirstate_tree/owning_dispatch.rs
+++ b/rust/hg-core/src/dirstate_tree/owning_dispatch.rs
@@ -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(
diff --git a/rust/hg-core/src/dirstate_tree/dispatch.rs b/rust/hg-core/src/dirstate_tree/dispatch.rs
--- a/rust/hg-core/src/dirstate_tree/dispatch.rs
+++ b/rust/hg-core/src/dirstate_tree/dispatch.rs
@@ -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(
diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -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
diff --git a/rust/hg-core/src/dirstate/dirstate_map.rs b/rust/hg-core/src/dirstate/dirstate_map.rs
--- a/rust/hg-core/src/dirstate/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate/dirstate_map.rs
@@ -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(())
     }
 
diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -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)
 



To: SimonSapin, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20210923/8003b2f6/attachment-0001.html>


More information about the Mercurial-patches mailing list