[PATCH 2 of 3] revset: port limit() to support keyword arguments

Yuya Nishihara yuya at tcha.org
Tue Oct 13 10:57:25 CDT 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1444637962 -32400
#      Mon Oct 12 17:19:22 2015 +0900
# Node ID 5da62cb1c7370d0da4d0e28aaa7a2e423cd43cf6
# Parent  bbddf707ae6cb58065249f14bc8e0fcf2c8e004e
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):


More information about the Mercurial-devel mailing list