Patchwork revset: changed spanset implementation to take hidden revisions into account

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 14, 2014, 4:49 p.m.
Message ID <d9966f60aaff167b866e.1392396569@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3657/
State Superseded
Commit 1850a7f5fb66928d34a029d80758d335c790c39f
Headers show

Comments

Lucas Moscovicz - Feb. 14, 2014, 4:49 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1392082723 28800
#      Mon Feb 10 17:38:43 2014 -0800
# Node ID d9966f60aaff167b866e02185769bdc06fd4c778
# Parent  959d8a69a22ef664626abd997143f58babbdbedf
revset: changed spanset implementation to take hidden revisions into account

Hidden revisions are now excluded from the spanset.
Now this doesn't break for people using changeset evolution.
Matt Mackall - Feb. 14, 2014, 5:36 p.m.
On Fri, 2014-02-14 at 08:49 -0800, Lucas Moscovicz wrote:
>      def __iter__(self):
>          if self._start <= self._end:
>              for r in xrange(self._start, self._end):
> -                yield r
> +                if not self._hidden(r):
> +                    yield r
>          else:
>              for r in xrange(self._start, self._end, -1):
> -                yield r
> +                if not self._hidden(r):
> +                    yield r

How can you fix this so that it minimizes a) expensive name lookups and
b) expensive function calls when the hidden set is empty?

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2132,21 +2132,30 @@ 
     """Duck type for baseset class which represents a range of revisions and
     can work lazily and without having all the range in memory
     """
-    def __init__(self, start, end):
+    def __init__(self, start, end, hiddenrevs=set()):
         self._start = start
         self._end = end
+        self._hiddenrevs = hiddenrevs
+
+    def _hidden(self, rev):
+        return self._hiddenrevs and rev in self._hiddenrevs
+
+    def _contained(self, rev):
+        return (rev <= self._start and rev > self._end) or (rev >= self._start
+                and rev < self._end)
 
     def __iter__(self):
         if self._start <= self._end:
             for r in xrange(self._start, self._end):
-                yield r
+                if not self._hidden(r):
+                    yield r
         else:
             for r in xrange(self._start, self._end, -1):
-                yield r
+                if not self._hidden(r):
+                    yield r
 
     def __contains__(self, x):
-        return (x <= self._start and x > self._end) or (x >= self._start and x<
-                self._end)
+        return self._contained(x) and not self._hidden(x)
 
     def __and__(self, x):
         return lazyset(self, lambda r: r in x)
@@ -2159,7 +2168,14 @@ 
         return l + baseset(x)
 
     def __len__(self):
-        return abs(self._end - self._start)
+        if not self._hiddenrevs:
+            return abs(self._end - self._start)
+        else:
+            count = 0
+            for rev in self._hiddenrevs:
+                if self._contained(rev):
+                    count += 1
+            return abs(self._end - self._start) - count
 
     def __getitem__(self, x):
         # Basic implementation to be changed in future patches.