[PATCH 3 of 9] chgserve: pre-import extensions
Yuya Nishihara
yuya at tcha.org
Sat Nov 19 04:02:43 EST 2016
On Sun, 13 Nov 2016 21:55:47 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1479070477 0
> # Sun Nov 13 20:54:37 2016 +0000
> # Node ID 70611a6b45d51ba4bf560c2cfdb8d94e08a3dc8f
> # Parent ca7a76135db4a9b8a90665c8a42013debbdae3b7
> chgserve: pre-import extensions
>
> This patch makes chgserve pre-import extensions. It assumes that
> pre-importing extensions does not have side effects.
>
> diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
> --- a/mercurial/chgserver.py
> +++ b/mercurial/chgserver.py
> @@ -73,4 +73,26 @@ testedwith = 'ships-with-hg-core'
> _log = commandserver.log
>
> +_preimported = {} # {(name, path): mod}
> +
> +def _preimportextensions(ui):
> + for name, path in ui.configitems('extensions'):
> + # do not pre-import disabled extensions
> + if path.startswith('!'):
> + continue
> + try:
> + mod = extensions._importext(name, path)
> + except ImportError:
> + pass
> + else:
> + _preimported[(name, path)] = mod
> + ui.debug('chg: pre-imported %s\n' % name)
> +
> +def _importext(orig, name, path=None, reportfunc=None):
> + mod = _preimported.get((name, path))
> + if mod:
> + return mod
> + else:
> + return orig(name, path, reportfunc)
> +
> def _hashlist(items):
> """return sha1 hexdigest for a list"""
> @@ -646,4 +668,5 @@ def uisetup(ui):
> def _runchgservice(args):
> ui = uimod.ui()
> + _preimportextensions(ui)
>
> addresses = dispatch._earlygetopt(['--address'], args)
> @@ -662,3 +685,4 @@ def _runchgservice(args):
>
> def run():
> + extensions.wrapfunction(extensions, '_importext', _importext)
> sys.exit(_runchgservice(sys.argv[1:]))
Can we do this formally (i.e. without function wrapping and private
function calls)? chgserver.py isn't an extension now.
More information about the Mercurial-devel
mailing list