Patchwork revset: properly parse "descend" argument of followlines()

login
register
mail settings
Submitter Denis Laxalde
Date April 14, 2017, 5:22 p.m.
Message ID <6b9fbf9d5196681d213d.1492190550@marimba>
Download mbox | patch
Permalink /patch/20208/
State Superseded
Headers show

Comments

Denis Laxalde - April 14, 2017, 5:22 p.m.
# HG changeset patch
# User Denis Laxalde <denis@laxalde.org>
# Date 1492188762 -7200
#      Fri Apr 14 18:52:42 2017 +0200
# Node ID 6b9fbf9d5196681d213d2a61ac2bed79c18e3a4c
# Parent  4c2c30bc38b4f84ce8f215146bbf158e299065b3
revset: properly parse "descend" argument of followlines()

We get "descend" symbol out of args dict (prior extraction by getargsdict
already checked that it is a symbol) and then parse it as a Boolean.

In tests, check for error cases and vary Boolean values here and there.
Yuya Nishihara - April 15, 2017, 7:52 a.m.
On Fri, 14 Apr 2017 19:22:30 +0200, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis@laxalde.org>
> # Date 1492188762 -7200
> #      Fri Apr 14 18:52:42 2017 +0200
> # Node ID 6b9fbf9d5196681d213d2a61ac2bed79c18e3a4c
> # Parent  4c2c30bc38b4f84ce8f215146bbf158e299065b3
> revset: properly parse "descend" argument of followlines()

This looks good. A few nits follow.

> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -944,7 +944,12 @@ def followlines(repo, subset, x):
>      fromline, toline = util.processlinerange(fromline, toline)
>  
>      fctx = repo[rev].filectx(fname)
> -    if args.get('descend', False):
> +    descend = False
> +    if 'descend' in args:
> +        descend = util.parsebool(getsymbol(args['descend']))

Let's add revsetlang.getboolean().

> +        if descend is None:
> +            raise error.ParseError(_("'descend' argument must be a Boolean"))

s/Boolean/boolean/ for consistency with the other error messages.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -944,7 +944,12 @@  def followlines(repo, subset, x):
     fromline, toline = util.processlinerange(fromline, toline)
 
     fctx = repo[rev].filectx(fname)
-    if args.get('descend', False):
+    descend = False
+    if 'descend' in args:
+        descend = util.parsebool(getsymbol(args['descend']))
+        if descend is None:
+            raise error.ParseError(_("'descend' argument must be a Boolean"))
+    if descend:
         rs = generatorset(
             (c.rev() for c, _linerange
              in context.blockdescendants(fctx, fromline, toline)),
diff --git a/tests/test-annotate.t b/tests/test-annotate.t
--- a/tests/test-annotate.t
+++ b/tests/test-annotate.t
@@ -508,7 +508,7 @@  when they should.
   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)'
   20: baz:4
   $ echo 6 >> baz
   $ hg ci -m 'added line 8'
@@ -516,12 +516,12 @@  when they should.
   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)'
   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
@@ -529,7 +529,7 @@  when they should.
   $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, startrev=19, descend=True)'
   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
@@ -655,6 +655,12 @@  check error cases
   $ 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