# HG changeset patch # User Pierre-Yves David # Date 2021-09-29 12:51:31 # Node ID 79bc60ca5946dc1912b7c8866db95ee0332deccc # Parent 80783e553bd57bd9581a497644b7fb7c17024c95 dirstate-item: introduce a `any_tracked` property This property is True is the file is tracked anywhere, either the working copy, or any of the parent. Differential Revision: https://phab.mercurial-scm.org/D11524 diff --git a/mercurial/cext/parsers.c b/mercurial/cext/parsers.c --- a/mercurial/cext/parsers.c +++ b/mercurial/cext/parsers.c @@ -635,6 +635,18 @@ static PyObject *dirstate_item_get_maybe } }; +static PyObject *dirstate_item_get_any_tracked(dirstateItemObject *self) +{ + unsigned char mask = dirstate_flag_wc_tracked | + dirstate_flag_p1_tracked | + dirstate_flag_p2_tracked; + if ((self->flags & mask) != 0) { + Py_RETURN_TRUE; + } else { + Py_RETURN_FALSE; + } +}; + static PyObject *dirstate_item_get_removed(dirstateItemObject *self) { if (dirstate_item_c_removed(self)) { @@ -655,6 +667,8 @@ static PyGetSetDef dirstate_item_getset[ {"from_p2", (getter)dirstate_item_get_from_p2, NULL, "from_p2", NULL}, {"maybe_clean", (getter)dirstate_item_get_maybe_clean, NULL, "maybe_clean", NULL}, + {"any_tracked", (getter)dirstate_item_get_any_tracked, NULL, "any_tracked", + NULL}, {"removed", (getter)dirstate_item_get_removed, NULL, "removed", NULL}, {NULL} /* Sentinel */ }; diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py --- a/mercurial/pure/parsers.py +++ b/mercurial/pure/parsers.py @@ -314,6 +314,11 @@ class DirstateItem(object): return self._wc_tracked @property + def any_tracked(self): + """True is the file is tracked anywhere (wc or parents)""" + return self._wc_tracked or self._p1_tracked or self._p2_tracked + + @property def added(self): """True if the file has been added""" return self._wc_tracked and not (self._p1_tracked or self._p2_tracked) diff --git a/rust/hg-core/src/dirstate/entry.rs b/rust/hg-core/src/dirstate/entry.rs --- a/rust/hg-core/src/dirstate/entry.rs +++ b/rust/hg-core/src/dirstate/entry.rs @@ -205,6 +205,12 @@ impl DirstateEntry { } } + pub fn any_tracked(&self) -> bool { + self.flags.intersects( + Flags::WDIR_TRACKED | Flags::P1_TRACKED | Flags::P2_TRACKED, + ) + } + pub fn state(&self) -> EntryState { if self.removed() { EntryState::Removed diff --git a/rust/hg-cpython/src/dirstate/item.rs b/rust/hg-cpython/src/dirstate/item.rs --- a/rust/hg-cpython/src/dirstate/item.rs +++ b/rust/hg-cpython/src/dirstate/item.rs @@ -90,6 +90,11 @@ py_class!(pub class DirstateItem |py| { Ok(self.entry(py).get().maybe_clean()) } + @property + def any_tracked(&self) -> PyResult { + Ok(self.entry(py).get().any_tracked()) + } + def v1_state(&self) -> PyResult { let (state, _mode, _size, _mtime) = self.entry(py).get().v1_data(); let state_byte: u8 = state.into();