revset: reject negative number to select first/last n members
authorYuya Nishihara <yuya@tcha.org>
Sat, 10 Jun 2017 18:35:11 +0900
changeset 32799 b36ec65ea583
parent 32798 573b792872c1
child 32800 3e6f9bff7e3f
revset: reject negative number to select first/last n members Negative 'lim' doesn't make sense here, and it makes things complicated when using list[:lim].
mercurial/revset.py
tests/test-revset.t
--- a/mercurial/revset.py	Sat Jun 10 18:04:56 2017 +0900
+++ b/mercurial/revset.py	Sat Jun 10 18:35:11 2017 +0900
@@ -1162,6 +1162,8 @@
         raise error.ParseError(_("limit requires one to three arguments"))
     # i18n: "limit" is a keyword
     lim = getinteger(args.get('n'), _("limit expects a number"), default=1)
+    if lim < 0:
+        raise error.ParseError(_("negative number to select"))
     # i18n: "limit" is a keyword
     ofs = getinteger(args.get('offset'), _("limit expects a number"), default=0)
     if ofs < 0:
@@ -1192,6 +1194,8 @@
     if len(l) == 2:
         # i18n: "last" is a keyword
         lim = getinteger(l[1], _("last expects a number"))
+    if lim < 0:
+        raise error.ParseError(_("negative number to select"))
     os = getset(repo, fullreposet(repo), l[0])
     os.reverse()
     result = []
--- a/tests/test-revset.t	Sat Jun 10 18:04:56 2017 +0900
+++ b/tests/test-revset.t	Sat Jun 10 18:35:11 2017 +0900
@@ -1001,7 +1001,14 @@
   $ log 'limit(all(), 1, -1)'
   hg: parse error: negative offset
   [255]
-
+  $ log 'limit(all(), -1)'
+  hg: parse error: negative number to select
+  [255]
+  $ log 'limit(all(), 0)'
+
+  $ log 'last(all(), -1)'
+  hg: parse error: negative number to select
+  [255]
   $ log 'last(all(), 0)'
   $ log 'last(all(), 1)'
   9