D5442: rust-cpython: using the new bindings from Python
gracinet (Georges Racinet)
phabricator at mercurial-scm.org
Sat Dec 15 11:43:20 UTC 2018
gracinet created this revision.
Herald added a reviewer: indygreg.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
The Python callers detect if we have cpython or
direct-ffi bindings and fallback to the Python
implementation if none is present.
This intermediate state allows to compare the
three possibilities.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D5442
AFFECTED FILES
mercurial/revlog.py
CHANGE DETAILS
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -97,6 +97,10 @@
REVIDX_RAWTEXT_CHANGING_FLAGS
parsers = policy.importmod(r'parsers')
+try:
+ from . import rustext
+except ImportError:
+ rustext = None
# Aliased for performance.
_zlibdecompress = zlib.decompress
@@ -779,12 +783,28 @@
for r in revs:
checkrev(r)
# and we're sure ancestors aren't filtered as well
- if util.safehasattr(parsers, 'rustlazyancestors'):
- return ancestor.rustlazyancestors(
- self.index, revs,
- stoprev=stoprev, inclusive=inclusive)
- return ancestor.lazyancestors(self._uncheckedparentrevs, revs,
- stoprev=stoprev, inclusive=inclusive)
+
+ # rustext can be an unloaded module (see hgdemandimport)
+ # so we need to trigger an actual import to check for its presence,
+ # which is done by looking up any attribute.
+ # If in the future we reach the point where the ancestor module
+ # can be imported by policy, we will be able to get rid of this
+ global rustext
+ if rustext is not None:
+ try:
+ rustext.__name__
+ except ImportError:
+ rustext = None
+ if rustext is not None:
+ lazyancestors = rustext.ancestor.lazyancestors
+ arg = self.index
+ elif util.safehasattr(parsers, 'rustlazyancestors'):
+ lazyancestors = ancestor.rustlazyancestors
+ arg = self.index
+ else:
+ lazyancestors = ancestor.lazyancestors
+ arg = self._uncheckedparentrevs
+ return lazyancestors(arg, revs, stoprev=stoprev, inclusive=inclusive)
def descendants(self, revs):
return dagop.descendantrevs(revs, self.revs, self.parentrevs)
To: gracinet, indygreg, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list