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

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 14, 2014, 8:57 p.m.
Message ID <84f626df10a5df208b21.1392411427@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3662/
State Accepted
Commit 1850a7f5fb66928d34a029d80758d335c790c39f
Headers show

Comments

Lucas Moscovicz - Feb. 14, 2014, 8:57 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1392082723 28800
#      Mon Feb 10 17:38:43 2014 -0800
# Node ID 84f626df10a5df208b211d3ad907562034d33c1e
# 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.
Olle Lundberg - Feb. 15, 2014, 2:20 p.m.
On Fri, Feb 14, 2014 at 9:57 PM, Lucas Moscovicz <lmoscovicz@fb.com> wrote:

> # HG changeset patch
> # User Lucas Moscovicz <lmoscovicz@fb.com>
> # Date 1392082723 28800
> #      Mon Feb 10 17:38:43 2014 -0800
> # Node ID 84f626df10a5df208b211d3ad907562034d33c1e
> # 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.
>
> diff --git a/mercurial/revset.py b/mercurial/revset.py
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -2132,21 +2132,33 @@
>      """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 _contained(self, rev):
> +        return (rev <= self._start and rev > self._end) or (rev >=
> self._start
> +                and rev < self._end)
>

This notation:
return (self._end < rev <= self._start) or ( self._start <= rev < self._end)

Is more readable IMHO.


>
>      def __iter__(self):
>          if self._start <= self._end:
> -            for r in xrange(self._start, self._end):
> -                yield r
> +            iterrange = xrange(self._start, self._end)
>          else:
> -            for r in xrange(self._start, self._end, -1):
> +            iterrange = xrange(self._start, self._end, -1)
> +
> +        if self._hiddenrevs:
> +            s = self._hiddenrevs
> +            for r in iterrange:
> +                if r not in s:
> +                    yield r
> +        else:
> +            for r in iterrange:
>                  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._hiddenrevs and rev in
> +                self._hiddenrevs)
>
>      def __and__(self, x):
>          return lazyset(self, lambda r: r in x)
> @@ -2159,7 +2171,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.
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>
Matt Mackall - Feb. 16, 2014, 4:07 a.m.
On Fri, 2014-02-14 at 12:57 -0800, Lucas Moscovicz wrote:
> # HG changeset patch
> # User Lucas Moscovicz <lmoscovicz@fb.com>
> # Date 1392082723 28800
> #      Mon Feb 10 17:38:43 2014 -0800
> # Node ID 84f626df10a5df208b211d3ad907562034d33c1e
> # Parent  959d8a69a22ef664626abd997143f58babbdbedf
> revset: changed spanset implementation to take hidden revisions into account

Queued for default, thanks.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2132,21 +2132,33 @@ 
     """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 _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
+            iterrange = xrange(self._start, self._end)
         else:
-            for r in xrange(self._start, self._end, -1):
+            iterrange = xrange(self._start, self._end, -1)
+
+        if self._hiddenrevs:
+            s = self._hiddenrevs
+            for r in iterrange:
+                if r not in s:
+                    yield r
+        else:
+            for r in iterrange:
                 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._hiddenrevs and rev in
+                self._hiddenrevs)
 
     def __and__(self, x):
         return lazyset(self, lambda r: r in x)
@@ -2159,7 +2171,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.