Patchwork [2,of,4] revset: port parsing rule of old-style ranges from scmutil.revrange()

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 4, 2015, 3:10 p.m.
Message ID <fb330f1901e39f450b5a.1438701028@mimosa>
Download mbox | patch
Permalink /patch/10101/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 4, 2015, 3:10 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1437229817 -32400
#      Sat Jul 18 23:30:17 2015 +0900
# Node ID fb330f1901e39f450b5aec93e590df1a247c2bfc
# Parent  d31439b19ed278f05b0c1e113fc9b48bb1627f7e
revset: port parsing rule of old-style ranges from scmutil.revrange()

The old-style parser will be removed soon.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -178,6 +178,21 @@  def tokenize(program, lookup=None, symin
     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]
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -201,13 +201,49 @@  names that should work without quoting
 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