changeset 47685:265cdfaad372

dirstate-item: introduce a `dm_nonnormal` property See inline documentation for details. Differential Revision: https://phab.mercurial-scm.org/D11123
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 14 Jul 2021 21:59:18 +0200
parents 852262e2e7d9
children e43128ee436f
files mercurial/cext/parsers.c mercurial/dirstatemap.py mercurial/pure/parsers.py
diffstat 3 files changed, 22 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/parsers.c	Fri Jul 16 16:19:31 2021 +0200
+++ b/mercurial/cext/parsers.c	Wed Jul 14 21:59:18 2021 +0200
@@ -142,6 +142,15 @@
 	return PyInt_FromLong(self->mtime);
 };
 
+static PyObject *dm_nonnormal(dirstateItemObject *self)
+{
+	if (self->state != 'n' || self->mtime == ambiguous_time) {
+		Py_RETURN_TRUE;
+	} else {
+		Py_RETURN_FALSE;
+	}
+};
+
 static PyObject *dirstate_item_need_delay(dirstateItemObject *self,
                                           PyObject *value)
 {
@@ -221,6 +230,8 @@
      "build a new DirstateItem object from V1 data"},
     {"set_possibly_dirty", (PyCFunction)dirstate_item_set_possibly_dirty,
      METH_NOARGS, "mark a file as \"possibly dirty\""},
+    {"dm_nonnormal", (PyCFunction)dm_nonnormal, METH_NOARGS,
+     "True is the entry is non-normal in the dirstatemap sense"},
     {NULL} /* Sentinel */
 };
 
--- a/mercurial/dirstatemap.py	Fri Jul 16 16:19:31 2021 +0200
+++ b/mercurial/dirstatemap.py	Wed Jul 14 21:59:18 2021 +0200
@@ -196,8 +196,8 @@
             self._dirs.addpath(f)
         if old_entry is None and "_alldirs" in self.__dict__:
             self._alldirs.addpath(f)
-        self._map[f] = DirstateItem(state, mode, size, mtime)
-        if state != b'n' or mtime == AMBIGUOUS_TIME:
+        e = self._map[f] = DirstateItem(state, mode, size, mtime)
+        if e.dm_nonnormal:
             self.nonnormalset.add(f)
         if size == FROM_P2:
             self.otherparentset.add(f)
@@ -274,7 +274,7 @@
             nonnorm = set()
             otherparent = set()
             for fname, e in pycompat.iteritems(self._map):
-                if e.state != b'n' or e.mtime == AMBIGUOUS_TIME:
+                if e.dm_nonnormal:
                     nonnorm.add(fname)
                 if e.from_p2:
                     otherparent.add(fname)
--- a/mercurial/pure/parsers.py	Fri Jul 16 16:19:31 2021 +0200
+++ b/mercurial/pure/parsers.py	Wed Jul 14 21:59:18 2021 +0200
@@ -187,6 +187,14 @@
         """
         return self._state == b'r' and self._size == NONNORMAL
 
+    @property
+    def dm_nonnormal(self):
+        """True is the entry is non-normal in the dirstatemap sense
+
+        There is no reason for any code, but the dirstatemap one to use this.
+        """
+        return self.state != b'n' or self.mtime == AMBIGUOUS_TIME
+
     def v1_state(self):
         """return a "state" suitable for v1 serialization"""
         return self._state