Move cmdtable and reposetup handling out of extensions.py
A new function (extensions.extensions) allows the code that is
interested in those attributes to handle them directly.
This allows some cleanups of extensions.py. Notably, we can
remove the extensions.commandtable hack.
It also makes it easier to add standard extension attributes,
like a "hgwebsetup" function or a "helptable" dict that augments
the data in help.py, etc.
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3129,8 +3129,6 @@ table = {
"version": (version_, [], _('hg version')),
}
-extensions.commandtable = table
-
norepo = ("clone init version help debugancestor debugcomplete debugdata"
" debugindex debugindexdot debugdate debuginstall")
optionalrepo = ("paths serve showconfig")
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -238,6 +238,7 @@ def _earlygetopt(aliases, args):
pos += 1
return values
+_loaded = {}
def _dispatch(ui, args):
# read --config before doing anything else
# (e.g. to change trust settings for reading .hg/hgrc)
@@ -269,6 +270,16 @@ def _dispatch(ui, args):
lui.readconfig(os.path.join(path, ".hg", "hgrc"))
extensions.loadall(lui)
+ for name, module in extensions.extensions():
+ if name in _loaded:
+ continue
+ 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[name] = 1
# check for fallback encoding
fallback = lui.config('ui', 'fallbackencoding')
if fallback:
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -10,8 +10,13 @@ import util, sys
from i18n import _
_extensions = {}
-commandtable = {}
-setuphooks = []
+_order = []
+
+def extensions():
+ for name in _order:
+ module = _extensions[name]
+ if module:
+ yield name, module
def find(name):
'''return module with given extension name'''
@@ -55,19 +60,11 @@ def load(ui, name, path):
except ImportError:
mod = importh(name)
_extensions[shortname] = mod
+ _order.append(shortname)
uisetup = getattr(mod, 'uisetup', None)
if uisetup:
uisetup(ui)
- reposetup = getattr(mod, 'reposetup', None)
- if reposetup:
- setuphooks.append(reposetup)
- cmdtable = getattr(mod, 'cmdtable', {})
- overrides = [cmd for cmd in cmdtable if cmd in commandtable]
- if overrides:
- ui.warn(_("extension '%s' overrides commands: %s\n")
- % (name, " ".join(overrides)))
- commandtable.update(cmdtable)
def loadall(ui):
result = ui.configitems("extensions")
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -61,8 +61,10 @@ def repository(ui, path='', create=False
"""return a repository object for the specified path"""
repo = _lookup(path).instance(ui, path, create)
ui = getattr(repo, "ui", ui)
- for hook in extensions.setuphooks:
- hook(ui, repo)
+ for name, module in extensions.extensions():
+ hook = getattr(module, 'reposetup', None)
+ if hook:
+ hook(ui, repo)
return repo
def defaultdest(source):