changeset 48087:79bc60ca5946

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
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 29 Sep 2021 14:51:31 +0200
parents 80783e553bd5
children 418611f18fd8
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, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/parsers.c	Wed Sep 29 14:41:19 2021 +0200
+++ b/mercurial/cext/parsers.c	Wed Sep 29 14:51:31 2021 +0200
@@ -635,6 +635,18 @@
 	}
 };
 
+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 @@
     {"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 */
 };
--- a/mercurial/pure/parsers.py	Wed Sep 29 14:41:19 2021 +0200
+++ b/mercurial/pure/parsers.py	Wed Sep 29 14:51:31 2021 +0200
@@ -314,6 +314,11 @@
         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)
--- a/rust/hg-core/src/dirstate/entry.rs	Wed Sep 29 14:41:19 2021 +0200
+++ b/rust/hg-core/src/dirstate/entry.rs	Wed Sep 29 14:51:31 2021 +0200
@@ -205,6 +205,12 @@
         }
     }
 
+    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
--- a/rust/hg-cpython/src/dirstate/item.rs	Wed Sep 29 14:41:19 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/item.rs	Wed Sep 29 14:51:31 2021 +0200
@@ -90,6 +90,11 @@
         Ok(self.entry(py).get().maybe_clean())
     }
 
+    @property
+    def any_tracked(&self) -> PyResult<bool> {
+        Ok(self.entry(py).get().any_tracked())
+    }
+
     def v1_state(&self) -> PyResult<PyBytes> {
         let (state, _mode, _size, _mtime) = self.entry(py).get().v1_data();
         let state_byte: u8 = state.into();