Patchwork [2,of,2] revset: added extend and append methods to lazy structures

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 20, 2014, midnight
Message ID <d9bb5abb1c584e3e04ac.1392854412@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3705/
State Accepted
Headers show

Comments

Lucas Moscovicz - Feb. 20, 2014, midnight
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@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.
Matt Mackall - Feb. 21, 2014, 11:29 p.m.
On Wed, 2014-02-19 at 16:00 -0800, Lucas Moscovicz wrote:
> # HG changeset patch
> # User Lucas Moscovicz <lmoscovicz@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.

What code currently uses extend or append? Can we consider changing that
code instead?

I've queued patch 1.
Lucas Moscovicz - Feb. 21, 2014, 11:50 p.m.
On 2/21/14, 3:29 PM, "Matt Mackall" <mpm@selenic.com> wrote:

>On Wed, 2014-02-19 at 16:00 -0800, Lucas Moscovicz wrote:
>> # HG changeset patch
>> # User Lucas Moscovicz <lmoscovicz@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.
>
>What code currently uses extend or append? Can we consider changing that
>code instead?

Extend is actually used on scmutil on revrange method which I changed in
later patches to work with lazysets.


>
>I've queued patch 1.
>
>-- 
>Mathematics is the supreme nostalgia of our time.
>
>
Matt Mackall - Feb. 21, 2014, 11:52 p.m.
On Fri, 2014-02-21 at 23:50 +0000, Lucas Moscovicz wrote:
> On 2/21/14, 3:29 PM, "Matt Mackall" <mpm@selenic.com> wrote:
> 
> >On Wed, 2014-02-19 at 16:00 -0800, Lucas Moscovicz wrote:
> >> # HG changeset patch
> >> # User Lucas Moscovicz <lmoscovicz@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.
> >
> >What code currently uses extend or append? Can we consider changing that
> >code instead?
> 
> Extend is actually used on scmutil on revrange method which I changed in
> later patches to work with lazysets.

Ok, that answers half of my question?
Lucas Moscovicz - Feb. 21, 2014, 11:53 p.m.
On 2/21/14, 3:52 PM, "Matt Mackall" <mpm@selenic.com> wrote:

>Ok, that answers half of my question?

I¹m not sure if append is used, I implemented it just in case I need it in
another patch but I think I can just remove it for now.
Matt Mackall - Feb. 21, 2014, 11:55 p.m.
On Fri, 2014-02-21 at 23:53 +0000, Lucas Moscovicz wrote:
> 
> On 2/21/14, 3:52 PM, "Matt Mackall" <mpm@selenic.com> wrote:
> 
> >Ok, that answers half of my question?
> 
> I¹m not sure if append is used, I implemented it just in case I need it in
> another patch but I think I can just remove it for now.

Let me try again: can we nuke all the code that attempts to use
list.extend on revsets rather than add an extend method to a bunch of
classes?
Lucas Moscovicz - Feb. 21, 2014, 11:57 p.m.
On 2/21/14, 3:55 PM, "Matt Mackall" <mpm@selenic.com> wrote:

>On Fri, 2014-02-21 at 23:53 +0000, Lucas Moscovicz wrote:

>> 

>> On 2/21/14, 3:52 PM, "Matt Mackall" <mpm@selenic.com> wrote:

>> 

>> >Ok, that answers half of my question?

>> 

>> I¹m not sure if append is used, I implemented it just in case I need it

>>in

>> another patch but I think I can just remove it for now.

>

>Let me try again: can we nuke all the code that attempts to use

>list.extend on revsets rather than add an extend method to a bunch of

>classes?


I think we actually may be able to do that. I’ll see if I can get it
working without the extend method.

>

>-- 

>Mathematics is the supreme nostalgia of our time.

>

>

Patch

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)