changeset 47535:6025353c9c55

dirstate: no longer pass `oldstate` to the `dropfile` The `oldstate` value come literally from `_map` so we don't need to pass tha information along. Differential Revision: https://phab.mercurial-scm.org/D10978
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 04 Jul 2021 02:28:08 +0200
parents e53a42dce923
children 8e4b9fe31334
files mercurial/dirstate.py 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-cpython/src/dirstate/dirstate_map.rs rust/hg-cpython/src/dirstate/dispatch.rs
diffstat 7 files changed, 22 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Sun Jul 04 02:21:59 2021 +0200
+++ b/mercurial/dirstate.py	Sun Jul 04 02:28:08 2021 +0200
@@ -563,8 +563,7 @@
 
     def drop(self, f):
         '''Drop a file from the dirstate'''
-        oldstate = self[f]
-        if self._map.dropfile(f, oldstate):
+        if self._map.dropfile(f):
             self._dirty = True
             self._updatedfiles.add(f)
             self._map.copymap.pop(f, None)
@@ -1308,7 +1307,6 @@
             # general. That is much slower than simply accessing and storing the
             # tuple members one by one.
             t = dget(fn)
-            state = t.state
             mode = t[1]
             size = t[2]
             time = t[3]
--- a/mercurial/dirstatemap.py	Sun Jul 04 02:21:59 2021 +0200
+++ b/mercurial/dirstatemap.py	Sun Jul 04 02:28:08 2021 +0200
@@ -235,12 +235,17 @@
         self._map[f] = dirstatetuple(b'r', 0, size, 0)
         self.nonnormalset.add(f)
 
-    def dropfile(self, f, oldstate):
+    def dropfile(self, f):
         """
         Remove a file from the dirstate.  Returns True if the file was
         previously recorded.
         """
-        exists = self._map.pop(f, None) is not None
+        old_entry = self._map.pop(f, None)
+        exists = False
+        oldstate = b'?'
+        if old_entry is not None:
+            exists = True
+            oldstate = old_entry.state
         if exists:
             if oldstate != b"r" and "_dirs" in self.__dict__:
                 self._dirs.delpath(f)
--- a/rust/hg-core/src/dirstate/dirstate_map.rs	Sun Jul 04 02:21:59 2021 +0200
+++ b/rust/hg-core/src/dirstate/dirstate_map.rs	Sun Jul 04 02:28:08 2021 +0200
@@ -205,8 +205,11 @@
     pub fn drop_file(
         &mut self,
         filename: &HgPath,
-        old_state: EntryState,
     ) -> Result<bool, DirstateError> {
+        let old_state = match self.get(filename) {
+            Some(e) => e.state,
+            None => EntryState::Unknown,
+        };
         let exists = self.state_map.remove(filename).is_some();
 
         if exists {
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Sun Jul 04 02:21:59 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Sun Jul 04 02:28:08 2021 +0200
@@ -803,11 +803,11 @@
         Ok(self.add_or_remove_file(filename, old_state, entry)?)
     }
 
-    fn drop_file(
-        &mut self,
-        filename: &HgPath,
-        old_state: EntryState,
-    ) -> Result<bool, DirstateError> {
+    fn drop_file(&mut self, filename: &HgPath) -> Result<bool, DirstateError> {
+        let old_state = match self.get(filename)? {
+            Some(e) => e.state,
+            None => EntryState::Unknown,
+        };
         struct Dropped {
             was_tracked: bool,
             had_entry: bool,
--- a/rust/hg-core/src/dirstate_tree/dispatch.rs	Sun Jul 04 02:21:59 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dispatch.rs	Sun Jul 04 02:28:08 2021 +0200
@@ -10,7 +10,6 @@
 use crate::DirstateMap;
 use crate::DirstateParents;
 use crate::DirstateStatus;
-use crate::EntryState;
 use crate::PatternFileWarning;
 use crate::StateMapIter;
 use crate::StatusError;
@@ -74,11 +73,7 @@
     ///
     /// `old_state` is the state in the entry that `get` would have returned
     /// before this call, or `EntryState::Unknown` if there was no such entry.
-    fn drop_file(
-        &mut self,
-        filename: &HgPath,
-        old_state: EntryState,
-    ) -> Result<bool, DirstateError>;
+    fn drop_file(&mut self, filename: &HgPath) -> Result<bool, DirstateError>;
 
     /// Among given files, mark the stored `mtime` as ambiguous if there is one
     /// (if `state == EntryState::Normal`) equal to the given current Unix
@@ -305,12 +300,8 @@
         self.remove_file(filename, in_merge)
     }
 
-    fn drop_file(
-        &mut self,
-        filename: &HgPath,
-        old_state: EntryState,
-    ) -> Result<bool, DirstateError> {
-        self.drop_file(filename, old_state)
+    fn drop_file(&mut self, filename: &HgPath) -> Result<bool, DirstateError> {
+        self.drop_file(filename)
     }
 
     fn clear_ambiguous_times(
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs	Sun Jul 04 02:21:59 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs	Sun Jul 04 02:28:08 2021 +0200
@@ -32,7 +32,6 @@
     dirstate::SIZE_NON_NORMAL,
     dirstate_tree::dispatch::DirstateMapMethods,
     dirstate_tree::on_disk::DirstateV2ParseError,
-    errors::HgError,
     revlog::Node,
     utils::files::normalize_case,
     utils::hg_path::{HgPath, HgPathBuf},
@@ -181,16 +180,10 @@
     def dropfile(
         &self,
         f: PyObject,
-        oldstate: PyObject
     ) -> PyResult<PyBool> {
         self.inner(py).borrow_mut()
             .drop_file(
                 HgPath::new(f.extract::<PyBytes>(py)?.data(py)),
-                oldstate.extract::<PyBytes>(py)?.data(py)[0]
-                    .try_into()
-                    .map_err(|e: HgError| {
-                        PyErr::new::<exc::ValueError, _>(py, e.to_string())
-                    })?,
             )
             .and_then(|b| Ok(b.to_py_object(py)))
             .or_else(|e| {
--- a/rust/hg-cpython/src/dirstate/dispatch.rs	Sun Jul 04 02:21:59 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/dispatch.rs	Sun Jul 04 02:28:08 2021 +0200
@@ -9,7 +9,6 @@
 use hg::DirstateError;
 use hg::DirstateParents;
 use hg::DirstateStatus;
-use hg::EntryState;
 use hg::PatternFileWarning;
 use hg::StateMapIter;
 use hg::StatusError;
@@ -48,12 +47,8 @@
         self.get_mut().remove_file(filename, in_merge)
     }
 
-    fn drop_file(
-        &mut self,
-        filename: &HgPath,
-        old_state: EntryState,
-    ) -> Result<bool, DirstateError> {
-        self.get_mut().drop_file(filename, old_state)
+    fn drop_file(&mut self, filename: &HgPath) -> Result<bool, DirstateError> {
+        self.get_mut().drop_file(filename)
     }
 
     fn clear_ambiguous_times(