D10958: dirstate-entry: `merged_removed` and `from_p2_removed` properties

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Sun Jul 4 21:53:19 UTC 2021


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

REVISION SUMMARY
  Lets start to define and use more semantic property. These two might be a bit
  too low level and could be shaved off later, however this seems an improvement
  for now.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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

CHANGE DETAILS

diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -36,6 +36,9 @@
 # a special value used internally for `size` if the file come from the other parent
 FROM_P2 = -2
 
+# a special value used internally for `size` if the file is modified/merged/added
+NONNORMAL = -1
+
 
 class dirstatetuple(object):
     """represente a dirstate entry
@@ -100,10 +103,28 @@
         return self._size == FROM_P2
 
     @property
+    def from_p2_removed(self):
+        """True if the file has been removed, but was merged initially
+
+        This property seems like an attraction leakage and should probably be
+        dealt in this class (or maybe the dirstatemap one directly.
+        """
+        return self._state == b'r' and self._size == FROM_P2
+
+    @property
     def removed(self):
         """True if the file has been removed"""
         return self._state == b'r'
 
+    @property
+    def merged_removed(self):
+        """True if the file has been removed, but was merged initially
+
+        This property seems like an attraction leakage and should probably be
+        dealt in this class (or maybe the dirstatemap one directly.
+        """
+        return self._state == b'r' and self._size == NONNORMAL
+
     def v1_state(self):
         """return a "state" suitable for v1 serialization"""
         return self._state
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -531,16 +531,18 @@
             # being removed, restore that state.
             entry = self._map.get(f)
             if entry is not None:
-                if entry.removed and (entry[2] == NONNORMAL or entry.from_p2):
+                # XXX this should probably be dealt with a a lower level
+                # (see `merged_removed` and `from_p2_removed`)
+                if entry.merged_removed or entry.from_p2_removed:
                     source = self._map.copymap.get(f)
-                    if entry[2] == NONNORMAL:
+                    if entry.merged_removed:
                         self.merge(f)
-                    elif entry.from_p2:
+                    elif entry.from_p2_removed:
                         self.otherparent(f)
-                    if source:
+                    if source is not None:
                         self.copy(source, f)
                     return
-                if entry.merged or entry.state == b'n' and entry.from_p2:
+                elif entry.merged or entry.state == b'n' and entry.from_p2:
                     return
         self._addpath(f, b'n', 0, possibly_dirty=True)
         self._map.copymap.pop(f, None)
diff --git a/mercurial/cext/parsers.c b/mercurial/cext/parsers.c
--- a/mercurial/cext/parsers.c
+++ b/mercurial/cext/parsers.c
@@ -30,6 +30,7 @@
 static const char *const versionerrortext = "Python minor version mismatch";
 
 static const int dirstate_v1_from_p2 = -2;
+static const int dirstate_v1_nonnormal = -1;
 
 static PyObject *dict_new_presized(PyObject *self, PyObject *args)
 {
@@ -166,6 +167,15 @@
 	}
 };
 
+static PyObject *dirstatetuple_get_merged_removed(dirstateTupleObject *self)
+{
+	if (self->state == 'r' && self->size == dirstate_v1_nonnormal) {
+		Py_RETURN_TRUE;
+	} else {
+		Py_RETURN_FALSE;
+	}
+};
+
 static PyObject *dirstatetuple_get_from_p2(dirstateTupleObject *self)
 {
 	if (self->size == dirstate_v1_from_p2) {
@@ -175,6 +185,15 @@
 	}
 };
 
+static PyObject *dirstatetuple_get_from_p2_removed(dirstateTupleObject *self)
+{
+	if (self->state == 'r' && self->size == dirstate_v1_from_p2) {
+		Py_RETURN_TRUE;
+	} else {
+		Py_RETURN_FALSE;
+	}
+};
+
 static PyObject *dirstatetuple_get_removed(dirstateTupleObject *self)
 {
 	if (self->state == 'r') {
@@ -186,7 +205,11 @@
 
 static PyGetSetDef dirstatetuple_getset[] = {
     {"state", (getter)dirstatetuple_get_state, NULL, "state", NULL},
+    {"merged_removed", (getter)dirstatetuple_get_merged_removed, NULL,
+     "merged_removed", NULL},
     {"merged", (getter)dirstatetuple_get_merged, NULL, "merged", NULL},
+    {"from_p2_removed", (getter)dirstatetuple_get_from_p2_removed, NULL,
+     "from_p2_removed", NULL},
     {"from_p2", (getter)dirstatetuple_get_from_p2, NULL, "from_p2", NULL},
     {"removed", (getter)dirstatetuple_get_removed, NULL, "removed", NULL},
     {NULL} /* Sentinel */



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


More information about the Mercurial-devel mailing list