changeset 47513:10e740292dff

dirstate-entry: add a `merged` property Lets start to define and use more semantic property. Differential Revision: https://phab.mercurial-scm.org/D10955
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 03 Jul 2021 04:07:21 +0200
parents 769037a279ec
children 559aee84b889
files mercurial/cext/parsers.c mercurial/dirstate.py mercurial/dirstatemap.py mercurial/pure/parsers.py
diffstat 4 files changed, 25 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/parsers.c	Sun Jul 04 03:29:20 2021 +0200
+++ b/mercurial/cext/parsers.c	Sat Jul 03 04:07:21 2021 +0200
@@ -155,8 +155,18 @@
 	return PyBytes_FromStringAndSize(&self->state, 1);
 };
 
+static PyObject *dirstatetuple_get_merged(dirstateTupleObject *self)
+{
+	if (self->state == 'm') {
+		Py_RETURN_TRUE;
+	} else {
+		Py_RETURN_FALSE;
+	}
+};
+
 static PyGetSetDef dirstatetuple_getset[] = {
     {"state", (getter)dirstatetuple_get_state, NULL, "state", NULL},
+    {"merged", (getter)dirstatetuple_get_merged, NULL, "merged", NULL},
     {NULL} /* Sentinel */
 };
 
--- a/mercurial/dirstate.py	Sun Jul 04 03:29:20 2021 +0200
+++ b/mercurial/dirstate.py	Sat Jul 03 04:07:21 2021 +0200
@@ -355,7 +355,7 @@
     def setparents(self, p1, p2=None):
         """Set dirstate parents to p1 and p2.
 
-        When moving from two parents to one, 'm' merged entries a
+        When moving from two parents to one, "merged" entries a
         adjusted to normal and previous copy records discarded and
         returned by the call.
 
@@ -386,8 +386,8 @@
                 if s is None:
                     continue
 
-                # Discard 'm' markers when moving away from a merge state
-                if s.state == b'm':
+                # Discard "merged" markers when moving away from a merge state
+                if s.merged:
                     source = self._map.copymap.get(f)
                     if source:
                         copies[f] = source
@@ -527,7 +527,7 @@
         '''Mark a file normal, but possibly dirty.'''
         if self.in_merge:
             # if there is a merge going on and the file was either
-            # in state 'm' (-1) or coming from other parent (-2) before
+            # "merged" or coming from other parent (-2) before
             # being removed, restore that state.
             entry = self._map.get(f)
             if entry is not None:
@@ -540,11 +540,7 @@
                     if source:
                         self.copy(source, f)
                     return
-                if (
-                    entry.state == b'm'
-                    or entry.state == b'n'
-                    and entry[2] == FROM_P2
-                ):
+                if entry.merged or entry.state == b'n' and entry[2] == FROM_P2:
                     return
         self._addpath(f, b'n', 0, possibly_dirty=True)
         self._map.copymap.pop(f, None)
@@ -1362,7 +1358,7 @@
                     ladd(fn)
                 elif listclean:
                     cadd(fn)
-            elif state == b'm':
+            elif t.merged:
                 madd(fn)
             elif state == b'a':
                 aadd(fn)
--- a/mercurial/dirstatemap.py	Sun Jul 04 03:29:20 2021 +0200
+++ b/mercurial/dirstatemap.py	Sat Jul 03 04:07:21 2021 +0200
@@ -171,7 +171,7 @@
             # would be nice.
             if entry is not None:
                 # backup the previous state
-                if entry[0] == b'm':  # merge
+                if entry.merged:  # merge
                     size = NONNORMAL
                 elif entry[0] == b'n' and entry[2] == FROM_P2:  # other parent
                     size = FROM_P2
--- a/mercurial/pure/parsers.py	Sun Jul 04 03:29:20 2021 +0200
+++ b/mercurial/pure/parsers.py	Sat Jul 03 04:07:21 2021 +0200
@@ -79,6 +79,14 @@
         """
         return self._state
 
+    @property
+    def merged(self):
+        """True if the file has been merged
+
+        Should only be set if a merge is in progress in the dirstate
+        """
+        return self._state == b'm'
+
     def v1_state(self):
         """return a "state" suitable for v1 serialization"""
         return self._state