Patchwork D10968: dirstate-entry: add a `added` property

login
register
mail settings
Submitter phabricator
Date July 4, 2021, 9:55 p.m.
Message ID <differential-rev-PHID-DREV-3xwcnvq6frgrw2whxxi3-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49279/
State Superseded
Headers show

Comments

phabricator - July 4, 2021, 9:55 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Lets use more semantic property instead of the `state` implementation details.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/cext/parsers.c
  mercurial/dirstate.py
  mercurial/pure/parsers.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -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
 
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -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)
diff --git a/mercurial/cext/parsers.c b/mercurial/cext/parsers.c
--- a/mercurial/cext/parsers.c
+++ b/mercurial/cext/parsers.c
@@ -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},