[PATCH 2 of 2] extensions: pass ui arguement to extsetup if accepted

Brodie Rao dackze at gmail.com
Fri Aug 28 20:22:33 CDT 2009


On Aug 28, 2009, at 8:25 PM, Martin Geisler wrote:

> Georg Brandl <g.brandl at gmx.net> writes:
>
>> Dirkjan Ochtman schrieb:
>>> On Wed, Aug 26, 2009 at 23:02, Simon Heimberg<simohe at besonet.ch>  
>>> wrote:
>>>> # HG changeset patch
>>>> # User Simon Heimberg <simohe at besonet.ch>
>>>> # Date 1250376084 -7200
>>>> # Node ID 5f4e2711e3b2f1de44ce92616be43c5aa38e3e77
>>>> # Parent  51ca46023b3844b11ee304555ac6f23b7581d67c
>>>> extensions: pass ui arguement to extsetup if accepted
>>>>
>>>> diff -r 51ca46023b38 -r 5f4e2711e3b2 mercurial/extensions.py
>>>> --- a/mercurial/extensions.py   Son Aug 16 00:41:14 2009 +0200
>>>> +++ b/mercurial/extensions.py   Son Aug 16 00:41:24 2009 +0200
>>>> @@ -117,7 +117,12 @@
>>>>    for name, mod in unloaded:
>>>>        extsetup = getattr(mod, 'extsetup', None)
>>>>        if extsetup:
>>>> -            extsetup()
>>>> +            try:
>>>> +                extsetup(ui)
>>>> +            except TypeError:
>>>> +                if extsetup.func_code.co_argcount != 0:
>>>> +                    raise
>>>> +                extsetup() # old extsetup with no ui argument
>>>
>>> Why the try-except this way? Couldn't it just be
>>>
>>> if extsetup.func_code.co_argcount:
>>>    extsetup(ui)
>>> else:
>>>    extsetup()
>>
>> Can't an extension be written in C?
>
> I guess it can, do you mean that func_code.co_argcount wont be there  
> in
> that case? If so, do you know of a better way to handle this?


try:
     util.checksignature(extsetup)(ui)
except util.SignatureError:
     extsetup()

Does extsetup really need to be changed, though? With uisetup being  
called after all extensions are loaded, is it even useful anymore?


More information about the Mercurial-devel mailing list