Patchwork [2,of,2,V2] revset: properly parse "descend" argument of followlines()

login
register
mail settings
Submitter Denis Laxalde
Date April 15, 2017, 9:41 a.m.
Message ID <12f163bb4258cac6be9f.1492249312@marimba>
Download mbox | patch
Permalink /patch/20211/
State Accepted
Headers show

Comments

Denis Laxalde - April 15, 2017, 9:41 a.m.
# HG changeset patch
# User Denis Laxalde <denis@laxalde.org>
# Date 1492248582 -7200
#      Sat Apr 15 11:29:42 2017 +0200
# Node ID 12f163bb4258cac6be9f330d5d37c9191bed70e1
# Parent  b7086dbbff268161576bd62a374eec531bdabd7d
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.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -32,6 +32,7 @@  from . import (
 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 @@  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 = getboolean(args['descend'],
+                             _("'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