Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/extensions.py @ 33064: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 | 80a5d237a4ae |
children | c467d13334ee |
comparison
equal
deleted
inserted
replaced
33063:15a79ac823e8 | 33064:45b0e9d05ee9 |
---|---|
241 | 241 |
242 # loadall() is called multiple times and lingering _aftercallbacks | 242 # loadall() is called multiple times and lingering _aftercallbacks |
243 # entries could result in double execution. See issue4646. | 243 # entries could result in double execution. See issue4646. |
244 _aftercallbacks.clear() | 244 _aftercallbacks.clear() |
245 | 245 |
246 # delay importing avoids cyclic dependency (especially commands) | |
247 from . import ( | |
248 color, | |
249 commands, | |
250 fileset, | |
251 revset, | |
252 templatefilters, | |
253 templatekw, | |
254 templater, | |
255 ) | |
256 | |
257 # list of (objname, loadermod, loadername) tuple: | |
258 # - objname is the name of an object in extension module, | |
259 # from which extra information is loaded | |
260 # - loadermod is the module where loader is placed | |
261 # - loadername is the name of the function, | |
262 # which takes (ui, extensionname, extraobj) arguments | |
263 extraloaders = [ | |
264 ('cmdtable', commands, 'loadcmdtable'), | |
265 ('colortable', color, 'loadcolortable'), | |
266 ('filesetpredicate', fileset, 'loadpredicate'), | |
267 ('revsetpredicate', revset, 'loadpredicate'), | |
268 ('templatefilter', templatefilters, 'loadfilter'), | |
269 ('templatefunc', templater, 'loadfunction'), | |
270 ('templatekeyword', templatekw, 'loadkeyword'), | |
271 ] | |
272 | |
273 for name in _order[newindex:]: | |
274 module = _extensions[name] | |
275 if not module: | |
276 continue # loading this module failed | |
277 | |
278 for objname, loadermod, loadername in extraloaders: | |
279 extraobj = getattr(module, objname, None) | |
280 if extraobj is not None: | |
281 getattr(loadermod, loadername)(ui, name, extraobj) | |
282 | |
246 def afterloaded(extension, callback): | 283 def afterloaded(extension, callback): |
247 '''Run the specified function after a named extension is loaded. | 284 '''Run the specified function after a named extension is loaded. |
248 | 285 |
249 If the named extension is already loaded, the callback will be called | 286 If the named extension is already loaded, the callback will be called |
250 immediately. | 287 immediately. |