Mercurial > hg-stable
changeset 22829:36e09c25f870
baseset: explicitly track order of the baseset
A baseset starts without an explicit order. But as soon as a sort is requested,
we simply register that the baseset has an order and use the ordered version of
the list to behave accordingly.
We will want to properly record the order at creation time in the future. This
would unlock more optimisation and avoid some sorting.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Fri, 03 Oct 2014 03:29:55 -0500 |
parents | 966860f7a1a8 |
children | 1d1da8abe130 |
files | mercurial/revset.py |
diffstat | 1 files changed, 17 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revset.py Fri Oct 03 03:31:05 2014 -0500 +++ b/mercurial/revset.py Fri Oct 03 03:29:55 2014 -0500 @@ -2372,10 +2372,13 @@ return bool(self._list) def sort(self, reverse=False): - self._list.sort(reverse=reverse) + self._ascending = not bool(reverse) def reverse(self): - self._list.reverse() + if self._ascending is None: + self._list.reverse() + else: + self._ascending = not self._ascending def __len__(self): return len(self._list) @@ -2421,12 +2424,22 @@ def first(self): if self: - return self._list[0] + if self._ascending is None: + return self._list[0] + elif self._ascending: + return self._asclist[0] + else: + return self._asclist[-1] return None def last(self): if self: - return self._list[-1] + if self._ascending is None: + return self._list[-1] + elif self._ascending: + return self._asclist[-1] + else: + return self._asclist[0] return None class filteredset(abstractsmartset):