[PATCH 6 of 9] record extension: removed 'has_key' usage

Nicolas Dumazet nicdumz at gmail.com
Thu Jul 1 20:57:47 CDT 2010


2010/7/2 Greg Ward <greg-hg at gerg.ca>:
> On Thu, Jul 1, 2010 at 6:27 PM, Renato Cunha <renatoc at gmail.com> wrote:
>>  hgext/record.py |  5 ++++-
>>  1 files changed, 4 insertions(+), 1 deletions(-)
>>
>>
>> # HG changeset patch
>> # User Renato Cunha <renatoc at gmail.com>
>> # Date 1278023223 10800
>> # Node ID b16f77a9ba30bc5053d35926d1fd1a8066d018a6
>> # Parent  be82e9c22659856bfe041391f9ebe15f4c79e939
>> record extension: removed 'has_key' usage.
>>
>> Py3k has removed the dictionary has_key method. This patch implements a one
>> argument function that can be used as a callback by hg.revert in the record
>> extension.
>>
>> diff --git a/hgext/record.py b/hgext/record.py
>> --- a/hgext/record.py
>> +++ b/hgext/record.py
>> @@ -486,7 +486,10 @@
>>
>>             # 3a. apply filtered patch to clean repo  (clean)
>>             if backups:
>> -                hg.revert(repo, repo.dirstate.parents()[0], backups.has_key)
>> +                def has_key(key):
>> +                    return key in has_key.backups
>> +                has_key.backups = backups
>> +                hg.revert(repo, repo.dirstate.parents()[0], has_key)
>
> Can't you just pass backups.__contains__ there?  If you look in the
> Python source (Objects/dictobject.c), you can see that the C function
> implementing has_key() (dict_has_key()) just calls dict_contains(),
> which is the implementation of __contains__().

And it exists in Python2.4 through py3k, so +1

And -1 to Mads ;)

Cheers,

>
> Greg
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>



-- 
Nicolas Dumazet — NicDumZ


More information about the Mercurial-devel mailing list