##// END OF EJS Templates
extensions: load and configure extensions in well-defined phases...
Martin Geisler -
r9410:1c83938b default
parent child Browse files
Show More
@@ -349,19 +349,20 b' def _dispatch(ui, args):'
349 lui = ui.copy()
349 lui = ui.copy()
350 lui.readconfig(os.path.join(path, ".hg", "hgrc"))
350 lui.readconfig(os.path.join(path, ".hg", "hgrc"))
351
351
352 # Configure extensions in phases: uisetup, extsetup, cmdtable, and
353 # reposetup. Programs like TortoiseHg will call _dispatch several
354 # times so we keep track of configured extensions in _loaded.
352 extensions.loadall(lui)
355 extensions.loadall(lui)
353 for name, module in extensions.extensions():
356 exts = [ext for ext in extensions.extensions() if ext[0] not in _loaded]
354 if name in _loaded:
355 continue
356
357
357 # setup extensions
358 # (uisetup is handled in extensions.loadall)
358 # TODO this should be generalized to scheme, where extensions can
359
359 # redepend on other extensions. then we should toposort them, and
360 for name, module in exts:
360 # do initialization in correct order
361 extsetup = getattr(module, 'extsetup', None)
361 extsetup = getattr(module, 'extsetup', None)
362 if extsetup:
362 if extsetup:
363 extsetup()
363 extsetup()
364
364
365 for name, module in exts:
365 cmdtable = getattr(module, 'cmdtable', {})
366 cmdtable = getattr(module, 'cmdtable', {})
366 overrides = [cmd for cmd in cmdtable if cmd in commands.table]
367 overrides = [cmd for cmd in cmdtable if cmd in commands.table]
367 if overrides:
368 if overrides:
@@ -370,6 +371,8 b' def _dispatch(ui, args):'
370 commands.table.update(cmdtable)
371 commands.table.update(cmdtable)
371 _loaded.add(name)
372 _loaded.add(name)
372
373
374 # (reposetup is handled in hg.repository)
375
373 addaliases(lui, commands.table)
376 addaliases(lui, commands.table)
374
377
375 # check for fallback encoding
378 # check for fallback encoding
@@ -40,6 +40,7 b' def loadpath(path, module_name):'
40 return imp.load_source(module_name, path)
40 return imp.load_source(module_name, path)
41
41
42 def load(ui, name, path):
42 def load(ui, name, path):
43 # unused ui argument kept for backwards compatibility
43 if name.startswith('hgext.') or name.startswith('hgext/'):
44 if name.startswith('hgext.') or name.startswith('hgext/'):
44 shortname = name[6:]
45 shortname = name[6:]
45 else:
46 else:
@@ -66,12 +67,9 b' def load(ui, name, path):'
66 _extensions[shortname] = mod
67 _extensions[shortname] = mod
67 _order.append(shortname)
68 _order.append(shortname)
68
69
69 uisetup = getattr(mod, 'uisetup', None)
70 if uisetup:
71 uisetup(ui)
72
73 def loadall(ui):
70 def loadall(ui):
74 result = ui.configitems("extensions")
71 result = ui.configitems("extensions")
72 newindex = len(_order)
75 for (name, path) in result:
73 for (name, path) in result:
76 if path:
74 if path:
77 if path[0] == '!':
75 if path[0] == '!':
@@ -90,6 +88,11 b' def loadall(ui):'
90 if ui.traceback():
88 if ui.traceback():
91 return 1
89 return 1
92
90
91 for name in _order[newindex:]:
92 uisetup = getattr(_extensions[name], 'uisetup', None)
93 if uisetup:
94 uisetup(ui)
95
93 def wrapcommand(table, command, wrapper):
96 def wrapcommand(table, command, wrapper):
94 aliases, entry = cmdutil.findcmd(command, table)
97 aliases, entry = cmdutil.findcmd(command, table)
95 for alias, e in table.iteritems():
98 for alias, e in table.iteritems():
@@ -55,6 +55,29 b' cd a'
55 hg foo
55 hg foo
56 echo 'barfoo = !' >> $HGRCPATH
56 echo 'barfoo = !' >> $HGRCPATH
57
57
58 # check that extensions are loaded in phases
59 cat > foo.py <<EOF
60 import os
61 name = os.path.basename(__file__).rsplit('.', 1)[0]
62 print "1) %s imported" % name
63 def uisetup(ui):
64 print "2) %s uisetup" % name
65 def extsetup():
66 print "3) %s extsetup" % name
67 def reposetup(ui, repo):
68 print "4) %s reposetup" % name
69 EOF
70
71 cp foo.py bar.py
72 echo 'foo = foo.py' >> $HGRCPATH
73 echo 'bar = bar.py' >> $HGRCPATH
74
75 # command with no output, we just want to see the extensions loaded
76 hg paths
77
78 echo 'foo = !' >> $HGRCPATH
79 echo 'bar = !' >> $HGRCPATH
80
58 cd ..
81 cd ..
59 cat > empty.py <<EOF
82 cat > empty.py <<EOF
60 '''empty cmdtable
83 '''empty cmdtable
@@ -16,6 +16,14 b' uisetup called'
16 reposetup called for a
16 reposetup called for a
17 ui == repo.ui
17 ui == repo.ui
18 Foo
18 Foo
19 1) foo imported
20 1) bar imported
21 2) foo uisetup
22 2) bar uisetup
23 3) foo extsetup
24 3) bar extsetup
25 4) foo reposetup
26 4) bar reposetup
19 empty extension - empty cmdtable
27 empty extension - empty cmdtable
20
28
21 no commands defined
29 no commands defined
General Comments 0
You need to be logged in to leave comments. Login now