dirstate: no longer pass the `oldstate` value to the dirstatemap
The dirstatemap already have this information.
Differential Revision: https://phab.mercurial-scm.org/D10966
--- a/mercurial/dirstate.py Sat Jul 03 20:57:44 2021 +0200
+++ b/mercurial/dirstate.py Sat Jul 03 20:59:26 2021 +0200
@@ -450,7 +450,6 @@
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 @@
self._updatedfiles.add(f)
self._map.addfile(
f,
- oldstate,
state=state,
mode=mode,
size=size,
--- a/mercurial/dirstatemap.py Sat Jul 03 20:57:44 2021 +0200
+++ b/mercurial/dirstatemap.py Sat Jul 03 20:59:26 2021 +0200
@@ -147,7 +147,6 @@
def addfile(
self,
f,
- oldstate,
state,
mode,
size=None,
@@ -175,9 +174,12 @@
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 @@
def addfile(
self,
f,
- oldstate,
state,
mode,
size=None,
@@ -469,7 +470,6 @@
):
return self._rustmap.addfile(
f,
- oldstate,
state,
mode,
size,
--- a/rust/hg-core/src/dirstate/dirstate_map.rs Sat Jul 03 20:57:44 2021 +0200
+++ b/rust/hg-core/src/dirstate/dirstate_map.rs Sat Jul 03 20:59:26 2021 +0200
@@ -68,7 +68,6 @@
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 @@
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 @@
map.add_file(
HgPath::new(b"meh"),
- EntryState::Normal,
DirstateEntry {
state: EntryState::Normal,
mode: 1337,
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs Sat Jul 03 20:57:44 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs Sat Jul 03 20:59:26 2021 +0200
@@ -721,7 +721,6 @@
fn add_file(
&mut self,
filename: &HgPath,
- old_state: EntryState,
entry: DirstateEntry,
from_p2: bool,
possibly_dirty: bool,
@@ -744,6 +743,11 @@
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)?)
}
--- a/rust/hg-core/src/dirstate_tree/dispatch.rs Sat Jul 03 20:57:44 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dispatch.rs Sat Jul 03 20:59:26 2021 +0200
@@ -47,7 +47,6 @@
fn add_file(
&mut self,
filename: &HgPath,
- old_state: EntryState,
entry: DirstateEntry,
from_p2: bool,
possibly_dirty: bool,
@@ -287,12 +286,11 @@
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(
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs Sat Jul 03 20:57:44 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs Sat Jul 03 20:59:26 2021 +0200
@@ -108,7 +108,6 @@
def addfile(
&self,
f: PyObject,
- oldstate: PyObject,
state: PyObject,
mode: PyObject,
size: PyObject,
@@ -118,11 +117,6 @@
) -> PyResult<PyObject> {
let f = f.extract::<PyBytes>(py)?;
let filename = HgPath::new(f.data(py));
- let oldstate = oldstate.extract::<PyBytes>(py)?.data(py)[0]
- .try_into()
- .map_err(|e: HgError| {
- PyErr::new::<exc::ValueError, _>(py, e.to_string())
- })?;
let state = state.extract::<PyBytes>(py)?.data(py)[0]
.try_into()
.map_err(|e: HgError| {
@@ -151,7 +145,6 @@
let possibly_dirty = possibly_dirty.extract::<PyBool>(py)?.is_true();
self.inner(py).borrow_mut().add_file(
filename,
- oldstate,
entry,
from_p2,
possibly_dirty
--- a/rust/hg-cpython/src/dirstate/dispatch.rs Sat Jul 03 20:57:44 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/dispatch.rs Sat Jul 03 20:59:26 2021 +0200
@@ -24,18 +24,12 @@
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(