Show More
@@ -1169,18 +1169,7 b' def limit(repo, subset, x, order):' | |||
|
1169 | 1169 | if ofs < 0: |
|
1170 | 1170 | raise error.ParseError(_("negative offset")) |
|
1171 | 1171 | os = getset(repo, fullreposet(repo), args['set']) |
|
1172 | result = [] | |
|
1173 | it = iter(os) | |
|
1174 | for x in xrange(ofs): | |
|
1175 | y = next(it, None) | |
|
1176 | if y is None: | |
|
1177 | break | |
|
1178 | for x in xrange(lim): | |
|
1179 | y = next(it, None) | |
|
1180 | if y is None: | |
|
1181 | break | |
|
1182 | result.append(y) | |
|
1183 | ls = baseset(result, datarepr=('<limit n=%d, offset=%d, %r>', lim, ofs, os)) | |
|
1172 | ls = os.slice(ofs, ofs + lim) | |
|
1184 | 1173 | if order == followorder and lim > 1: |
|
1185 | 1174 | return subset & ls |
|
1186 | 1175 | return ls & subset |
@@ -1199,14 +1188,7 b' def last(repo, subset, x, order):' | |||
|
1199 | 1188 | raise error.ParseError(_("negative number to select")) |
|
1200 | 1189 | os = getset(repo, fullreposet(repo), l[0]) |
|
1201 | 1190 | os.reverse() |
|
1202 | result = [] | |
|
1203 | it = iter(os) | |
|
1204 | for x in xrange(lim): | |
|
1205 | y = next(it, None) | |
|
1206 | if y is None: | |
|
1207 | break | |
|
1208 | result.append(y) | |
|
1209 | ls = baseset(result, datarepr=('<last n=%d, %r>', lim, os)) | |
|
1191 | ls = os.slice(0, lim) | |
|
1210 | 1192 | if order == followorder and lim > 1: |
|
1211 | 1193 | return subset & ls |
|
1212 | 1194 | ls.reverse() |
@@ -8,6 +8,7 b'' | |||
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | from . import ( |
|
11 | error, | |
|
11 | 12 | util, |
|
12 | 13 | ) |
|
13 | 14 | |
@@ -155,6 +156,28 b' class abstractsmartset(object):' | |||
|
155 | 156 | condition = util.cachefunc(condition) |
|
156 | 157 | return filteredset(self, condition, condrepr) |
|
157 | 158 | |
|
159 | def slice(self, start, stop): | |
|
160 | """Return new smartset that contains selected elements from this set""" | |
|
161 | if start < 0 or stop < 0: | |
|
162 | raise error.ProgrammingError('negative index not allowed') | |
|
163 | return self._slice(start, stop) | |
|
164 | ||
|
165 | def _slice(self, start, stop): | |
|
166 | # sub classes may override this. start and stop must not be negative, | |
|
167 | # but start > stop is allowed, which should be an empty set. | |
|
168 | ys = [] | |
|
169 | it = iter(self) | |
|
170 | for x in xrange(start): | |
|
171 | y = next(it, None) | |
|
172 | if y is None: | |
|
173 | break | |
|
174 | for x in xrange(stop - start): | |
|
175 | y = next(it, None) | |
|
176 | if y is None: | |
|
177 | break | |
|
178 | ys.append(y) | |
|
179 | return baseset(ys, datarepr=('slice=%d:%d %r', start, stop, self)) | |
|
180 | ||
|
158 | 181 | class baseset(abstractsmartset): |
|
159 | 182 | """Basic data structure that represents a revset and contains the basic |
|
160 | 183 | operation that it should be able to perform. |
@@ -1016,14 +1016,34 b' Test first (=limit) and last' | |||
|
1016 | 1016 | 8 |
|
1017 | 1017 | 9 |
|
1018 | 1018 | |
|
1019 | Test smartset.slice() by first/last() | |
|
1020 | ||
|
1021 | (using unoptimized set, filteredset as example) | |
|
1022 | ||
|
1023 | $ hg debugrevspec --no-show-revs -s '0:7 & branch("re:")' | |
|
1024 | * set: | |
|
1025 | <filteredset | |
|
1026 | <spanset+ 0:8>, | |
|
1027 | <branch 're:'>> | |
|
1028 | $ log 'limit(0:7 & branch("re:"), 3, 4)' | |
|
1029 | 4 | |
|
1030 | 5 | |
|
1031 | 6 | |
|
1032 | $ log 'limit(7:0 & branch("re:"), 3, 4)' | |
|
1033 | 3 | |
|
1034 | 2 | |
|
1035 | 1 | |
|
1036 | $ log 'last(0:7 & branch("re:"), 2)' | |
|
1037 | 6 | |
|
1038 | 7 | |
|
1039 | ||
|
1019 | 1040 | Test order of first/last revisions |
|
1020 | 1041 | |
|
1021 | 1042 | $ hg debugrevspec -s 'first(4:0, 3) & 3:' |
|
1022 | 1043 | * set: |
|
1023 | 1044 | <filteredset |
|
1024 | <baseset | |
|
1025 | <limit n=3, offset=0, | |
|
1026 | <spanset- 0:5>>>, | |
|
1045 | <baseset slice=0:3 | |
|
1046 | <spanset- 0:5>>, | |
|
1027 | 1047 | <spanset+ 3:10>> |
|
1028 | 1048 | 4 |
|
1029 | 1049 | 3 |
@@ -1032,18 +1052,16 b' Test order of first/last revisions' | |||
|
1032 | 1052 | * set: |
|
1033 | 1053 | <filteredset |
|
1034 | 1054 | <spanset+ 3:10>, |
|
1035 | <baseset | |
|
1036 | <limit n=3, offset=0, | |
|
1037 | <spanset- 0:5>>>> | |
|
1055 | <baseset slice=0:3 | |
|
1056 | <spanset- 0:5>>> | |
|
1038 | 1057 | 3 |
|
1039 | 1058 | 4 |
|
1040 | 1059 | |
|
1041 | 1060 | $ hg debugrevspec -s 'last(4:0, 3) & :1' |
|
1042 | 1061 | * set: |
|
1043 | 1062 | <filteredset |
|
1044 | <baseset | |
|
1045 |
< |
|
|
1046 | <spanset+ 0:5>>>, | |
|
1063 | <baseset slice=0:3 | |
|
1064 | <spanset+ 0:5>>, | |
|
1047 | 1065 | <spanset+ 0:2>> |
|
1048 | 1066 | 1 |
|
1049 | 1067 | 0 |
@@ -1052,9 +1070,8 b' Test order of first/last revisions' | |||
|
1052 | 1070 | * set: |
|
1053 | 1071 | <filteredset |
|
1054 | 1072 | <spanset+ 0:2>, |
|
1055 | <baseset | |
|
1056 | <last n=3, | |
|
1057 | <spanset+ 0:5>>>> | |
|
1073 | <baseset slice=0:3 | |
|
1074 | <spanset+ 0:5>>> | |
|
1058 | 1075 | 0 |
|
1059 | 1076 | 1 |
|
1060 | 1077 | |
@@ -1950,9 +1967,8 b' ordering defined by it.' | |||
|
1950 | 1967 | define) |
|
1951 | 1968 | * set: |
|
1952 | 1969 | <filteredset |
|
1953 | <baseset | |
|
1954 | <limit n=1, offset=0, | |
|
1955 | <baseset [1, 0, 2]>>>, | |
|
1970 | <baseset slice=0:1 | |
|
1971 | <baseset [1, 0, 2]>>, | |
|
1956 | 1972 | <spanset- 0:3>> |
|
1957 | 1973 | 1 |
|
1958 | 1974 | |
@@ -1987,9 +2003,8 b' ordering defined by it.' | |||
|
1987 | 2003 | <filteredset |
|
1988 | 2004 | <spanset- 0:3>, |
|
1989 | 2005 | <not |
|
1990 | <baseset | |
|
1991 |
< |
|
|
1992 | <baseset [1, 2, 0]>>>>> | |
|
2006 | <baseset slice=0:1 | |
|
2007 | <baseset [1, 2, 0]>>>> | |
|
1993 | 2008 | 2 |
|
1994 | 2009 | 0 |
|
1995 | 2010 | |
@@ -3613,9 +3628,8 b' issue2549 - correct optimizations' | |||
|
3613 | 3628 | ('symbol', '2'))) |
|
3614 | 3629 | * set: |
|
3615 | 3630 | <filteredset |
|
3616 | <baseset | |
|
3617 | <limit n=2, offset=0, | |
|
3618 | <baseset [1, 2, 3]>>>, | |
|
3631 | <baseset slice=0:2 | |
|
3632 | <baseset [1, 2, 3]>>, | |
|
3619 | 3633 | <not |
|
3620 | 3634 | <baseset [2]>>> |
|
3621 | 3635 | 1 |
@@ -3669,9 +3683,8 b' issue2549 - correct optimizations' | |||
|
3669 | 3683 | ('symbol', '2'))) |
|
3670 | 3684 | * set: |
|
3671 | 3685 | <filteredset |
|
3672 | <baseset | |
|
3673 |
< |
|
|
3674 | <baseset [2, 1]>>>, | |
|
3686 | <baseset slice=0:1 | |
|
3687 | <baseset [2, 1]>>, | |
|
3675 | 3688 | <not |
|
3676 | 3689 | <baseset [2]>>> |
|
3677 | 3690 |
General Comments 0
You need to be logged in to leave comments.
Login now