comparison mercurial/revset.py @ 20427:4a9191ca848e

revset: added lazyset class with basic operations This class allows us to return values from large revsets as soon as they are computed instead of having to wait for the entire revset to be calculated.
author Lucas Moscovicz <lmoscovicz@fb.com>
date Thu, 06 Feb 2014 14:19:40 -0800
parents 1da346bad3d8
children 2e33cda452f6
comparison
equal deleted inserted replaced
20426:00f2d29308db 20427:4a9191ca848e
2070 def __add__(self, x): 2070 def __add__(self, x):
2071 s = self.set() 2071 s = self.set()
2072 l = [r for r in x if r not in s] 2072 l = [r for r in x if r not in s]
2073 return baseset(list(self) + l) 2073 return baseset(list(self) + l)
2074 2074
2075 class lazyset(object):
2076 """Duck type for baseset class which iterates lazily over the revisions in
2077 the subset and contains a function which tests for membership in the
2078 revset
2079 """
2080 def __init__(self, subset, condition):
2081 self._subset = subset
2082 self._condition = condition
2083
2084 def __contains__(self, x):
2085 return x in self._subset and self._condition(x)
2086
2087 def __iter__(self):
2088 cond = self._condition
2089 for x in self._subset:
2090 if cond(x):
2091 yield x
2092
2075 # tell hggettext to extract docstrings from these functions: 2093 # tell hggettext to extract docstrings from these functions:
2076 i18nfunctions = symbols.values() 2094 i18nfunctions = symbols.values()