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

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 11, 2014, 12:49 a.m.
Message ID <ecb4171110b4f2a9df16.1392079791@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3561/
State Accepted
Commit f5b560c60bcdda25d0600cee1e9c3aa7ba139c5a
Headers show

Comments

Lucas Moscovicz - Feb. 11, 2014, 12:49 a.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1391725777 28800
#      Thu Feb 06 14:29:37 2014 -0800
# Node ID ecb4171110b4f2a9df166ec4a3087ded6577f857
# Parent  969baade3f73a6c26172f0c4337d92abd70fd106
revset: added operations to duck type baseset

Added more operations which are not lazy but only used so far to duck type
baseset.

Their implementations will be changed in future patches.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2099,5 +2099,26 @@ 
         l = baseset([r for r in self])
         return l + baseset(x)
 
+    def __len__(self):
+        # Basic implementation to be changed in future patches.
+        l = baseset([r for r in self])
+        return len(l)
+
+    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.
+        self._subset = baseset(self._subset)
+        self._subset.sort(reverse=reverse)
+
+    def reverse(self):
+        self._subset.reverse()
+
+    def set(self):
+        return set([r for r in self])
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()