Patchwork [3,of,3] revset: added operations to spanset to duck type baseset

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 12, 2014, 9:54 p.m.
Message ID <959d8a69a22ef664626a.1392242091@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3621/
State Accepted
Commit 0f1ef9e9e904c18f1ac96aef3a0e0d3aa5f1190c
Headers show

Comments

Lucas Moscovicz - Feb. 12, 2014, 9:54 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1391730985 28800
#      Thu Feb 06 15:56:25 2014 -0800
# Node ID 959d8a69a22ef664626abd997143f58babbdbedf
# Parent  fd9f5172db9aef525229b9acebb1e892c280ed6e
revset: added operations to spanset to duck type baseset

Added more operations which are not lazy but only used so far to duck type
baseset.
Matt Mackall - Feb. 12, 2014, 11:41 p.m.
On Wed, 2014-02-12 at 13:54 -0800, Lucas Moscovicz wrote:
> # HG changeset patch
> # User Lucas Moscovicz <lmoscovicz@fb.com>
> # Date 1391730985 28800
> #      Thu Feb 06 15:56:25 2014 -0800
> # Node ID 959d8a69a22ef664626abd997143f58babbdbedf
> # Parent  fd9f5172db9aef525229b9acebb1e892c280ed6e
> revset: added operations to spanset to duck type baseset

These are queued for default, thanks.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2158,5 +2158,27 @@ 
         l = baseset(self)
         return l + baseset(x)
 
+    def __len__(self):
+        return abs(self._end - self._start)
+
+    def __getitem__(self, x):
+        # Basic implementation to be changed in future patches.
+        l = baseset([r for r in self])
+        return l[x]
+
+    def sort(self, reverse=False):
+        # Basic implementation to be changed in future patches.
+        if reverse:
+            self.reverse()
+
+    def reverse(self):
+        if self._start <= self._end:
+            self._start, self._end = self._end - 1, self._start - 1
+        else:
+            self._start, self._end = self._end + 1, self._start + 1
+
+    def set(self):
+        return self
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()