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

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 11, 2014, 12:49 a.m.
Message ID <dd21fb069db6f9d8fffc.1392079789@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3559/
State Accepted
Commit 4a9191ca848e232613d4577b83cc9b92bee313bb
Headers show

Comments

Lucas Moscovicz - Feb. 11, 2014, 12:49 a.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@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.

Patch

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()