marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This property is True is the file is tracked anywhere, either the working 
copy,
  or any of the parent.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11524

AFFECTED FILES
  mercurial/cext/parsers.c
  mercurial/pure/parsers.py
  rust/hg-core/src/dirstate/entry.rs
  rust/hg-cpython/src/dirstate/item.rs

CHANGE DETAILS

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 @@
         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();
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 @@
         }
     }
 
+    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/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -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)
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_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 */
 };



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to