Patchwork [2,of,3,V2] revset: allow to parse single integer as a range

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 1, 2019, 1:23 p.m.
Message ID <a72c5cfe7b8da68563a1.1549027417@mimosa>
Download mbox | patch
Permalink /patch/38289/
State Superseded
Headers show

Comments

Yuya Nishihara - Feb. 1, 2019, 1:23 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1548563325 -32400
#      Sun Jan 27 13:28:45 2019 +0900
# Node ID a72c5cfe7b8da68563a1fb07d1477a9804d28d74
# Parent  1502f467006b95eb15b3f51ab5dc4c1d5a53a90f
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.
Yuya Nishihara - Feb. 1, 2019, 1:26 p.m.
On Fri, 01 Feb 2019 22:23:37 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1548563325 -32400
> #      Sun Jan 27 13:28:45 2019 +0900
> # Node ID a72c5cfe7b8da68563a1fb07d1477a9804d28d74
> # Parent  1502f467006b95eb15b3f51ab5dc4c1d5a53a90f
> revset: allow to parse single integer as a range

>      a, b = getrange(x, err1)
>      return getinteger(a, err2, deffirst), getinteger(b, err2, deflast)
>  
> +
>  def getargs(x, min, max, err):

Merge error. I'll send V3 soon. Sorry for the noise.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1071,7 +1071,7 @@  def followlines(repo, subset, x):
     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)
diff --git a/mercurial/revsetlang.py b/mercurial/revsetlang.py
--- a/mercurial/revsetlang.py
+++ b/mercurial/revsetlang.py
@@ -246,9 +246,13 @@  def getintrange(x, err1, err2, deffirst=
     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)
 
+
 def getargs(x, min, max, err):
     l = getlist(x)
     if len(l) < min or (max >= 0 and len(l) > max):
diff --git a/tests/test-annotate.t b/tests/test-annotate.t
--- a/tests/test-annotate.t
+++ b/tests/test-annotate.t
@@ -809,6 +809,15 @@  track of possible further descendants in
   |\
   ~ ~
 
+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 @@  check error cases
   $ 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