revset: parse variable-length arguments of followlines() by getargsdict()
authorYuya Nishihara <yuya@tcha.org>
Mon, 09 Jan 2017 16:02:56 +0900
changeset 30754 26209cb7184e
parent 30753 c3a3896a9fa8
child 30755 0fbb3a5c188e
revset: parse variable-length arguments of followlines() by getargsdict()
mercurial/revset.py
tests/test-annotate.t
--- a/mercurial/revset.py	Mon Jan 09 15:25:52 2017 +0900
+++ b/mercurial/revset.py	Mon Jan 09 16:02:56 2017 +0900
@@ -1078,19 +1078,19 @@
     """
     from . import context  # avoid circular import issues
 
-    args = getargs(x, 3, 4, _("followlines takes at least three arguments"))
+    args = getargsdict(x, 'followlines', 'file *lines rev')
+    if len(args['lines']) != 2:
+        raise error.ParseError(_("followlines takes at least three arguments"))
 
     rev = '.'
-    if len(args) == 4:
-        revarg = getargsdict(args[3], 'followlines', 'rev')
-        if 'rev' in revarg:
-            revs = getset(repo, fullreposet(repo), revarg['rev'])
-            if len(revs) != 1:
-                raise error.ParseError(
-                    _("followlines expects exactly one revision"))
-            rev = revs.last()
-
-    pat = getstring(args[0], _("followlines requires a pattern"))
+    if 'rev' in args:
+        revs = getset(repo, fullreposet(repo), args['rev'])
+        if len(revs) != 1:
+            raise error.ParseError(
+                _("followlines expects exactly one revision"))
+        rev = revs.last()
+
+    pat = getstring(args['file'], _("followlines requires a pattern"))
     if not matchmod.patkind(pat):
         fname = pathutil.canonpath(repo.root, repo.getcwd(), pat)
     else:
@@ -1101,7 +1101,7 @@
         fname = files[0]
 
     try:
-        fromline, toline = [int(getsymbol(a)) for a in args[1:3]]
+        fromline, toline = [int(getsymbol(a)) for a in args['lines']]
     except ValueError:
         raise error.ParseError(_("line range bounds must be integers"))
     if toline - fromline < 0:
--- a/tests/test-annotate.t	Mon Jan 09 15:25:52 2017 +0900
+++ b/tests/test-annotate.t	Mon Jan 09 16:02:56 2017 +0900
@@ -582,6 +582,15 @@
   $ hg up 23 --quiet
 
 check error cases
+  $ hg log -r 'followlines()'
+  hg: parse error: followlines takes at least 1 positional arguments
+  [255]
+  $ hg log -r 'followlines(baz)'
+  hg: parse error: followlines takes at least three arguments
+  [255]
+  $ hg log -r 'followlines(baz, 1)'
+  hg: parse error: followlines takes at least three arguments
+  [255]
   $ hg log -r 'followlines(baz, 1, 2, rev=desc("b"))'
   hg: parse error: followlines expects exactly one revision
   [255]