##// END OF EJS Templates
extensions: register functions always at loading extension (issue5601)...
FUJIWARA Katsunori -
r33052:45b0e9d0 default
parent child Browse files
Show More
@@ -30,17 +30,12 b' from . import ('
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 )
@@ -727,22 +722,6 b' def _checkshellalias(lui, ui, args):'
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
@@ -770,19 +749,11 b' def _dispatch(req):'
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
756
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
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)
@@ -243,6 +243,43 b' def loadall(ui, whitelist=None):'
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
@@ -77,15 +77,25 b' Check that extensions are loaded in phas'
77 > print "3) %s extsetup" % name
77 > print "3) %s extsetup" % name
78 > def reposetup(ui, repo):
78 > def reposetup(ui, repo):
79 > print "4) %s reposetup" % name
79 > print "4) %s reposetup" % name
80 >
81 > # custom predicate to check registration of functions at loading
82 > from mercurial import (
83 > registrar,
84 > smartset,
85 > )
86 > revsetpredicate = registrar.revsetpredicate()
87 > @revsetpredicate(name, safe=True) # safe=True for query via hgweb
88 > def custompredicate(repo, subset, x):
89 > return smartset.baseset([r for r in subset if r in {0}])
80 > EOF
90 > EOF
81
91
82 $ cp foo.py bar.py
92 $ cp foo.py bar.py
83 $ echo 'foo = foo.py' >> $HGRCPATH
93 $ echo 'foo = foo.py' >> $HGRCPATH
84 $ echo 'bar = bar.py' >> $HGRCPATH
94 $ echo 'bar = bar.py' >> $HGRCPATH
85
95
86 Command with no output, we just want to see the extensions loaded:
96 Check normal command's load order of extensions and registration of functions
87
97
88 $ hg paths
98 $ hg log -r "foo() and bar()" -q
89 1) foo imported
99 1) foo imported
90 1) bar imported
100 1) bar imported
91 2) foo uisetup
101 2) foo uisetup
@@ -94,8 +104,9 b' Command with no output, we just want to '
94 3) bar extsetup
104 3) bar extsetup
95 4) foo reposetup
105 4) foo reposetup
96 4) bar reposetup
106 4) bar reposetup
107 0:c24b9ac61126
97
108
98 Check hgweb's load order:
109 Check hgweb's load order of extensions and registration of functions
99
110
100 $ cat > hgweb.cgi <<EOF
111 $ cat > hgweb.cgi <<EOF
101 > #!$PYTHON
112 > #!$PYTHON
@@ -118,6 +129,14 b" Check hgweb's load order:"
118 4) foo reposetup
129 4) foo reposetup
119 4) bar reposetup
130 4) bar reposetup
120
131
132 (check that revset predicate foo() and bar() are available)
133
134 $ REQUEST_METHOD='GET' PATH_INFO='/shortlog' SCRIPT_NAME='' \
135 > QUERY_STRING='rev=foo() and bar()' \
136 > SERVER_PORT='80' SERVER_NAME='localhost' python hgweb.cgi \
137 > | grep '<a href="/rev/[0-9a-z]*">'
138 <a href="/rev/c24b9ac61126">add file</a>
139
121 $ echo 'foo = !' >> $HGRCPATH
140 $ echo 'foo = !' >> $HGRCPATH
122 $ echo 'bar = !' >> $HGRCPATH
141 $ echo 'bar = !' >> $HGRCPATH
123
142
General Comments 0
You need to be logged in to leave comments. Login now