From patchwork Tue Feb 11 00:49:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1,of,4] revset: added lazyset class with basic operations From: Lucas Moscovicz X-Patchwork-Id: 3559 Message-Id: To: mercurial-devel@selenic.com Date: Mon, 10 Feb 2014 16:49:49 -0800 # HG changeset patch # User Lucas Moscovicz # 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()