changeset 48143:21542d4cb568

dirstate-item: introduce a `p1_tracked` property It is useful to simplify various conditional that use `any_tracked and not added`. Differential Revision: https://phab.mercurial-scm.org/D11586
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 01 Oct 2021 04:07:21 +0200
parents fb3b41d583c2
children 6f54afb094bd
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, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/parsers.c	Fri Oct 01 04:04:09 2021 +0200
+++ b/mercurial/cext/parsers.c	Fri Oct 01 04:07:21 2021 +0200
@@ -567,6 +567,14 @@
 		Py_RETURN_FALSE;
 	}
 };
+static PyObject *dirstate_item_get_p1_tracked(dirstateItemObject *self)
+{
+	if (self->flags & dirstate_flag_p1_tracked) {
+		Py_RETURN_TRUE;
+	} else {
+		Py_RETURN_FALSE;
+	}
+};
 
 static PyObject *dirstate_item_get_added(dirstateItemObject *self)
 {
@@ -642,6 +650,8 @@
     {"mtime", (getter)dirstate_item_get_mtime, NULL, "mtime", NULL},
     {"state", (getter)dirstate_item_get_state, NULL, "state", NULL},
     {"tracked", (getter)dirstate_item_get_tracked, NULL, "tracked", NULL},
+    {"p1_tracked", (getter)dirstate_item_get_p1_tracked, NULL, "p1_tracked",
+     NULL},
     {"added", (getter)dirstate_item_get_added, NULL, "added", NULL},
     {"p2_info", (getter)dirstate_item_get_p2_info, NULL, "p2_info", NULL},
     {"merged", (getter)dirstate_item_get_merged, NULL, "merged", NULL},
--- a/mercurial/pure/parsers.py	Fri Oct 01 04:04:09 2021 +0200
+++ b/mercurial/pure/parsers.py	Fri Oct 01 04:07:21 2021 +0200
@@ -301,6 +301,11 @@
         return True
 
     @property
+    def p1_tracked(self):
+        """True if the file is tracked in the first parent manifest"""
+        return self._p1_tracked
+
+    @property
     def p2_info(self):
         """True if the file needed to merge or apply any input from p2
 
--- a/rust/hg-core/src/dirstate/entry.rs	Fri Oct 01 04:04:09 2021 +0200
+++ b/rust/hg-core/src/dirstate/entry.rs	Fri Oct 01 04:07:21 2021 +0200
@@ -153,6 +153,10 @@
         self.flags.contains(Flags::WDIR_TRACKED)
     }
 
+    pub fn p1_tracked(&self) -> bool {
+        self.flags.contains(Flags::P1_TRACKED)
+    }
+
     fn in_either_parent(&self) -> bool {
         self.flags.intersects(Flags::P1_TRACKED | Flags::P2_INFO)
     }
--- a/rust/hg-cpython/src/dirstate/item.rs	Fri Oct 01 04:04:09 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/item.rs	Fri Oct 01 04:07:21 2021 +0200
@@ -67,6 +67,11 @@
     }
 
     @property
+    def p1_tracked(&self) -> PyResult<bool> {
+        Ok(self.entry(py).get().p1_tracked())
+    }
+
+    @property
     def added(&self) -> PyResult<bool> {
         Ok(self.entry(py).get().added())
     }