revset: allow to parse single integer as a range
Even though this wouldn't be any useful in followlines(), it helps to unify
range processing.
--- a/mercurial/revset.py Sun Jan 27 13:18:53 2019 +0900
+++ b/mercurial/revset.py Sun Jan 27 13:28:45 2019 +0900
@@ -1071,7 +1071,7 @@
fromline, toline = util.processlinerange(
*getintrange(args['lines'][0],
# i18n: "followlines" is a keyword
- _("followlines expects a line range"),
+ _("followlines expects a line number or a range"),
_("line range bounds must be integers")))
fctx = repo[rev].filectx(fname)
--- a/mercurial/revsetlang.py Sun Jan 27 13:18:53 2019 +0900
+++ b/mercurial/revsetlang.py Sun Jan 27 13:28:45 2019 +0900
@@ -246,6 +246,9 @@
If any of the sides omitted, and if no default provided, ParseError will
be raised.
"""
+ if x and (x[0] == 'string' or x[0] == 'symbol'):
+ n = getinteger(x, err1)
+ return n, n
a, b = getrange(x, err1)
return getinteger(a, err2, deffirst), getinteger(b, err2, deflast)
--- a/tests/test-annotate.t Sun Jan 27 13:18:53 2019 +0900
+++ b/tests/test-annotate.t Sun Jan 27 13:28:45 2019 +0900
@@ -809,6 +809,15 @@
|\
~ ~
+An integer as a line range, which is parsed as '1:1'
+
+ $ hg log -r 'followlines(baz, 1)'
+ changeset: 22:2174d0bf352a
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: added two lines with 0
+
+
check error cases
$ hg up 24 --quiet
$ hg log -r 'followlines()'
@@ -817,8 +826,8 @@
$ hg log -r 'followlines(baz)'
hg: parse error: followlines requires a line range
[255]
- $ hg log -r 'followlines(baz, 1)'
- hg: parse error: followlines expects a line range
+ $ hg log -r 'followlines(baz, x)'
+ hg: parse error: followlines expects a line number or a range
[255]
$ hg log -r 'followlines(baz, 1:2, startrev=desc("b"))'
hg: parse error: followlines expects exactly one revision