Mercurial > hg
changeset 32799:b36ec65ea583
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].
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 10 Jun 2017 18:35:11 +0900 |
parents | 573b792872c1 |
children | 3e6f9bff7e3f |
files | mercurial/revset.py tests/test-revset.t |
diffstat | 2 files changed, 12 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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