Show More
@@ -1284,24 +1284,33 def keyword(repo, subset, x): | |||||
1284 | return subset.filter(matches) |
|
1284 | return subset.filter(matches) | |
1285 |
|
1285 | |||
1286 | def limit(repo, subset, x): |
|
1286 | def limit(repo, subset, x): | |
1287 |
"""``limit(set |
|
1287 | """``limit(set[, n[, offset]])`` | |
1288 | First n members of set, defaulting to 1. |
|
1288 | First n members of set, defaulting to 1, starting from offset. | |
1289 | """ |
|
1289 | """ | |
1290 | args = getargsdict(x, 'limit', 'set n') |
|
1290 | args = getargsdict(x, 'limit', 'set n offset') | |
1291 | if 'set' not in args: |
|
1291 | if 'set' not in args: | |
1292 | # i18n: "limit" is a keyword |
|
1292 | # i18n: "limit" is a keyword | |
1293 |
raise error.ParseError(_("limit requires one |
|
1293 | raise error.ParseError(_("limit requires one to three arguments")) | |
1294 | try: |
|
1294 | try: | |
1295 | lim = 1 |
|
1295 | lim, ofs = 1, 0 | |
1296 | if 'n' in args: |
|
1296 | if 'n' in args: | |
1297 | # i18n: "limit" is a keyword |
|
1297 | # i18n: "limit" is a keyword | |
1298 | lim = int(getstring(args['n'], _("limit requires a number"))) |
|
1298 | lim = int(getstring(args['n'], _("limit requires a number"))) | |
|
1299 | if 'offset' in args: | |||
|
1300 | # i18n: "limit" is a keyword | |||
|
1301 | ofs = int(getstring(args['offset'], _("limit requires a number"))) | |||
|
1302 | if ofs < 0: | |||
|
1303 | raise error.ParseError(_("negative offset")) | |||
1299 | except (TypeError, ValueError): |
|
1304 | except (TypeError, ValueError): | |
1300 | # i18n: "limit" is a keyword |
|
1305 | # i18n: "limit" is a keyword | |
1301 | raise error.ParseError(_("limit expects a number")) |
|
1306 | raise error.ParseError(_("limit expects a number")) | |
1302 | os = getset(repo, fullreposet(repo), args['set']) |
|
1307 | os = getset(repo, fullreposet(repo), args['set']) | |
1303 | result = [] |
|
1308 | result = [] | |
1304 | it = iter(os) |
|
1309 | it = iter(os) | |
|
1310 | for x in xrange(ofs): | |||
|
1311 | y = next(it, None) | |||
|
1312 | if y is None: | |||
|
1313 | break | |||
1305 | for x in xrange(lim): |
|
1314 | for x in xrange(lim): | |
1306 | y = next(it, None) |
|
1315 | y = next(it, None) | |
1307 | if y is None: |
|
1316 | if y is None: |
@@ -566,6 +566,16 test ancestors | |||||
566 | $ log 'keyword("test a")' |
|
566 | $ log 'keyword("test a")' | |
567 | $ log 'limit(head(), 1)' |
|
567 | $ log 'limit(head(), 1)' | |
568 | 0 |
|
568 | 0 | |
|
569 | $ log 'limit(author("re:bob|test"), 3, 5)' | |||
|
570 | 5 | |||
|
571 | 6 | |||
|
572 | 7 | |||
|
573 | $ log 'limit(author("re:bob|test"), offset=6)' | |||
|
574 | 6 | |||
|
575 | $ log 'limit(author("re:bob|test"), offset=10)' | |||
|
576 | $ log 'limit(all(), 1, -1)' | |||
|
577 | hg: parse error: negative offset | |||
|
578 | [255] | |||
569 | $ log 'matching(6)' |
|
579 | $ log 'matching(6)' | |
570 | 6 |
|
580 | 6 | |
571 | $ log 'matching(6:7, "phase parents user date branch summary files description substate")' |
|
581 | $ log 'matching(6:7, "phase parents user date branch summary files description substate")' |
General Comments 0
You need to be logged in to leave comments.
Login now