[PATCH 1 of 2] extensions: load all extensions first, call setup functions thereafter
Simon Heimberg
simohe at besonet.ch
Sat Aug 15 17:54:32 CDT 2009
# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1250376074 -7200
# Node ID 81213461824da8521d5e18f258f414085d49f9ba
# Parent b90014474342c4d3f35595d96ceb3388898e16ac
extensions: load all extensions first, call setup functions thereafter
new order for extension calls:
- load all extensions
- uisetup(ui) for all extensions
- extsetup(ui) or extsetup() for all extensions
- add commands to commandtable for all extensions
- reposetup(ui, repo) for all extensions
diff -r b90014474342 -r 81213461824d mercurial/dispatch.py
--- a/mercurial/dispatch.py Son Aug 16 00:41:12 2009 +0200
+++ b/mercurial/dispatch.py Son Aug 16 00:41:14 2009 +0200
@@ -320,7 +320,6 @@
result = ret)
return ret
-_loaded = set()
def _dispatch(ui, args):
# read --config before doing anything else
# (e.g. to change trust settings for reading .hg/hgrc)
@@ -350,25 +349,6 @@
lui.readconfig(os.path.join(path, ".hg", "hgrc"))
extensions.loadall(lui)
- for name, module in extensions.extensions():
- if name in _loaded:
- continue
-
- # setup extensions
- # TODO this should be generalized to scheme, where extensions can
- # redepend on other extensions. then we should toposort them, and
- # do initialization in correct order
- extsetup = getattr(module, 'extsetup', None)
- if extsetup:
- extsetup()
-
- cmdtable = getattr(module, 'cmdtable', {})
- overrides = [cmd for cmd in cmdtable if cmd in commands.table]
- if overrides:
- ui.warn(_("extension '%s' overrides commands: %s\n")
- % (name, " ".join(overrides)))
- commands.table.update(cmdtable)
- _loaded.add(name)
addaliases(lui, commands.table)
diff -r b90014474342 -r 81213461824d mercurial/extensions.py
--- a/mercurial/extensions.py Son Aug 16 00:41:12 2009 +0200
+++ b/mercurial/extensions.py Son Aug 16 00:41:14 2009 +0200
@@ -39,7 +39,7 @@
else:
return imp.load_source(module_name, path)
-def load(ui, name, path):
+def load(ui, name, path, setuplater=False):
if name.startswith('hgext.') or name.startswith('hgext/'):
shortname = name[6:]
else:
@@ -66,18 +66,21 @@
_extensions[shortname] = mod
_order.append(shortname)
- uisetup = getattr(mod, 'uisetup', None)
- if uisetup:
- uisetup(ui)
+ if setuplater:
+ return
+ setup(ui, [shortname])
def loadall(ui):
+ '''
+ load all configured extensions and execute setup
+ '''
result = ui.configitems("extensions")
for (name, path) in result:
if path:
if path[0] == '!':
continue
try:
- load(ui, name, path)
+ load(ui, name, path, True)
except KeyboardInterrupt:
raise
except Exception, inst:
@@ -89,6 +92,42 @@
% (name, inst))
if ui.traceback():
return 1
+ setup(ui, None)
+
+_loaded = set()
+def setup(ui, modules):
+ '''
+ Execute uisetup and extsetup for all given modules and update the
+ commandtable. Each task is done for all extensions before the next task.
+ If modules is none, setup is executed for all loaded uninitialized
+ modules.
+ '''
+ import commands
+
+ if modules is None:
+ modules = _order
+ unloaded = []
+ for name in modules:
+ if name in _loaded:
+ continue
+ mod = _extensions[name]
+ unloaded.append((name, mod))
+ _loaded.add(name)
+ uisetup = getattr(mod, 'uisetup', None)
+ if uisetup:
+ uisetup(ui)
+ for name, mod in unloaded:
+ extsetup = getattr(mod, 'extsetup', None)
+ if extsetup:
+ extsetup()
+ for name, mod in unloaded:
+ cmdtable = getattr(mod, 'cmdtable', {})
+ overrides = [cmd for cmd in cmdtable if cmd in commands.table]
+ if overrides:
+ ui.warn(_("extension '%s' overrides commands: %s\n")
+ % (name, " ".join(overrides)))
+ commands.table.update(cmdtable)
+ return unloaded
def wrapcommand(table, command, wrapper):
aliases, entry = cmdutil.findcmd(command, table)
More information about the Mercurial-devel
mailing list