changeset 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 00f2d29308db
children 2e33cda452f6
files mercurial/revset.py
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Sun Feb 09 00:26:01 2014 +0100
+++ b/mercurial/revset.py	Thu Feb 06 14:19:40 2014 -0800
@@ -2072,5 +2072,23 @@
         l = [r for r in x if r not in s]
         return baseset(list(self) + l)
 
+class lazyset(object):
+    """Duck type for baseset class which iterates lazily over the revisions in
+    the subset and contains a function which tests for membership in the
+    revset
+    """
+    def __init__(self, subset, condition):
+        self._subset = subset
+        self._condition = condition
+
+    def __contains__(self, x):
+        return x in self._subset and self._condition(x)
+
+    def __iter__(self):
+        cond = self._condition
+        for x in self._subset:
+            if cond(x):
+                yield x
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()