Patchwork [2,of,4] revset: added filter method to revset classes

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 27, 2014, 10:12 p.m.
Message ID <b6c85775ed674469fa9b.1393539169@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3786/
State Superseded
Headers show

Comments

Lucas Moscovicz - Feb. 27, 2014, 10:12 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1391735891 28800
#      Thu Feb 06 17:18:11 2014 -0800
# Node ID b6c85775ed674469fa9b5a5bc66588bed6283dcb
# Parent  730d872f70ae8b6d7b509cc31c6f85f02c1a1186
revset: added filter method to revset classes

This method will replace the creation of lazysets inside the revset methods.
Instead, the classes that handle lazy structures will create them based on
their current order.
Matt Mackall - Feb. 27, 2014, 10:22 p.m.
On Thu, 2014-02-27 at 14:12 -0800, Lucas Moscovicz wrote:
> # HG changeset patch
> # User Lucas Moscovicz <lmoscovicz@fb.com>
> # Date 1391735891 28800
> #      Thu Feb 06 17:18:11 2014 -0800
> # Node ID b6c85775ed674469fa9b5a5bc66588bed6283dcb
> # Parent  730d872f70ae8b6d7b509cc31c6f85f02c1a1186
> revset: added filter method to revset classes

> +        if self._start <= self._end:
> +            return orderedlazyset(self, l, 'asc')

As I mentioned last time around, these strings indicating direction are
really ugly. Use an int like 1 or -1 or a bool (eg ascending=True) or
basically anything but a string, please.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2146,6 +2146,9 @@ 
         l = [r for r in x if r not in s]
         return baseset(list(self) + l)
 
+    def filter(self, l):
+        return lazyset(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
@@ -2204,6 +2207,9 @@ 
     def set(self):
         return set([r for r in self])
 
+    def filter(self, l):
+        return lazyset(self, l)
+
 class orderedlazyset(lazyset):
     """Subclass of lazyset which subset can be ordered either ascending or
     descendingly
@@ -2212,6 +2218,9 @@ 
         super(orderedlazyset, self).__init__(subset, condition)
         self._order = order
 
+    def filter(self, l):
+        return orderedlazyset(self, l, self._order)
+
 class generatorset(object):
     """Wrapper structure for generators that provides lazy membership and can
     be iterated more than once.
@@ -2345,5 +2354,11 @@ 
     def set(self):
         return self
 
+    def filter(self, l):
+        if self._start <= self._end:
+            return orderedlazyset(self, l, 'asc')
+        else:
+            return orderedlazyset(self, l, 'desc')
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()