[PATCH 3 of 3 RFC] chgserve: preimport enabled extensions
Yuya Nishihara
yuya at tcha.org
Mon Oct 3 08:59:02 EDT 2016
On Mon, 3 Oct 2016 07:11:20 +0100, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1475463449 -3600
> # Mon Oct 03 03:57:29 2016 +0100
> # Node ID 6f38a7d259add12c44040535681c4b3ceef0a791
> # Parent 7d106c3386e17746c9b49ab9c788535634b3e8f6
> # Available At https://bitbucket.org/quark-zju/hg-draft
> # hg pull https://bitbucket.org/quark-zju/hg-draft -r 6f38a7d259ad
> chgserve: preimport enabled extensions
>
> This patch pre-imports enabled extensions, so performance improvement is
> visible. It's about 0.01 seconds slower than the old chg, which seems to be
> acceptable.
(I haven't read the patch 1 and 2 yet.)
Regarding this, I was thinking about 'extensions.<name>:enabled' syntax so
users (or sysadmins) can define a set of conditionally-enabled extensions
globally.
[extensions]
rebase =
topic = /path/to/topic.py
topic:enabled = False
chg daemon will import all extensions listed in ~/.hgrc. And if :enabled = True
is flagged by repo/.hg/hgrc, ui/reposetup() will be run.
> +def _importext(orig, name, path=None, reportfunc=None):
> + mod = _preimported.get((name, path))
> + if mod:
> + return mod
> + else:
> + return orig(name, path, reportfunc)
> +
> +def _preimportextensions(ui):
> + for name, path in ui.configitems("extensions"):
> + # only enabled extensions are pre-imported - assuming importing an
> + # extension is side-effect free.
> + if path.startswith('!'):
> + continue
> + try:
> + mod = extensions._importext(name, path)
> + except ImportError:
> + pass
> + else:
> + _preimported[(name, path)] = mod
Perhaps path needs to be normalized.
More information about the Mercurial-devel
mailing list