[PATCH 1 of 2] color: wrap qdiff/qseries after all extensions are loaded

Martin Geisler mg at lazybytes.net
Thu May 7 11:09:27 CDT 2009


Brodie Rao <dackze at gmail.com> writes:

> # HG changeset patch
> # User Brodie Rao <me+hg at dackz.net>
> # Date 1241641670 14400
> # Node ID 3f9b09941552106f2a5329079cd14e221f1a6b32
> # Parent  edd676eae7d7835e238e7bec6ee09f2b90007b1b
> color: wrap qdiff/qseries after all extensions are loaded
>
> diff --git a/hgext/color.py b/hgext/color.py
> --- a/hgext/color.py
> +++ b/hgext/color.py
> @@ -224,18 +224,24 @@ _diff_effects = {'diffline': ('bold',),
>                   'changed': ('white',),
>                   'trailingwhitespace': ('bold', 'red_background'),}
>  
> +_ui = None
> +
>  def uisetup(ui):
>      '''Initialize the extension.'''
> +    global _ui
> +    _ui = ui
>      _setupcmd(ui, 'diff', commands.table, colordiff, _diff_effects)
>      _setupcmd(ui, 'incoming', commands.table, None, _diff_effects)
>      _setupcmd(ui, 'log', commands.table, None, _diff_effects)
>      _setupcmd(ui, 'outgoing', commands.table, None, _diff_effects)
>      _setupcmd(ui, 'tip', commands.table, None, _diff_effects)
>      _setupcmd(ui, 'status', commands.table, colorstatus, _status_effects)
> +
> +def extsetup():
>      try:
>          mq = extensions.find('mq')
> -        _setupcmd(ui, 'qdiff', mq.cmdtable, colordiff, _diff_effects)
> -        _setupcmd(ui, 'qseries', mq.cmdtable, colorqseries, _patch_effects)
> +        _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

I was sure this would work, but it is unfortunately more tricky than
this and this code still depends on the order in which the extensions
are loaded... When I have the extensions like this:

  [extensions]
  hgext.mq =
  hgext.color =

the mq commands are without color.

The problem is that when dispatch._dispatch loads mq it will do:

  mq.extsetup()
  commands.table.update(mq.cmdtable)

and then when color is loaded it calls

  color.extsetup()

At that point color.extsetup will modify mq.cmdtable, but this does not
take effect because mq.cmdtable was already merged with commands.table.

Maybe this is a good time to fix this TODO comment in dispatch:

    # 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

-- 
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/20090507/368a02e1/attachment.pgp 


More information about the Mercurial-devel mailing list