[PATCH 2 of 3] revset: allow to parse single integer as a range

Yuya Nishihara yuya at tcha.org
Thu Jan 31 09:19:19 EST 2019


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1548563325 -32400
#      Sun Jan 27 13:28:45 2019 +0900
# Node ID d5978ebfee5ac4ec9694c8d1a2df37c7e1555bd3
# Parent  5e5dda247ee2ba8407bc4932118a944c1959b1f9
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.

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, err, deffirst=_notset
     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, err)
+        return n, n
     a, b = getrange(x, err)
     return getinteger(a, err, deffirst), getinteger(b, err, 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,9 +826,6 @@ 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 an integer line range
-  [255]
   $ hg log -r 'followlines(baz, 1:2, startrev=desc("b"))'
   hg: parse error: followlines expects exactly one revision
   [255]


More information about the Mercurial-devel mailing list