changeset 47526:8bcae9bf9e8d

dirstate-entry: add a `added` property Lets use more semantic property instead of the `state` implementation details. Differential Revision: https://phab.mercurial-scm.org/D10968
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 04 Jul 2021 01:44:43 +0200
parents fe4641cf9b72
children c6b91a9c242a
files mercurial/cext/parsers.c mercurial/dirstate.py mercurial/pure/parsers.py
diffstat 3 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/parsers.c	Sun Jul 04 01:42:10 2021 +0200
+++ b/mercurial/cext/parsers.c	Sun Jul 04 01:44:43 2021 +0200
@@ -158,6 +158,15 @@
 	return PyBytes_FromStringAndSize(&self->state, 1);
 };
 
+static PyObject *dirstatetuple_get_added(dirstateTupleObject *self)
+{
+	if (self->state == 'a') {
+		Py_RETURN_TRUE;
+	} else {
+		Py_RETURN_FALSE;
+	}
+};
+
 static PyObject *dirstatetuple_get_merged(dirstateTupleObject *self)
 {
 	if (self->state == 'm') {
@@ -205,6 +214,7 @@
 
 static PyGetSetDef dirstatetuple_getset[] = {
     {"state", (getter)dirstatetuple_get_state, NULL, "state", NULL},
+    {"added", (getter)dirstatetuple_get_added, NULL, "added", NULL},
     {"merged_removed", (getter)dirstatetuple_get_merged_removed, NULL,
      "merged_removed", NULL},
     {"merged", (getter)dirstatetuple_get_merged, NULL, "merged", NULL},
--- a/mercurial/dirstate.py	Sun Jul 04 01:42:10 2021 +0200
+++ b/mercurial/dirstate.py	Sun Jul 04 01:44:43 2021 +0200
@@ -1346,7 +1346,7 @@
                     cadd(fn)
             elif t.merged:
                 madd(fn)
-            elif state == b'a':
+            elif t.added:
                 aadd(fn)
             elif t.removed:
                 radd(fn)
--- a/mercurial/pure/parsers.py	Sun Jul 04 01:42:10 2021 +0200
+++ b/mercurial/pure/parsers.py	Sun Jul 04 01:44:43 2021 +0200
@@ -87,6 +87,11 @@
         return self._state
 
     @property
+    def added(self):
+        """True if the file has been added"""
+        return self._state == b'a'
+
+    @property
     def merged(self):
         """True if the file has been merged