revset: port parsing rule of old-style ranges from scmutil.revrange()
authorYuya Nishihara <yuya@tcha.org>
Sat, 18 Jul 2015 23:30:17 +0900
changeset 25902 5214cbdc37e5
parent 25901 0203c50a589f
child 25903 9bbab9decd71
revset: port parsing rule of old-style ranges from scmutil.revrange() The old-style parser will be removed soon.
mercurial/revset.py
tests/test-revset.t
--- a/mercurial/revset.py	Sat Jul 18 23:02:18 2015 +0900
+++ b/mercurial/revset.py	Sat Jul 18 23:30:17 2015 +0900
@@ -178,6 +178,21 @@
     if symletters is None:
         symletters = _symletters
 
+    if program and lookup:
+        # attempt to parse old-style ranges first to deal with
+        # things like old-tag which contain query metacharacters
+        parts = program.split(':', 1)
+        if all(lookup(sym) for sym in parts if sym):
+            if parts[0]:
+                yield ('symbol', parts[0], 0)
+            if len(parts) > 1:
+                s = len(parts[0])
+                yield (':', None, s)
+                if parts[1]:
+                    yield ('symbol', parts[1], s + 1)
+            yield ('end', None, len(program))
+            return
+
     pos, l = 0, len(program)
     while pos < l:
         c = program[pos]
--- a/tests/test-revset.t	Sat Jul 18 23:02:18 2015 +0900
+++ b/tests/test-revset.t	Sat Jul 18 23:30:17 2015 +0900
@@ -201,13 +201,49 @@
 names that should be caught by fallback mechanism
 
   $ try -- '-a-b-c-'
-  (negate
-    ('symbol', 'a-b-c-'))
+  ('symbol', '-a-b-c-')
   * set:
   <baseset [4]>
   4
   $ log -a-b-c-
   4
+  $ try '+a+b+c+'
+  ('symbol', '+a+b+c+')
+  * set:
+  <baseset [3]>
+  3
+  $ try '+a+b+c+:'
+  (rangepost
+    ('symbol', '+a+b+c+'))
+  * set:
+  <spanset+ 3:9>
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+  $ try ':+a+b+c+'
+  (rangepre
+    ('symbol', '+a+b+c+'))
+  * set:
+  <spanset+ 0:3>
+  0
+  1
+  2
+  3
+  $ try -- '-a-b-c-:+a+b+c+'
+  (range
+    ('symbol', '-a-b-c-')
+    ('symbol', '+a+b+c+'))
+  * set:
+  <spanset- 3:4>
+  4
+  3
+  $ log '-a-b-c-:+a+b+c+'
+  4
+  3
 
   $ try -- -a-b-c--a # complains
   (minus