# HG changeset patch # User Yuya Nishihara # Date 2015-10-12 08:19:22 # Node ID 179764469754850bcc22d2895c3a6cc0cb8db2b9 # Parent ff6baf32b3ba2dddf0609adc621b1a4eaeca08aa 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. diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -1287,17 +1287,19 @@ def limit(repo, subset, x): """``limit(set, [n])`` First n members of set, defaulting to 1. """ - # i18n: "limit" is a keyword - l = getargs(x, 1, 2, _("limit requires one or two arguments")) + args = getargsdict(x, 'limit', 'set n') + if 'set' not in args: + # i18n: "limit" is a keyword + raise error.ParseError(_("limit requires one or two arguments")) try: lim = 1 - if len(l) == 2: + if 'n' in args: # i18n: "limit" is a keyword - lim = int(getstring(l[1], _("limit requires a number"))) + lim = int(getstring(args['n'], _("limit requires a number"))) except (TypeError, ValueError): # i18n: "limit" is a keyword raise error.ParseError(_("limit expects a number")) - os = getset(repo, fullreposet(repo), l[0]) + os = getset(repo, fullreposet(repo), args['set']) result = [] it = iter(os) for x in xrange(lim):