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

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 1, 2019, 1:35 p.m.
Message ID <28b6a15f5bb2fcfa8095.1549028122@mimosa>
Download mbox | patch
Permalink /patch/38292/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 1, 2019, 1:35 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1548563325 -32400
#      Sun Jan 27 13:28:45 2019 +0900
# Node ID 28b6a15f5bb2fcfa809532e27cf9008aa4f93d0d
# 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.

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,6 +246,9 @@  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)
 
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