[PATCH 1 of 2] revlog: add __contains__ for fast membership test

Yuya Nishihara yuya at tcha.org
Thu Feb 5 12:18:00 UTC 2015


On Wed, 4 Feb 2015 08:29:08 -0800, Gregory Szorc wrote:
> diff --git a/mercurial/changelog.py b/mercurial/changelog.py
> > --- a/mercurial/changelog.py
> > +++ b/mercurial/changelog.py
> > @@ -143,6 +143,11 @@ class changelog(revlog.revlog):
> >              if i not in self.filteredrevs:
> >                  return self.node(i)
> >
> > +    def __contains__(self, rev):
> > +        """filtered version of revlog.__contains__"""
> > +        return (revlog.revlog.__contains__(self, rev)
> > +                and rev not in self.filteredrevs)
> > +
> >
> 
> What you've implemented here is changelog.hasunfilteredrev(). I'm not
> convinced __contains__ should be implemented:
> 
> a) to only accept numeric revisions (what about nodes)
> b) to only operate on unfiltered revs
> 
> "a" applies to revlog.__contains__ as well.

What about hasrev(rev) because there's hasnode(node) ?
Anyway, I think __contains__ should be implemented to ban use of slow
"x in repo.changelog".

Regards,



More information about the Mercurial-devel mailing list