spanset: implement `first` and `last` methods
authorPierre-Yves David <pierre-yves.david@fb.com>
Mon, 06 Oct 2014 11:54:53 -0700
changeset 22809 88dad916c008
parent 22808 228b0aafb1ce
child 22810 7f97cb12782f
spanset: implement `first` and `last` methods
mercurial/revset.py
--- 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