# HG changeset patch # User Pierre-Yves David # Date 2014-11-01 22:58:30 # Node ID 7361d8244efbd789fd199c7fd3fe831f1dd33d24 # Parent 8b4a8a9176e2f596a0c90bd8366c4584e61d9832 addset: fix `first` and `last` on sorted addset (issue4426) The lazy sorting were not enforced on addset. This was made visible through MQ. diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -2642,14 +2642,15 @@ class addset(abstractsmartset): self._ascending = not self._ascending def first(self): - if self: - return self._list.first() + for x in self: + return x return None def last(self): - if self: - return self._list.last() - return None + self.reverse() + val = self.first() + self.reverse() + return val class generatorset(abstractsmartset): """Wrap a generator for lazy iteration diff --git a/tests/test-mq.t b/tests/test-mq.t --- a/tests/test-mq.t +++ b/tests/test-mq.t @@ -1581,3 +1581,19 @@ Test that secret mq patch does not break tip [0-9a-f]{40} (re) $ cd .. + +Test interraction with revset (issue4426) + + $ hg init issue4426 + $ cd issue4426 + + $ echo a > a + $ hg ci -Am a + adding a + $ echo a >> a + $ hg ci -m a + $ echo a >> a + $ hg ci -m a + $ hg qimport -r 0:: + + $ cd ..