[PATCH 1 of 4] revset: added lazyset class with basic operations

Lucas Moscovicz lmoscovicz at fb.com
Mon Feb 10 18:49:49 CST 2014


# HG changeset patch
# User Lucas Moscovicz <lmoscovicz at fb.com>
# Date 1391725180 28800
#      Thu Feb 06 14:19:40 2014 -0800
# Node ID dd21fb069db6f9d8fffcb50c98f0d3f29db110ba
# Parent  3925ccf169223cfde890c83d5429f3f533f07214
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.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2071,5 +2071,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()


More information about the Mercurial-devel mailing list