Mercurial > hg
changeset 2944:2efa9b8aed30
load extensions from every hgrc.
before this change only extensions in global hgrc files were loaded.
now extensions in per-repo hgrc are loaded.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Fri, 18 Aug 2006 14:13:24 -0700 |
parents | 8e59010158ce |
children | 731f6b3d27c2 |
files | mercurial/commands.py mercurial/ui.py |
diffstat | 2 files changed, 16 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Fri Aug 11 16:12:14 2006 -0700 +++ b/mercurial/commands.py Fri Aug 18 14:13:24 2006 -0700 @@ -3449,8 +3449,11 @@ return sys.modules[v] raise KeyError(name) -def load_extensions(ui, extensions): - for ext_name, load_from_name in extensions: +def load_extensions(ui): + added = [] + for ext_name, load_from_name in ui.extensions(): + if ext_name in external: + continue try: if load_from_name: # the module will be loaded in sys.modules @@ -3470,6 +3473,7 @@ except ImportError: mod = importh(ext_name) external[ext_name] = mod.__name__ + added.append((mod, ext_name)) except (util.SignalInterrupt, KeyboardInterrupt): raise except Exception, inst: @@ -3478,11 +3482,10 @@ if ui.print_exc(): return 1 - for name in external.itervalues(): - mod = sys.modules[name] + for mod, name in added: uisetup = getattr(mod, 'uisetup', None) if uisetup: - uisetup(u) + uisetup(ui) cmdtable = getattr(mod, 'cmdtable', {}) for t in cmdtable: if t in table: @@ -3495,13 +3498,12 @@ if num: signal.signal(num, catchterm) try: - u = ui.ui(traceback='--traceback' in sys.argv[1:]) + u = ui.ui(traceback='--traceback' in sys.argv[1:], + readhooks=[load_extensions]) except util.Abort, inst: sys.stderr.write(_("abort: %s\n") % inst) return -1 - load_extensions(u, u.extensions()) - try: cmd, func, args, options, cmdoptions = parse(u, args) if options["time"]:
--- a/mercurial/ui.py Fri Aug 11 16:12:14 2006 -0700 +++ b/mercurial/ui.py Fri Aug 18 14:13:24 2006 -0700 @@ -12,11 +12,13 @@ class ui(object): def __init__(self, verbose=False, debug=False, quiet=False, - interactive=True, traceback=False, parentui=None): + interactive=True, traceback=False, parentui=None, + readhooks=[]): self.overlay = {} if parentui is None: # this is the parent of all ui children self.parentui = None + self.readhooks = list(readhooks) self.cdata = ConfigParser.SafeConfigParser() self.readconfig(util.rcpath()) @@ -34,6 +36,7 @@ else: # parentui may point to an ui object which is already a child self.parentui = parentui.parentui or parentui + self.readhooks = list(parentui.readhooks or readhooks) parent_cdata = self.parentui.cdata self.cdata = ConfigParser.SafeConfigParser(parent_cdata.defaults()) # make interpolation work @@ -78,6 +81,8 @@ for name, path in self.configitems("paths"): if path and "://" not in path and not os.path.isabs(path): self.cdata.set("paths", name, os.path.join(root, path)) + for hook in self.readhooks: + hook(self) def setconfig(self, section, name, val): self.overlay[(section, name)] = val