Show More
@@ -349,19 +349,20 b' def _dispatch(ui, args):' | |||
|
349 | 349 | lui = ui.copy() |
|
350 | 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 | 355 | extensions.loadall(lui) |
|
353 | for name, module in extensions.extensions(): | |
|
354 | if name in _loaded: | |
|
355 | continue | |
|
356 | exts = [ext for ext in extensions.extensions() if ext[0] not in _loaded] | |
|
356 | 357 | |
|
357 | # setup extensions | |
|
358 | # TODO this should be generalized to scheme, where extensions can | |
|
359 | # redepend on other extensions. then we should toposort them, and | |
|
360 | # do initialization in correct order | |
|
358 | # (uisetup is handled in extensions.loadall) | |
|
359 | ||
|
360 | for name, module in exts: | |
|
361 | 361 | extsetup = getattr(module, 'extsetup', None) |
|
362 | 362 | if extsetup: |
|
363 | 363 | extsetup() |
|
364 | 364 | |
|
365 | for name, module in exts: | |
|
365 | 366 | cmdtable = getattr(module, 'cmdtable', {}) |
|
366 | 367 | overrides = [cmd for cmd in cmdtable if cmd in commands.table] |
|
367 | 368 | if overrides: |
@@ -370,6 +371,8 b' def _dispatch(ui, args):' | |||
|
370 | 371 | commands.table.update(cmdtable) |
|
371 | 372 | _loaded.add(name) |
|
372 | 373 | |
|
374 | # (reposetup is handled in hg.repository) | |
|
375 | ||
|
373 | 376 | addaliases(lui, commands.table) |
|
374 | 377 | |
|
375 | 378 | # check for fallback encoding |
@@ -40,6 +40,7 b' def loadpath(path, module_name):' | |||
|
40 | 40 | return imp.load_source(module_name, path) |
|
41 | 41 | |
|
42 | 42 | def load(ui, name, path): |
|
43 | # unused ui argument kept for backwards compatibility | |
|
43 | 44 | if name.startswith('hgext.') or name.startswith('hgext/'): |
|
44 | 45 | shortname = name[6:] |
|
45 | 46 | else: |
@@ -66,12 +67,9 b' def load(ui, name, path):' | |||
|
66 | 67 | _extensions[shortname] = mod |
|
67 | 68 | _order.append(shortname) |
|
68 | 69 | |
|
69 | uisetup = getattr(mod, 'uisetup', None) | |
|
70 | if uisetup: | |
|
71 | uisetup(ui) | |
|
72 | ||
|
73 | 70 | def loadall(ui): |
|
74 | 71 | result = ui.configitems("extensions") |
|
72 | newindex = len(_order) | |
|
75 | 73 | for (name, path) in result: |
|
76 | 74 | if path: |
|
77 | 75 | if path[0] == '!': |
@@ -90,6 +88,11 b' def loadall(ui):' | |||
|
90 | 88 | if ui.traceback(): |
|
91 | 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 | 96 | def wrapcommand(table, command, wrapper): |
|
94 | 97 | aliases, entry = cmdutil.findcmd(command, table) |
|
95 | 98 | for alias, e in table.iteritems(): |
@@ -55,6 +55,29 b' cd a' | |||
|
55 | 55 | hg foo |
|
56 | 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 | 81 | cd .. |
|
59 | 82 | cat > empty.py <<EOF |
|
60 | 83 | '''empty cmdtable |
@@ -16,6 +16,14 b' uisetup called' | |||
|
16 | 16 | reposetup called for a |
|
17 | 17 | ui == repo.ui |
|
18 | 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 | 27 | empty extension - empty cmdtable |
|
20 | 28 | |
|
21 | 29 | no commands defined |
General Comments 0
You need to be logged in to leave comments.
Login now