##// END OF EJS Templates
namespaces: let namespaces override singlenode() definition...
namespaces: let namespaces override singlenode() definition Some namespaces have multiple nodes per name (meaning that their namemap() returns multiple nodes). One such namespace is the "topics" namespace (from the evolve repo). We also have our own internal namespace at Google (for review units) that has multiple nodes per name. These namespaces may not want to use the default "pick highest revnum" resolution that we currently use when resolving a name to a single node. As an example, they may decide that `hg co <name>` should check out a commit that's last in some sense even if an earlier commit had just been amended and thus had a higher revnum [1]. This patch gives the namespace the option to continue to return multiple nodes and to override how the best node is picked. Allowing namespaces to override that may also be useful as an optimization (it may be cheaper for the namespace to find just that node). I have been arguing (in D3715) for using all the nodes returned from namemap() when resolving the symbol to a revset, so e.g. `hg log -r stable` would resolve to *all* nodes on stable, not just the one with the highest revnum (except that I don't actually think we should change it for the branch namespace because of BC). Most people seem opposed to that. If we decide not to do it, I think we can deprecate the namemap() function in favor of the new singlenode() (I find it weird to have namespaces, like the branch namespace, where namemap() isn't nodemap()'s inverse). I therefore think this patch makes sense regardless of what we decide on that issue. [1] Actually, even the branch namespace would have wanted to override singlenode() if it had supported multiple nodes. That's because closes branch heads are mostly ignored, so "hg co default" will not check out the highest-revnum node if that's a closed head. Differential Revision: https://phab.mercurial-scm.org/D3852

File last commit:

r37862:670eb4fa default
r38505:4c068365 @58 default
Show More
__init__.py
78 lines | 2.4 KiB | text/x-python | PythonLexer
Siddharth Agarwal
demandimport: move to separate package...
r32420 # hgdemandimport - global demand-loading of modules for Mercurial
#
# Copyright 2017 Facebook Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
'''demandimport - automatic demand-loading of modules'''
# This is in a separate package from mercurial because in Python 3,
# demand loading is per-package. Keeping demandimport in the mercurial package
# would disable demand loading for any modules in mercurial.
from __future__ import absolute_import
Jun Wu
demandimport: move HGDEMANDIMPORT test to __init__.py...
r33861 import os
Siddharth Agarwal
demandimport: move ignore list to __init__.py...
r32422 import sys
Siddharth Agarwal
demandimport: add python 3 implementation...
r32423 if sys.version_info[0] >= 3:
from . import demandimportpy3 as demandimport
else:
from . import demandimportpy2 as demandimport
Siddharth Agarwal
demandimport: move to separate package...
r32420
Gregory Szorc
demandimport: make module ignores a set (API)...
r37862 # Full module names which can't be lazy imported.
# Extensions can add to this set.
IGNORES = {
Siddharth Agarwal
demandimport: move ignore list to __init__.py...
r32422 '__future__',
'_hashlib',
# ImportError during pkg_resources/__init__.py:fixup_namespace_package
'_imp',
'_xmlplus',
'fcntl',
'nt', # pathlib2 tests the existence of built-in 'nt' module
'win32com.gen_py',
'win32com.shell', # 'appdirs' tries to import win32com.shell
'_winreg', # 2.7 mimetypes needs immediate ImportError
'pythoncom',
# imported by tarfile, not available under Windows
'pwd',
'grp',
# imported by profile, itself imported by hotshot.stats,
# not available under Windows
'resource',
# this trips up many extension authors
'gtk',
# setuptools' pkg_resources.py expects "from __main__ import x" to
# raise ImportError if x not defined
'__main__',
'_ssl', # conditional imports in the stdlib, issue1964
'_sre', # issue4920
'rfc822',
'mimetools',
'sqlalchemy.events', # has import-time side effects (issue5085)
# setuptools 8 expects this module to explode early when not on windows
'distutils.msvc9compiler',
'__builtin__',
'builtins',
'urwid.command_map', # for pudb
Gregory Szorc
demandimport: make module ignores a set (API)...
r37862 }
Siddharth Agarwal
demandimport: move ignore list to __init__.py...
r32422
_pypy = '__pypy__' in sys.builtin_module_names
if _pypy:
Gregory Szorc
demandimport: make module ignores a set (API)...
r37862 # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5)
IGNORES.add('_ctypes.pointer')
Siddharth Agarwal
demandimport: move ignore list to __init__.py...
r32422
Gregory Szorc
demandimport: make module ignores a set (API)...
r37862 demandimport.init(IGNORES)
Siddharth Agarwal
demandimport: move ignore list to __init__.py...
r32422
Siddharth Agarwal
demandimport: move to separate package...
r32420 # Re-export.
isenabled = demandimport.isenabled
disable = demandimport.disable
deactivated = demandimport.deactivated
Jun Wu
demandimport: move HGDEMANDIMPORT test to __init__.py...
r33861
def enable():
Jun Wu
demandimport: disable if chg is being used...
r33862 # chg pre-imports modules so do not enable demandimport for it
if ('CHGINTERNALMARK' not in os.environ
and os.environ.get('HGDEMANDIMPORT') != 'disable'):
Jun Wu
demandimport: move HGDEMANDIMPORT test to __init__.py...
r33861 demandimport.enable()