[PATCH 2 of 2] revset: added extend and append methods to lazy structures
Lucas Moscovicz
lmoscovicz at fb.com
Wed Feb 19 18:00:12 CST 2014
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz at fb.com>
# 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)
More information about the Mercurial-devel
mailing list