# HG changeset patch # User Georges Racinet <georges.raci...@octobus.net> # Date 1558603373 -7200 # Thu May 23 11:22:53 2019 +0200 # Node ID 1ea01a0c2d35420f3b9f1a9e98e7bb41de29956a # Parent 36b4c4869531b3de0b101c941b77b94da85890b7 # EXP-Topic rust-modulepolicy rust: using policy.importrust from Python callers
This commit converts all current Python callers of mercurial.rustext to the new policy.importrust system. After this point, going through policy.importrust or policy.importmod (in some more distant future) is mandatory for callers of Rust code outside of Python tests. We felt it to be appropriate to keep Rust-specific tests run inconditionally if the Rust extensions are present. diff -r 36b4c4869531 -r 1ea01a0c2d35 mercurial/dirstate.py --- a/mercurial/dirstate.py Thu May 23 11:19:14 2019 +0200 +++ b/mercurial/dirstate.py Thu May 23 11:22:53 2019 +0200 @@ -27,13 +27,8 @@ util, ) -try: - from . import rustext - rustext.__name__ # force actual import (see hgdemandimport) -except ImportError: - rustext = None - parsers = policy.importmod(r'parsers') +rustmod = policy.importrust(r'dirstate') propertycache = util.propertycache filecache = scmutil.filecache @@ -1468,8 +1463,8 @@ # parsing the dirstate. # # (we cannot decorate the function directly since it is in a C module) - if rustext is not None: - parse_dirstate = rustext.dirstate.parse_dirstate + if rustmod is not None: + parse_dirstate = rustmod.parse_dirstate else: parse_dirstate = parsers.parse_dirstate @@ -1484,8 +1479,8 @@ self.get = self._map.get def write(self, st, now): - if rustext is not None: - pack_dirstate = rustext.dirstate.pack_dirstate + if rustmod is not None: + pack_dirstate = rustmod.pack_dirstate else: pack_dirstate = parsers.pack_dirstate diff -r 36b4c4869531 -r 1ea01a0c2d35 mercurial/match.py --- a/mercurial/match.py Thu May 23 11:19:14 2019 +0200 +++ b/mercurial/match.py Thu May 23 11:22:53 2019 +0200 @@ -17,6 +17,7 @@ encoding, error, pathutil, + policy, pycompat, util, ) @@ -24,11 +25,7 @@ stringutil, ) -try: - from . import rustext - rustext.__name__ # force actual import (see hgdemandimport) -except ImportError: - rustext = None +rustmod = policy.importrust('filepatterns') allpatternkinds = ('re', 'glob', 'path', 'relglob', 'relpath', 'relre', 'rootglob', @@ -1197,14 +1194,14 @@ regular expression. globsuffix is appended to the regexp of globs.''' - if rustext is not None: + if rustmod is not None: try: - return rustext.filepatterns.build_single_regex( + return rustmod.build_single_regex( kind, pat, globsuffix ) - except rustext.filepatterns.PatternError: + except rustmod.PatternError: raise error.ProgrammingError( 'not a regex pattern: %s:%s' % (kind, pat) ) @@ -1456,8 +1453,8 @@ This is useful to debug ignore patterns. ''' - if rustext is not None: - result, warnings = rustext.filepatterns.read_pattern_file( + if rustmod is not None: + result, warnings = rustmod.read_pattern_file( filepath, bool(warn), sourceinfo, diff -r 36b4c4869531 -r 1ea01a0c2d35 mercurial/revlog.py --- a/mercurial/revlog.py Thu May 23 11:19:14 2019 +0200 +++ b/mercurial/revlog.py Thu May 23 11:22:53 2019 +0200 @@ -97,11 +97,8 @@ REVIDX_RAWTEXT_CHANGING_FLAGS parsers = policy.importmod(r'parsers') -try: - from . import rustext - rustext.__name__ # force actual import (see hgdemandimport) -except ImportError: - rustext = None +rustancestor = policy.importrust(r'ancestor') +rustdagop = policy.importrust(r'dagop') # Aliased for performance. _zlibdecompress = zlib.decompress @@ -825,8 +822,8 @@ checkrev(r) # and we're sure ancestors aren't filtered as well - if rustext is not None: - lazyancestors = rustext.ancestor.LazyAncestors + if rustancestor is not None: + lazyancestors = rustancestor.LazyAncestors arg = self.index elif util.safehasattr(parsers, 'rustlazyancestors'): lazyancestors = ancestor.rustlazyancestors @@ -915,8 +912,8 @@ if common is None: common = [nullrev] - if rustext is not None: - return rustext.ancestor.MissingAncestors(self.index, common) + if rustancestor is not None: + return rustancestor.MissingAncestors(self.index, common) return ancestor.incrementalmissingancestors(self.parentrevs, common) def findmissingrevs(self, common=None, heads=None): @@ -1130,8 +1127,8 @@ return self.index.headrevs() except AttributeError: return self._headrevs() - if rustext is not None: - return rustext.dagop.headrevs(self.index, revs) + if rustdagop is not None: + return rustdagop.headrevs(self.index, revs) return dagop.headrevs(revs, self._uncheckedparentrevs) def computephases(self, roots): _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel