Mercurial > hg
comparison mercurial/dispatch.py @ 9410:1c83938b6a8e
extensions: load and configure extensions in well-defined phases
Extensions are now loaded with a call-graph like this:
dispatch._dispatch
extensions.loadall
extensions.load
# add foo module to extensions._extensions
extensions.load
# add bar module to extensions._extensions
foo.uisetup(ui)
bar.uisetup(ui)
foo.extsetup()
bar.extsetup()
commands.table.update(foo.cmdtable)
commands.table.update(bar.cmdtable)
hg.repository
foo.reposetup(ui, repo)
bar.reposetup(ui, repo)
The uisetup calls could easily be moved out to dispatch._dispatch, but
have been kept in extensions.loadall since at least TortoiseHg calls
extensions.loadall and expects it to call uisetup.
The extensions.load function called uisetup. It now has an unused ui
argument which has been kept for backwards compatibility.
author | Martin Geisler <mg@lazybytes.net> |
---|---|
date | Sat, 29 Aug 2009 00:29:16 +0200 |
parents | 1de6e7e1bb9f |
children | 8e6019b16a7d |
comparison
equal
deleted
inserted
replaced
9409:57157a224037 | 9410:1c83938b6a8e |
---|---|
347 if rpath: | 347 if rpath: |
348 path = lui.expandpath(rpath[-1]) | 348 path = lui.expandpath(rpath[-1]) |
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: | 357 |
355 continue | 358 # (uisetup is handled in extensions.loadall) |
356 | 359 |
357 # setup extensions | 360 for name, module in exts: |
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 | |
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: |
368 ui.warn(_("extension '%s' overrides commands: %s\n") | 369 ui.warn(_("extension '%s' overrides commands: %s\n") |
369 % (name, " ".join(overrides))) | 370 % (name, " ".join(overrides))) |
370 commands.table.update(cmdtable) | 371 commands.table.update(cmdtable) |
371 _loaded.add(name) | 372 _loaded.add(name) |
373 | |
374 # (reposetup is handled in hg.repository) | |
372 | 375 |
373 addaliases(lui, commands.table) | 376 addaliases(lui, commands.table) |
374 | 377 |
375 # check for fallback encoding | 378 # check for fallback encoding |
376 fallback = lui.config('ui', 'fallbackencoding') | 379 fallback = lui.config('ui', 'fallbackencoding') |