[PATCH 1 of 2] extensions: add loadext hook

Martin Geisler mg at lazybytes.net
Wed May 6 14:23:43 CDT 2009


Brodie Rao <dackze at gmail.com> writes:

> diff --git a/hgext/color.py b/hgext/color.py
> --- a/hgext/color.py
> +++ b/hgext/color.py
> @@ -232,13 +232,12 @@ def uisetup(ui):
>      _setupcmd(ui, 'outgoing', commands.table, None, _diff_effects)
>      _setupcmd(ui, 'tip', commands.table, None, _diff_effects)
>      _setupcmd(ui, 'status', commands.table, colorstatus, _status_effects)
> -    try:
> -        mq = extensions.find('mq')
> -        _setupcmd(ui, 'qdiff', mq.cmdtable, colordiff, _diff_effects)
> -        _setupcmd(ui, 'qseries', mq.cmdtable, colorqseries, _patch_effects)
> -    except KeyError:
> -        # The mq extension is not enabled
> -        pass
> +    ui.setconfig('hooks', 'loadext', _setupext)
> +
> +def _setupext(ui, repo, hooktype, extname, mod):
> +    if extname == 'mq':
> +        _setupcmd(ui, 'qdiff', mod.cmdtable, colordiff, _diff_effects)
> +        _setupcmd(ui, 'qseries', mod.cmdtable, colorqseries, _patch_effects)

Currently we have the following calls (in pseudo-python):

  dispatch._dispatch:
    extensions.loadall(lui)
      for (name, path) in result:
          load(ui, name, path)
            mod = importh(name)
            mod.uisetup(ui)
    for name, mod in extensions.extensions()
      mod.extsetup()

The problem is that color tries to wrap the functions in it's uisetup
function. If it used extsetup things should work fine -- except that it
needs a ui object in extsetup. It could store the ui away in uisetup and
use it in extsetup.

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial-devel/attachments/20090506/d608c43e/attachment.pgp 


More information about the Mercurial-devel mailing list