# HG changeset patch # User Pierre-Yves David # Date 2021-07-03 18:59:26 # Node ID 69a463a4f193aaa406910725789b7addc0ab636c # Parent b76d54b90dc93a10d22289cf91fc957c10ca3230 dirstate: no longer pass the `oldstate` value to the dirstatemap The dirstatemap already have this information. Differential Revision: https://phab.mercurial-scm.org/D10966 diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -450,7 +450,6 @@ class dirstate(object): from_p2=False, possibly_dirty=False, ): - oldstate = self[f] entry = self._map.get(f) if state == b'a' or entry is not None and entry.removed: scmutil.checkfilename(f) @@ -471,7 +470,6 @@ class dirstate(object): self._updatedfiles.add(f) self._map.addfile( f, - oldstate, state=state, mode=mode, size=size, diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py --- a/mercurial/dirstatemap.py +++ b/mercurial/dirstatemap.py @@ -147,7 +147,6 @@ class dirstatemap(object): def addfile( self, f, - oldstate, state, mode, size=None, @@ -175,9 +174,12 @@ class dirstatemap(object): mtime = mtime & rangemask assert size is not None assert mtime is not None - if oldstate in b"?r" and "_dirs" in self.__dict__: + old_entry = self.get(f) + if ( + old_entry is None or old_entry.removed + ) and "_dirs" in self.__dict__: self._dirs.addpath(f) - if oldstate == b"?" and "_alldirs" in self.__dict__: + if old_entry is None and "_alldirs" in self.__dict__: self._alldirs.addpath(f) self._map[f] = dirstatetuple(state, mode, size, mtime) if state != b'n' or mtime == AMBIGUOUS_TIME: @@ -459,7 +461,6 @@ if rustmod is not None: def addfile( self, f, - oldstate, state, mode, size=None, @@ -469,7 +470,6 @@ if rustmod is not None: ): return self._rustmap.addfile( f, - oldstate, state, mode, size, 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 @@ -68,7 +68,6 @@ impl DirstateMap { pub fn add_file( &mut self, filename: &HgPath, - old_state: EntryState, entry: DirstateEntry, // XXX once the dust settle this should probably become an enum from_p2: bool, @@ -91,7 +90,10 @@ impl DirstateMap { entry.size = entry.size & V1_RANGEMASK; entry.mtime = entry.mtime & V1_RANGEMASK; } - + let old_state = match self.get(filename) { + Some(e) => e.state, + None => EntryState::Unknown, + }; if old_state == EntryState::Unknown || old_state == EntryState::Removed { if let Some(ref mut dirs) = self.dirs { @@ -397,7 +399,6 @@ mod tests { map.add_file( HgPath::new(b"meh"), - EntryState::Normal, DirstateEntry { state: EntryState::Normal, mode: 1337, 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 @@ -721,7 +721,6 @@ impl<'on_disk> super::dispatch::Dirstate fn add_file( &mut self, filename: &HgPath, - old_state: EntryState, entry: DirstateEntry, from_p2: bool, possibly_dirty: bool, @@ -744,6 +743,11 @@ impl<'on_disk> super::dispatch::Dirstate entry.mtime = entry.mtime & V1_RANGEMASK; } + let old_state = match self.get(filename)? { + Some(e) => e.state, + None => EntryState::Unknown, + }; + Ok(self.add_or_remove_file(filename, old_state, entry)?) } 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 @@ -47,7 +47,6 @@ pub trait DirstateMapMethods { fn add_file( &mut self, filename: &HgPath, - old_state: EntryState, entry: DirstateEntry, from_p2: bool, possibly_dirty: bool, @@ -287,12 +286,11 @@ impl DirstateMapMethods for DirstateMap fn add_file( &mut self, filename: &HgPath, - old_state: EntryState, entry: DirstateEntry, from_p2: bool, possibly_dirty: bool, ) -> Result<(), DirstateError> { - self.add_file(filename, old_state, entry, from_p2, possibly_dirty) + self.add_file(filename, entry, from_p2, possibly_dirty) } fn remove_file( 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 @@ -108,7 +108,6 @@ py_class!(pub class DirstateMap |py| { def addfile( &self, f: PyObject, - oldstate: PyObject, state: PyObject, mode: PyObject, size: PyObject, @@ -118,11 +117,6 @@ py_class!(pub class DirstateMap |py| { ) -> PyResult { let f = f.extract::(py)?; let filename = HgPath::new(f.data(py)); - let oldstate = oldstate.extract::(py)?.data(py)[0] - .try_into() - .map_err(|e: HgError| { - PyErr::new::(py, e.to_string()) - })?; let state = state.extract::(py)?.data(py)[0] .try_into() .map_err(|e: HgError| { @@ -151,7 +145,6 @@ py_class!(pub class DirstateMap |py| { let possibly_dirty = possibly_dirty.extract::(py)?.is_true(); self.inner(py).borrow_mut().add_file( filename, - oldstate, entry, from_p2, possibly_dirty 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 @@ -24,18 +24,12 @@ impl DirstateMapMethods for OwningDirsta fn add_file( &mut self, filename: &HgPath, - old_state: EntryState, entry: DirstateEntry, from_p2: bool, possibly_dirty: bool, ) -> Result<(), DirstateError> { - self.get_mut().add_file( - filename, - old_state, - entry, - from_p2, - possibly_dirty, - ) + self.get_mut() + .add_file(filename, entry, from_p2, possibly_dirty) } fn remove_file(