[PATCH] smartset: fix generatorset.last() to not return the first element (issue5609)
Yuya Nishihara
yuya at tcha.org
Tue Jun 27 15:14:53 UTC 2017
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1498575022 -32400
# Tue Jun 27 23:50:22 2017 +0900
# Node ID f4f9cdc4a63d2e158396c58015b029b47aeed301
# Parent e88fdec9cb9ebc58e217f7e591ea15afe928c1c8
smartset: fix generatorset.last() to not return the first element (issue5609)
diff --git a/mercurial/smartset.py b/mercurial/smartset.py
--- a/mercurial/smartset.py
+++ b/mercurial/smartset.py
@@ -766,6 +766,11 @@ class generatorset(abstractsmartset):
be iterated more than once.
When asked for membership it generates values until either it finds the
requested one or has gone through all the elements in the generator
+
+ >>> xs = generatorset([0, 1, 4], iterasc=True)
+ >>> assert xs.last() == xs.last()
+ >>> xs.last() # cached
+ 4
"""
def __init__(self, gen, iterasc=None):
"""
@@ -937,7 +942,7 @@ class generatorset(abstractsmartset):
# we need to consume all and try again
for x in self._consumegen():
pass
- return self.first()
+ return self.last()
return next(it(), None)
def __repr__(self):
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1337,6 +1337,16 @@ Test order of first/last revisions
0
1
+Test scmutil.revsingle() should return the last revision
+
+ $ hg debugrevspec -s 'last(0::)'
+ * set:
+ <baseset slice=0:1
+ <generatorset->>
+ 9
+ $ hg identify -r '0::' --num
+ 9
+
Test matching
$ log 'matching(6)'
More information about the Mercurial-devel
mailing list