[PATCH] Provide better context for custom Python encode/decode filters

Patrick Mézard pmezard at gmail.com
Sun Jan 27 13:08:28 CST 2008


Jesse Glick a écrit :
> Patrick Mézard wrote:
>> Here is the rebased version of your patch assuming mine is pushed.
>> Main differences:
>> - exchanged filename/repo arguments positions. Most functions seem to take (ui, repo, ...).
> 
> Yes, fine.
> 
>> - moved the inspect logic in localrepo._filter() and run it one at every filter creation.
> 
> Not sure I understand why, but if it works then fine.

I could not find any compelling reason to keep registering this stuff in util.py, so it went in the most reduced scope by default, localrepo.py. It makes sense here to pass arguments like ui or repo. I don't like the idea of having util.filter handling opaque parameters only some obscure caller knows about. Let's do that when we really need it.
 
>> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
>> --- a/mercurial/localrepo.py
>> +++ b/mercurial/localrepo.py
>> -                    fn = lambda s, c: util.filter(s, c)
>> +                    def filterfn(s, cmd, **kwargs):
>> +                        return util.filter(s, cmd)
>> +                    fn = filterfn
> 
> Can't you just use
> 
>    fn = lambda s, c, **kwargs: util.filter(s, c)

Let's say I did not take 30 seconds to test how well lambdas support optional arguments and I knew I had a solution working at least as well and not especially ugly so... 

I will keep the lambdas.

--
Patrick Mézard


More information about the Mercurial-devel mailing list