From patchwork Thu Feb 20 00:00:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2,of,2] revset: added extend and append methods to lazy structures From: Lucas Moscovicz X-Patchwork-Id: 3705 Message-Id: To: mercurial-devel@selenic.com Date: Wed, 19 Feb 2014 16:00:12 -0800 # HG changeset patch # User Lucas Moscovicz # Date 1392320573 28800 # Thu Feb 13 11:42:53 2014 -0800 # Node ID d9bb5abb1c584e3e04ac3632805ff8886b1a2973 # Parent 4c90d85a7bc219eac7575beb7257619330f17c02 revset: added extend and append methods to lazy structures This methods will be used to duck type baseset. diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -2098,7 +2098,7 @@ the subset and contains a function which tests for membership in the revset """ - def __init__(self, subset, condition): + def __init__(self, subset, condition=lambda x: True): self._subset = subset self._condition = condition self._cache = {} @@ -2125,6 +2125,18 @@ l = baseset([r for r in self]) return l + baseset(x) + def append(self, x): + def gen(): + for r in self: + yield r + for r in x: + yield r + + return lazyset(generatorset(gen())) + + def extend(self, x): + self.append(x) + def __len__(self): # Basic implementation to be changed in future patches. l = baseset([r for r in self]) @@ -2246,6 +2258,18 @@ l = baseset(self) return l + baseset(x) + def append(self, x): + def gen(): + for r in self: + yield r + for r in x: + yield r + + return lazyset(generatorset(gen())) + + def extend(self, x): + self.append(x) + def __len__(self): if not self._hiddenrevs: return abs(self._end - self._start)