changeset 22809:88dad916c008

spanset: implement `first` and `last` methods
author Pierre-Yves David <pierre-yves.david@fb.com>
date Mon, 06 Oct 2014 11:54:53 -0700
parents 228b0aafb1ce
children 7f97cb12782f
files mercurial/revset.py
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Mon Oct 06 11:46:53 2014 -0700
+++ b/mercurial/revset.py	Mon Oct 06 11:54:53 2014 -0700
@@ -2862,6 +2862,24 @@
     def isdescending(self):
         return self._start >= self._end
 
+    def first(self):
+        if self._ascending:
+            it = self.fastasc
+        else:
+            it = self.fastdesc
+        for x in it():
+            return x
+        return None
+
+    def last(self):
+        if self._ascending:
+            it = self.fastdesc
+        else:
+            it = self.fastasc
+        for x in it():
+            return x
+        return None
+
 class fullreposet(_spanset):
     """a set containing all revisions in the repo