Mercurial > hg
changeset 48086:80783e553bd5
dirstate-item: introduce a `maybe_clean` property
It is useful for some extension that seek to invalidate some state.
Differential Revision: https://phab.mercurial-scm.org/D11523
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 29 Sep 2021 14:41:19 +0200 |
parents | 6a78715e56c8 |
children | 79bc60ca5946 |
files | mercurial/cext/parsers.c mercurial/pure/parsers.py rust/hg-core/src/dirstate/entry.rs rust/hg-cpython/src/dirstate/item.rs |
diffstat | 4 files changed, 49 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cext/parsers.c Wed Sep 29 02:37:24 2021 +0200 +++ b/mercurial/cext/parsers.c Wed Sep 29 14:41:19 2021 +0200 @@ -620,6 +620,21 @@ } }; +static PyObject *dirstate_item_get_maybe_clean(dirstateItemObject *self) +{ + if (!(self->flags & dirstate_flag_wc_tracked)) { + Py_RETURN_FALSE; + } else if (dirstate_item_c_added(self)) { + Py_RETURN_FALSE; + } else if (self->flags & dirstate_flag_merged) { + Py_RETURN_FALSE; + } else if (self->flags & dirstate_flag_clean_p2) { + Py_RETURN_FALSE; + } else { + Py_RETURN_TRUE; + } +}; + static PyObject *dirstate_item_get_removed(dirstateItemObject *self) { if (dirstate_item_c_removed(self)) { @@ -638,6 +653,8 @@ {"added", (getter)dirstate_item_get_added, NULL, "added", NULL}, {"merged", (getter)dirstate_item_get_merged, NULL, "merged", NULL}, {"from_p2", (getter)dirstate_item_get_from_p2, NULL, "from_p2", NULL}, + {"maybe_clean", (getter)dirstate_item_get_maybe_clean, NULL, "maybe_clean", + NULL}, {"removed", (getter)dirstate_item_get_removed, NULL, "removed", NULL}, {NULL} /* Sentinel */ };
--- a/mercurial/pure/parsers.py Wed Sep 29 02:37:24 2021 +0200 +++ b/mercurial/pure/parsers.py Wed Sep 29 14:41:19 2021 +0200 @@ -319,6 +319,19 @@ return self._wc_tracked and not (self._p1_tracked or self._p2_tracked) @property + def maybe_clean(self): + """True if the file has a chance to be in the "clean" state""" + if not self._wc_tracked: + return False + elif self.added: + return False + elif self._merged: + return False + elif self._clean_p2: + return False + return True + + @property def merged(self): """True if the file has been merged
--- a/rust/hg-core/src/dirstate/entry.rs Wed Sep 29 02:37:24 2021 +0200 +++ b/rust/hg-core/src/dirstate/entry.rs Wed Sep 29 14:41:19 2021 +0200 @@ -191,6 +191,20 @@ self.flags.contains(Flags::WDIR_TRACKED | Flags::CLEAN_P2) } + pub fn maybe_clean(&self) -> bool { + if !self.flags.contains(Flags::WDIR_TRACKED) { + false + } else if self.added() { + false + } else if self.flags.contains(Flags::MERGED) { + false + } else if self.flags.contains(Flags::CLEAN_P2) { + false + } else { + true + } + } + pub fn state(&self) -> EntryState { if self.removed() { EntryState::Removed
--- a/rust/hg-cpython/src/dirstate/item.rs Wed Sep 29 02:37:24 2021 +0200 +++ b/rust/hg-cpython/src/dirstate/item.rs Wed Sep 29 14:41:19 2021 +0200 @@ -85,6 +85,11 @@ Ok(self.entry(py).get().from_p2()) } + @property + def maybe_clean(&self) -> PyResult<bool> { + Ok(self.entry(py).get().maybe_clean()) + } + def v1_state(&self) -> PyResult<PyBytes> { let (state, _mode, _size, _mtime) = self.entry(py).get().v1_data(); let state_byte: u8 = state.into();