changeset 31998:83527d9f1f13

revset: properly parse "descend" argument of followlines() We parse "descend" symbol as a Boolean using getboolean (prior extraction by getargsdict already checked that it is a symbol). In tests, check for error cases and vary Boolean values here and there.
author Denis Laxalde <denis@laxalde.org>
date Sat, 15 Apr 2017 11:29:42 +0200
parents 11f501f0a213
children aa836f56c3cc
files mercurial/revset.py tests/test-annotate.t
diffstat 2 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Sat Apr 15 11:26:09 2017 +0200
+++ b/mercurial/revset.py	Sat Apr 15 11:29:42 2017 +0200
@@ -32,6 +32,7 @@
 getsymbol = revsetlang.getsymbol
 getstring = revsetlang.getstring
 getinteger = revsetlang.getinteger
+getboolean = revsetlang.getboolean
 getlist = revsetlang.getlist
 getrange = revsetlang.getrange
 getargs = revsetlang.getargs
@@ -944,7 +945,11 @@
     fromline, toline = util.processlinerange(fromline, toline)
 
     fctx = repo[rev].filectx(fname)
-    if args.get('descend', False):
+    descend = False
+    if 'descend' in args:
+        descend = getboolean(args['descend'],
+                             _("'descend' argument must be a boolean"))
+    if descend:
         rs = generatorset(
             (c.rev() for c, _linerange
              in context.blockdescendants(fctx, fromline, toline)),
--- a/tests/test-annotate.t	Sat Apr 15 11:26:09 2017 +0200
+++ b/tests/test-annotate.t	Sat Apr 15 11:29:42 2017 +0200
@@ -509,7 +509,7 @@
   16: baz:0
   19: baz:3
   20: baz:4
-  $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, descend=True, startrev=19)'
+  $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, descend=true, startrev=19)'
   19: baz:3
   20: baz:4
   $ echo 6 >> baz
@@ -518,13 +518,13 @@
   16: baz:0
   19: baz:3
   20: baz:4
-  $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, startrev=19, descend=True)'
+  $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, startrev=19, descend=1)'
   19: baz:3
   20: baz:4
   $ sed 's/3/3+/' baz > baz.new
   $ mv baz.new baz
   $ hg ci -m 'baz:3->3+'
-  $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 5:7)'
+  $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 5:7, descend=0)'
   16: baz:0
   19: baz:3
   20: baz:4
@@ -533,7 +533,7 @@
   19: baz:3
   20: baz:4
   23: baz:3->3+
-  $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 1:2)'
+  $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 1:2, descend=false)'
   21: added two lines with 0
 
 file patterns are okay
@@ -662,6 +662,12 @@
   $ hg log -r 'followlines(baz, 2:40)'
   abort: line range exceeds file size
   [255]
+  $ hg log -r 'followlines(baz, 2:4, startrev=20, descend=[1])'
+  hg: parse error at 43: syntax error in revset 'followlines(baz, 2:4, startrev=20, descend=[1])'
+  [255]
+  $ hg log -r 'followlines(baz, 2:4, startrev=20, descend=a)'
+  hg: parse error: 'descend' argument must be a boolean
+  [255]
 
 Test annotate with whitespace options