Mercurial > hg
comparison mercurial/dispatch.py @ 33052:45b0e9d05ee9
extensions: register functions always at loading extension (issue5601)
Before this patch, functions defined in extensions are registered via
extra loaders only in _dispatch(). Therefore, loading extensions in
other code paths like below omits registration of functions.
- WSGI service
- operation across repositories (e.g. subrepo)
- test-duplicateoptions.py, using extensions.loadall() directly
To register functions always at loading new extension, this patch
moves implementation for extra loading from dispatch._dispatch() to
extensions.loadall().
AFAIK, only commands module causes cyclic dependency between
extensions module, but this patch imports all related modules just
before extra loading in loadall(), in order to centralize them.
This patch makes extensions.py depend on many other modules, even
though extensions.py itself doesn't. It should be avoided if possible,
but I don't have any better idea. Some other places like below aren't
reasonable for extra loading, IMHO.
- specific function in newly added module:
existing callers of extensions.loadall() should invoke it, too
- hg.repository() or so:
no-repo commands aren't covered by this.
BTW, this patch removes _loaded.add(name) on relocation, because
dispatch._loaded is used only for extraloaders (for similar reason,
"exts" variable is removed, too).
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sat, 24 Jun 2017 02:39:20 +0900 |
parents | eede022fc142 |
children | ef46d432e2e4 |
comparison
equal
deleted
inserted
replaced
33051:15a79ac823e8 | 33052:45b0e9d05ee9 |
---|---|
28 demandimport, | 28 demandimport, |
29 encoding, | 29 encoding, |
30 error, | 30 error, |
31 extensions, | 31 extensions, |
32 fancyopts, | 32 fancyopts, |
33 fileset, | |
34 help, | 33 help, |
35 hg, | 34 hg, |
36 hook, | 35 hook, |
37 profiling, | 36 profiling, |
38 pycompat, | 37 pycompat, |
39 revset, | |
40 scmutil, | 38 scmutil, |
41 templatefilters, | |
42 templatekw, | |
43 templater, | |
44 ui as uimod, | 39 ui as uimod, |
45 util, | 40 util, |
46 ) | 41 ) |
47 | 42 |
48 class request(object): | 43 class request(object): |
725 return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, | 720 return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, |
726 [], {}) | 721 [], {}) |
727 | 722 |
728 _loaded = set() | 723 _loaded = set() |
729 | 724 |
730 # list of (objname, loadermod, loadername) tuple: | |
731 # - objname is the name of an object in extension module, from which | |
732 # extra information is loaded | |
733 # - loadermod is the module where loader is placed | |
734 # - loadername is the name of the function, which takes (ui, extensionname, | |
735 # extraobj) arguments | |
736 extraloaders = [ | |
737 ('cmdtable', commands, 'loadcmdtable'), | |
738 ('colortable', color, 'loadcolortable'), | |
739 ('filesetpredicate', fileset, 'loadpredicate'), | |
740 ('revsetpredicate', revset, 'loadpredicate'), | |
741 ('templatefilter', templatefilters, 'loadfilter'), | |
742 ('templatefunc', templater, 'loadfunction'), | |
743 ('templatekeyword', templatekw, 'loadkeyword'), | |
744 ] | |
745 | |
746 def _dispatch(req): | 725 def _dispatch(req): |
747 args = req.args | 726 args = req.args |
748 ui = req.ui | 727 ui = req.ui |
749 | 728 |
750 # check for cwd | 729 # check for cwd |
768 with profiling.profile(lui, enabled=profile) as profiler: | 747 with profiling.profile(lui, enabled=profile) as profiler: |
769 # Configure extensions in phases: uisetup, extsetup, cmdtable, and | 748 # Configure extensions in phases: uisetup, extsetup, cmdtable, and |
770 # reposetup. Programs like TortoiseHg will call _dispatch several | 749 # reposetup. Programs like TortoiseHg will call _dispatch several |
771 # times so we keep track of configured extensions in _loaded. | 750 # times so we keep track of configured extensions in _loaded. |
772 extensions.loadall(lui) | 751 extensions.loadall(lui) |
773 exts = [ext for ext in extensions.extensions() if ext[0] not in _loaded] | |
774 # Propagate any changes to lui.__class__ by extensions | 752 # Propagate any changes to lui.__class__ by extensions |
775 ui.__class__ = lui.__class__ | 753 ui.__class__ = lui.__class__ |
776 | 754 |
777 # (uisetup and extsetup are handled in extensions.loadall) | 755 # (uisetup and extsetup are handled in extensions.loadall) |
778 | |
779 for name, module in exts: | |
780 for objname, loadermod, loadername in extraloaders: | |
781 extraobj = getattr(module, objname, None) | |
782 if extraobj is not None: | |
783 getattr(loadermod, loadername)(ui, name, extraobj) | |
784 _loaded.add(name) | |
785 | 756 |
786 # (reposetup is handled in hg.repository) | 757 # (reposetup is handled in hg.repository) |
787 | 758 |
788 addaliases(lui, commands.table) | 759 addaliases(lui, commands.table) |
789 | 760 |