fsmonitor: use new dirstate APIs (
issue6728)
On top of fixing fsmonitor, it moves one more "old API" use to the new one.
This needs very verbose code to save a few function calls that are very
expensive in Python.
--- a/hgext/fsmonitor/__init__.py Wed Aug 31 06:37:42 2022 +0200
+++ b/hgext/fsmonitor/__init__.py Tue Aug 30 17:05:19 2022 +0200
@@ -117,6 +117,7 @@
from mercurial.i18n import _
from mercurial.node import hex
+
from mercurial.pycompat import open
from mercurial import (
context,
@@ -131,6 +132,9 @@
scmutil,
util,
)
+
+# no-check-code because we're accessing private information only public in pure
+from mercurial.pure import parsers
from mercurial import match as matchmod
from mercurial.utils import (
hashutil,
@@ -332,10 +336,22 @@
# for better performance, directly access the inner dirstate map if the
# standard dirstate implementation is in use.
dmap = dmap._map
+
+ has_mtime = parsers.DIRSTATE_V2_HAS_MTIME
+ mtime_is_ambiguous = parsers.DIRSTATE_V2_MTIME_SECOND_AMBIGUOUS
+ mask = has_mtime | mtime_is_ambiguous
+
+ # All entries that may not be clean
nonnormalset = {
f
for f, e in self._map.items()
- if e._v1_state() != b"n" or e._v1_mtime() == -1
+ if not e.maybe_clean
+ # same as "not has_time or has_ambiguous_time", but factored to only
+ # need a single access to flags for performance.
+ # `mask` removes all irrelevant bits, then we flip the `mtime` bit so
+ # its `true` value is NOT having a mtime, then check if either bit
+ # is set.
+ or bool((e.v2_data()[0] & mask) ^ has_mtime)
}
copymap = self._map.copymap
--- a/tests/test-check-code.t Wed Aug 31 06:37:42 2022 +0200
+++ b/tests/test-check-code.t Tue Aug 30 17:05:19 2022 +0200
@@ -30,6 +30,7 @@
Skipping contrib/packaging/hgpackaging/pyoxidizer.py it has no-che?k-code (glob)
Skipping contrib/packaging/hgpackaging/util.py it has no-che?k-code (glob)
Skipping contrib/packaging/hgpackaging/wix.py it has no-che?k-code (glob)
+ Skipping hgext/fsmonitor/__init__.py it has no-che?k-code (glob)
Skipping i18n/polib.py it has no-che?k-code (glob)
Skipping mercurial/statprof.py it has no-che?k-code (glob)
Skipping tests/testlib/badserverext.py it has no-che?k-code (glob)