D10978: dirstate: no longer pass `oldstate` to the `dropfile`

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Sun Jul 4 21:56:06 UTC 2021


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

REVISION SUMMARY
  The `oldstate` value come literally from `_map` so we don't need to pass tha
  information along.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED 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

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/dispatch.rs b/rust/hg-cpython/src/dirstate/dispatch.rs
--- a/rust/hg-cpython/src/dirstate/dispatch.rs
+++ b/rust/hg-cpython/src/dirstate/dispatch.rs
@@ -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(
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
@@ -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| {
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
@@ -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(
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
@@ -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,
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
@@ -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 {
diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -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)
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -564,8 +564,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)
@@ -1309,7 +1308,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]



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel


More information about the Mercurial-devel mailing list