From patchwork Mon Jul 19 10:39:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D11123: dirstate-item: introduce a `dm_nonnormal` property From: phabricator X-Patchwork-Id: 49437 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Mon, 19 Jul 2021 10:39:59 +0000 marmoute created this revision. Herald added a reviewer: hg-reviewers. Herald added a subscriber: mercurial-patches. REVISION SUMMARY See inline documentation for details. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D11123 AFFECTED FILES mercurial/cext/parsers.c mercurial/dirstatemap.py mercurial/pure/parsers.py CHANGE DETAILS To: marmoute, #hg-reviewers Cc: mercurial-patches, mercurial-devel diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py --- a/mercurial/pure/parsers.py +++ b/mercurial/pure/parsers.py @@ -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 diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py --- a/mercurial/dirstatemap.py +++ b/mercurial/dirstatemap.py @@ -194,8 +194,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) @@ -272,7 +272,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) diff --git a/mercurial/cext/parsers.c b/mercurial/cext/parsers.c --- a/mercurial/cext/parsers.c +++ b/mercurial/cext/parsers.c @@ -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 */ };