dirstate: use a `added` parameter to _addpath
My next target are the explicit `state` byte, so let start with abstracting
their initial storage.
Differential Revision: https://phab.mercurial-scm.org/D10967
--- a/mercurial/dirstate.py Sat Jul 03 20:59:26 2021 +0200
+++ b/mercurial/dirstate.py Sun Jul 04 01:42:10 2021 +0200
@@ -443,15 +443,16 @@
def _addpath(
self,
f,
- state,
- mode,
+ state=None,
+ mode=0,
size=None,
mtime=None,
+ added=False,
from_p2=False,
possibly_dirty=False,
):
entry = self._map.get(f)
- if state == b'a' or entry is not None and entry.removed:
+ if added or entry is not None and entry.removed:
scmutil.checkfilename(f)
if self._map.hastrackeddir(f):
msg = _(b'directory %r already in dirstate')
@@ -474,6 +475,7 @@
mode=mode,
size=size,
mtime=mtime,
+ added=added,
from_p2=from_p2,
possibly_dirty=possibly_dirty,
)
@@ -544,7 +546,7 @@
def add(self, f):
'''Mark a file added.'''
- self._addpath(f, b'a', 0)
+ self._addpath(f, added=True)
self._map.copymap.pop(f, None)
def remove(self, f):
--- a/mercurial/dirstatemap.py Sat Jul 03 20:59:26 2021 +0200
+++ b/mercurial/dirstatemap.py Sun Jul 04 01:42:10 2021 +0200
@@ -147,17 +147,19 @@
def addfile(
self,
f,
- state,
- mode,
+ state=None,
+ mode=0,
size=None,
mtime=None,
+ added=False,
from_p2=False,
possibly_dirty=False,
):
"""Add a tracked file to the dirstate."""
- if state == b'a':
+ if added:
assert not possibly_dirty
assert not from_p2
+ state = b'a'
size = NONNORMAL
mtime = AMBIGUOUS_TIME
elif from_p2:
@@ -168,10 +170,12 @@
size = NONNORMAL
mtime = AMBIGUOUS_TIME
else:
+ assert state != b'a'
assert size != FROM_P2
assert size != NONNORMAL
size = size & rangemask
mtime = mtime & rangemask
+ assert state is not None
assert size is not None
assert mtime is not None
old_entry = self.get(f)
@@ -461,10 +465,11 @@
def addfile(
self,
f,
- state,
- mode,
+ state=None,
+ mode=0,
size=None,
mtime=None,
+ added=False,
from_p2=False,
possibly_dirty=False,
):
@@ -474,6 +479,7 @@
mode,
size,
mtime,
+ added,
from_p2,
possibly_dirty,
)
--- a/rust/hg-core/src/dirstate/dirstate_map.rs Sat Jul 03 20:59:26 2021 +0200
+++ b/rust/hg-core/src/dirstate/dirstate_map.rs Sun Jul 04 01:42:10 2021 +0200
@@ -70,13 +70,15 @@
filename: &HgPath,
entry: DirstateEntry,
// XXX once the dust settle this should probably become an enum
+ added: bool,
from_p2: bool,
possibly_dirty: bool,
) -> Result<(), DirstateError> {
let mut entry = entry;
- if entry.state == EntryState::Added {
+ if added {
assert!(!possibly_dirty);
assert!(!from_p2);
+ entry.state = EntryState::Added;
entry.size = SIZE_NON_NORMAL;
entry.mtime = MTIME_UNSET;
} else if from_p2 {
@@ -407,6 +409,7 @@
},
false,
false,
+ false,
)
.unwrap();
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs Sat Jul 03 20:59:26 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs Sun Jul 04 01:42:10 2021 +0200
@@ -722,13 +722,15 @@
&mut self,
filename: &HgPath,
entry: DirstateEntry,
+ added: bool,
from_p2: bool,
possibly_dirty: bool,
) -> Result<(), DirstateError> {
let mut entry = entry;
- if entry.state == EntryState::Added {
+ if added {
assert!(!possibly_dirty);
assert!(!from_p2);
+ entry.state = EntryState::Added;
entry.size = SIZE_NON_NORMAL;
entry.mtime = MTIME_UNSET;
} else if from_p2 {
--- a/rust/hg-core/src/dirstate_tree/dispatch.rs Sat Jul 03 20:59:26 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dispatch.rs Sun Jul 04 01:42:10 2021 +0200
@@ -48,6 +48,7 @@
&mut self,
filename: &HgPath,
entry: DirstateEntry,
+ added: bool,
from_p2: bool,
possibly_dirty: bool,
) -> Result<(), DirstateError>;
@@ -287,10 +288,11 @@
&mut self,
filename: &HgPath,
entry: DirstateEntry,
+ added: bool,
from_p2: bool,
possibly_dirty: bool,
) -> Result<(), DirstateError> {
- self.add_file(filename, entry, from_p2, possibly_dirty)
+ self.add_file(filename, entry, added, from_p2, possibly_dirty)
}
fn remove_file(
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs Sat Jul 03 20:59:26 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs Sun Jul 04 01:42:10 2021 +0200
@@ -112,17 +112,28 @@
mode: PyObject,
size: PyObject,
mtime: PyObject,
+ added: PyObject,
from_p2: PyObject,
possibly_dirty: PyObject,
) -> PyResult<PyObject> {
let f = f.extract::<PyBytes>(py)?;
let filename = HgPath::new(f.data(py));
- let state = state.extract::<PyBytes>(py)?.data(py)[0]
+ let state = if state.is_none(py) {
+ // Arbitrary default value
+ EntryState::Normal
+ } else {
+ state.extract::<PyBytes>(py)?.data(py)[0]
.try_into()
.map_err(|e: HgError| {
PyErr::new::<exc::ValueError, _>(py, e.to_string())
- })?;
- let mode = mode.extract(py)?;
+ })?
+ };
+ let mode = if mode.is_none(py) {
+ // fallback default value
+ 0
+ } else {
+ mode.extract(py)?
+ };
let size = if size.is_none(py) {
// fallback default value
SIZE_NON_NORMAL
@@ -141,11 +152,13 @@
size: size,
mtime: mtime,
};
+ let added = added.extract::<PyBool>(py)?.is_true();
let from_p2 = from_p2.extract::<PyBool>(py)?.is_true();
let possibly_dirty = possibly_dirty.extract::<PyBool>(py)?.is_true();
self.inner(py).borrow_mut().add_file(
filename,
entry,
+ added,
from_p2,
possibly_dirty
).and(Ok(py.None())).or_else(|e: DirstateError| {
--- a/rust/hg-cpython/src/dirstate/dispatch.rs Sat Jul 03 20:59:26 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/dispatch.rs Sun Jul 04 01:42:10 2021 +0200
@@ -25,11 +25,17 @@
&mut self,
filename: &HgPath,
entry: DirstateEntry,
+ added: bool,
from_p2: bool,
possibly_dirty: bool,
) -> Result<(), DirstateError> {
- self.get_mut()
- .add_file(filename, entry, from_p2, possibly_dirty)
+ self.get_mut().add_file(
+ filename,
+ entry,
+ added,
+ from_p2,
+ possibly_dirty,
+ )
}
fn remove_file(