# HG changeset patch # User Pierre-Yves David # Date 1412625156 25200 # Node ID c1fd827e1ae0614a02fd8a7e34ce0b7f9bf32b46 # Parent 7f97cb12782f8f9c56317d033bb64de1e663735c generatorset: implement first and last methods diff -r 7f97cb12782f -r c1fd827e1ae0 mercurial/revset.py --- a/mercurial/revset.py Mon Oct 06 11:57:59 2014 -0700 +++ b/mercurial/revset.py Mon Oct 06 12:52:36 2014 -0700 @@ -2767,6 +2767,34 @@ def isdescending(self): return not self._ascending + def first(self): + if self._ascending: + it = self.fastasc + else: + it = self.fastdesc + if it is None: + # we need to consume all and try again + for x in self._consumegen(): + pass + return self.first() + if self: + return it.next() + return None + + def last(self): + if self._ascending: + it = self.fastdesc + else: + it = self.fastasc + if it is None: + # we need to consume all and try again + for x in self._consumegen(): + pass + return self.first() + if self: + return it.next() + return None + def spanset(repo, start=None, end=None): """factory function to dispatch between fullreposet and actual spanset