Mercurial > public > mercurial-scm > hg
comparison mercurial/revset.py @ 26637:179764469754
revset: port limit() to support keyword arguments
The next patch will introduce the third 'offset' argument. This allows us
to specify 'offset' without 'n' argument.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 12 Oct 2015 17:19:22 +0900 |
parents | ff6baf32b3ba |
children | 7afaf2566e25 |
comparison
equal
deleted
inserted
replaced
26636:ff6baf32b3ba | 26637:179764469754 |
---|---|
1285 | 1285 |
1286 def limit(repo, subset, x): | 1286 def limit(repo, subset, x): |
1287 """``limit(set, [n])`` | 1287 """``limit(set, [n])`` |
1288 First n members of set, defaulting to 1. | 1288 First n members of set, defaulting to 1. |
1289 """ | 1289 """ |
1290 # i18n: "limit" is a keyword | 1290 args = getargsdict(x, 'limit', 'set n') |
1291 l = getargs(x, 1, 2, _("limit requires one or two arguments")) | 1291 if 'set' not in args: |
1292 # i18n: "limit" is a keyword | |
1293 raise error.ParseError(_("limit requires one or two arguments")) | |
1292 try: | 1294 try: |
1293 lim = 1 | 1295 lim = 1 |
1294 if len(l) == 2: | 1296 if 'n' in args: |
1295 # i18n: "limit" is a keyword | 1297 # i18n: "limit" is a keyword |
1296 lim = int(getstring(l[1], _("limit requires a number"))) | 1298 lim = int(getstring(args['n'], _("limit requires a number"))) |
1297 except (TypeError, ValueError): | 1299 except (TypeError, ValueError): |
1298 # i18n: "limit" is a keyword | 1300 # i18n: "limit" is a keyword |
1299 raise error.ParseError(_("limit expects a number")) | 1301 raise error.ParseError(_("limit expects a number")) |
1300 os = getset(repo, fullreposet(repo), l[0]) | 1302 os = getset(repo, fullreposet(repo), args['set']) |
1301 result = [] | 1303 result = [] |
1302 it = iter(os) | 1304 it = iter(os) |
1303 for x in xrange(lim): | 1305 for x in xrange(lim): |
1304 y = next(it, None) | 1306 y = next(it, None) |
1305 if y is None: | 1307 if y is None: |