mercurial/revset.py
changeset 22813 5a96df266b2b
parent 22812 fcd12b310148
child 22817 e4eb4bfc3616
--- a/mercurial/revset.py	Mon Oct 06 14:42:00 2014 -0700
+++ b/mercurial/revset.py	Tue Oct 07 00:18:08 2014 -0700
@@ -2482,6 +2482,25 @@
     def isdescending(self):
         return self._ascending is not None and not self._ascending
 
+    def first(self):
+        for x in self:
+            return x
+        return None
+
+    def last(self):
+        it = None
+        if self._ascending is not None:
+            if self._ascending:
+                it = self.fastdesc
+            else:
+                it = self.fastasc
+        if it is None:
+            # slowly consume everything. This needs improvement
+            it = lambda: reversed(list(self))
+        for x in it():
+            return x
+        return None
+
 class addset(abstractsmartset):
     """Represent the addition of two sets