Patchwork [7,of,9,RFC] revset: added order property to lazyset classes

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

Comments

Lucas Moscovicz - Feb. 12, 2014, 10:39 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1391791458 28800
#      Fri Feb 07 08:44:18 2014 -0800
# Node ID 35e93209ef29f786911232f9f37ad95661abf3d9
# Parent  1cc650bf69c051609ef85d955d7562cbf9285743
revset: added order property to lazyset classes

This will allow revsetsto know if the subset they get is ordered in some way
to be able to work lazily when possible.
Matt Mackall - Feb. 14, 2014, 5:49 p.m.
On Wed, 2014-02-12 at 14:39 -0800, Lucas Moscovicz wrote:
> # HG changeset patch
> # User Lucas Moscovicz <lmoscovicz@fb.com>
> # Date 1391791458 28800
> #      Fri Feb 07 08:44:18 2014 -0800
> # Node ID 35e93209ef29f786911232f9f37ad95661abf3d9
> # Parent  1cc650bf69c051609ef85d955d7562cbf9285743
> revset: added order property to lazyset classes

This looks promising. Using strings for the direction names is a bit
unfortunate though.

Perhaps we can do something like this:

def ascending(self):
    # true if we can -efficiently- traverse this set in ascending order

def descending(self):
    # true if we can -efficiently- traverse this set in descending order

Both of these would be true for lazyset and spanset. And then we can
make algorithms that are conditional on these.
Pierre-Yves David - Feb. 14, 2014, 8:48 p.m.
On 02/14/2014 09:49 AM, Matt Mackall wrote:
> On Wed, 2014-02-12 at 14:39 -0800, Lucas Moscovicz wrote:
>> # HG changeset patch
>> # User Lucas Moscovicz <lmoscovicz@fb.com>
>> # Date 1391791458 28800
>> #      Fri Feb 07 08:44:18 2014 -0800
>> # Node ID 35e93209ef29f786911232f9f37ad95661abf3d9
>> # Parent  1cc650bf69c051609ef85d955d7562cbf9285743
>> revset: added order property to lazyset classes
>
> This looks promising. Using strings for the direction names is a bit
> unfortunate though.
>
> Perhaps we can do something like this:
>
> def ascending(self):
>      # true if we can -efficiently- traverse this set in ascending order
>
> def descending(self):
>      # true if we can -efficiently- traverse this set in descending order

If we can use more attribute instead of function call that would help to 
avoid the Python slowness.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2070,6 +2070,10 @@ 
         super(baseset, self).__init__(data)
         self._set = None
 
+    @property
+    def order(self):
+        return None
+
     def set(self):
         if not self._set:
             self._set = set(self)
@@ -2105,6 +2109,10 @@ 
         self._condition = condition
         self._ncache = set()
 
+    @property
+    def order(self):
+        return None
+
     def __contains__(self, x):
         if x in self._ncache:
             return False
@@ -2154,6 +2162,10 @@ 
         return lazyset(self, l)
 
 class asclazyset(lazyset):
+    @property
+    def order(self):
+        return 'asc'
+
     def filter(self, l):
         return asclazyset(self, l)
 
@@ -2164,6 +2176,10 @@ 
         return asclazyset(self, lambda r: r not in x)
 
 class desclazyset(lazyset):
+    @property
+    def order(self):
+        return 'desc'
+
     def filter(self, l):
         return desclazyset(self, l)
 
@@ -2259,6 +2275,13 @@ 
         self._end = end
         self._hiddenrevs = hiddenrevs
 
+    @property
+    def order(self):
+        if self._start <= self._end:
+            return 'asc'
+        else:
+            return 'desc'
+
     def _hidden(self, rev):
         return self._hiddenrevs and rev in self._hiddenrevs