[PATCH] extensions: new setup order, try to call extsetup(ui)

Brodie Rao dackze at gmail.com
Thu Aug 13 11:22:08 CDT 2009


On Aug 13, 2009, at 4:48 AM, Simon Heimberg wrote:

> # HG changeset patch
> # User Simon Heimberg <simohe at besonet.ch>
> # Date 1250151959 -7200
> # Node ID 01818c59bf968a5510597c6a5f6940ff52cb4bad
> # Parent  bbe66f8d35da9a1ceca87abbc7e8af81baa51657
> extensions: load all extensions first, call setup functions thereafter
>
> new order for extension calls:
> - load all extensions
> - uisetup(ui) for all extensions
> - extsetup(ui) or extsetup() for all extensions
> - add commands to commandtable for all extensions
> - reposetup(ui, repo) for all extensions

[snip]

> diff -r bbe66f8d35da -r 01818c59bf96 mercurial/extensions.py
> --- a/mercurial/extensions.py	Don Aug 13 10:23:19 2009 +0200
> +++ b/mercurial/extensions.py	Don Aug 13 10:25:59 2009 +0200
> @@ -39,7 +39,7 @@
>     else:
>         return imp.load_source(module_name, path)
>
> -def load(ui, name, path):
> +def load(ui, name, path, init=False):
>     if name.startswith('hgext.') or name.startswith('hgext/'):
>         shortname = name[6:]
>     else:
> @@ -66,9 +66,14 @@
>     _extensions[shortname] = mod
>     _order.append(shortname)
>
> +    if init:
> +        return

I don't like how you use the term "init" here. Just by glancing at the  
function signature I'd assume that it doesn't call the *setup()  
functions by default (i.e., it doesn't initialize the extension).

>     uisetup = getattr(mod, 'uisetup', None)
>     if uisetup:
>         uisetup(ui)
> +    extsetup = getattr(mod, 'extsetup', None)
> +    if extsetup:
> +        extsetup()

What happened to extsetup(ui)?

>
> def loadall(ui):
>     result = ui.configitems("extensions")
> @@ -77,7 +82,7 @@
>             if path[0] == '!':
>                 continue
>         try:
> -            load(ui, name, path)
> +            load(ui, name, path, True)
>         except KeyboardInterrupt:
>             raise
>         except Exception, inst:
> @@ -90,6 +95,27 @@
>             if ui.traceback():
>                 return 1
>
> +_loaded = set()
> +def setupall(ui):
> +    unloaded = []
> +    for name in _order:
> +        if name in _loaded:
> +            continue
> +        mod = _extensions[name]
> +        unloaded.append((name, mod))
> +        _loaded.add(name)
> +        uisetup = getattr(mod, 'uisetup', None)
> +        if uisetup:
> +            uisetup(ui)
> +    for name, mod in unloaded:
> +        extsetup = getattr(mod, 'extsetup', None)
> +        if extsetup:
> +            try:
> +                extsetup(ui)
> +            except TypeError:
> +                extsetup()

What if the extension's extsetup() accepts the ui parameter but  
something in the function throws TypeError? You'd end up suppressing a  
real exception and creating a new TypeError for the call in the except  
clause.

> +    return unloaded
> +
> def wrapcommand(table, command, wrapper):
>     aliases, entry = cmdutil.findcmd(command, table)
>     for alias, e in table.iteritems():



More information about the Mercurial-devel mailing list