[PATCH 1 of 2] context: fix repo[n] not to make invalid changectx if n is out of range

Pierre-Yves David pierre-yves.david at ens-lyon.org
Mon Feb 2 08:51:19 CST 2015



On 02/02/2015 02:48 PM, Yuya Nishihara wrote:
> On Mon, 02 Feb 2015 14:25:54 +0000, Pierre-Yves David wrote:
>> On 02/02/2015 02:15 PM, Yuya Nishihara wrote:
>>> # HG changeset patch
>>> # User Yuya Nishihara <yuya at tcha.org>
>>> # Date 1420883783 -32400
>>> #      Sat Jan 10 18:56:23 2015 +0900
>>> # Node ID 184aa519a7a72ab10361d91f66455e3cea8f4f50
>>> # Parent  3667bc21b8773715d9472a3b4e034b77e62c6451
>>> context: fix repo[n] not to make invalid changectx if n is out of range
>>>
>>> This problem was spotted by ba89f7b542c9 (and eb763217152a), so it uses
>>> fullreposet(repo) instead. This fix is necessary to rewrite "rev()" revset
>>> without using fullreposet.
>>>
>>> diff --git a/mercurial/context.py b/mercurial/context.py
>>> --- a/mercurial/context.py
>>> +++ b/mercurial/context.py
>>> @@ -371,6 +371,8 @@ class changectx(basectx):
>>>
>>>            try:
>>>                if isinstance(changeid, int):
>>> +                if changeid < nullrev or changeid >= len(repo.changelog):
>>
>> len(repo.changelog) can be more expensive than you expect this is has to
>> take filtering into account (iirc),
>
> I think it just returns revlog.__len__(), and changectx.__init__() does it
> for string revision.
>
>> you probably want `changeid in repo.changelog`
>
> It will iterate all nodes in changelog, see eb763217152a.

Can't we fix changelog.__contains__ to be non-stupid and fast instead?


-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list