diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -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] 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/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 { + 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/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 { + fn drop_file(&mut self, filename: &HgPath) -> Result { + 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_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; + fn drop_file(&mut self, filename: &HgPath) -> Result; /// 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 { - self.drop_file(filename, old_state) + fn drop_file(&mut self, filename: &HgPath) -> Result { + self.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 { self.inner(py).borrow_mut() .drop_file( HgPath::new(f.extract::(py)?.data(py)), - oldstate.extract::(py)?.data(py)[0] - .try_into() - .map_err(|e: HgError| { - PyErr::new::(py, e.to_string()) - })?, ) .and_then(|b| Ok(b.to_py_object(py))) .or_else(|e| { 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 { - self.get_mut().drop_file(filename, old_state) + fn drop_file(&mut self, filename: &HgPath) -> Result { + self.get_mut().drop_file(filename) } fn clear_ambiguous_times(