changeset 20780:403f1f73d30f

revset: try to handle hyphenated symbols if lookup callback is available Formerly an expression like "2.4-rc::" was tokenized as 2.4|-|rc|::. This allows dashes in symbols iff the whole symbol-like string can be looked up. Otherwise, it's tokenized as a series of symbols and operators. No attempt is made to accept dashed symbols inside larger symbol-like string, for instance foo-bar or bar-baz inside foo-bar-baz.
author Matt Mackall <mpm@selenic.com>
date Tue, 18 Mar 2014 17:54:42 -0500
parents ffc2295c6b80
children 8ecfa225bd16
files mercurial/revset.py
diffstat 1 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Tue Mar 18 17:19:44 2014 -0500
+++ b/mercurial/revset.py	Tue Mar 18 17:54:42 2014 -0500
@@ -178,7 +178,7 @@
             pos += 1
             while pos < l: # find end of symbol
                 d = program[pos]
-                if not (d.isalnum() or d in "._/@" or ord(d) > 127):
+                if not (d.isalnum() or d in "-._/@" or ord(d) > 127):
                     break
                 if d == '.' and program[pos - 1] == '.': # special case for ..
                     pos -= 1
@@ -187,6 +187,22 @@
             sym = program[s:pos]
             if sym in keywords: # operator keywords
                 yield (sym, None, s)
+            elif '-' in sym:
+                # some jerk gave us foo-bar-baz, try to check if it's a symbol
+                if lookup and lookup(sym):
+                    # looks like a real symbol
+                    yield ('symbol', sym, s)
+                else:
+                    # looks like an expression
+                    parts = sym.split('-')
+                    for p in parts[:-1]:
+                        if p: # possible consecutive -
+                            yield ('symbol', p, s)
+                        s += len(p)
+                        yield ('-', None, pos)
+                        s += 1
+                    if parts[-1]: # possible trailing -
+                        yield ('symbol', parts[-1], s)
             else:
                 yield ('symbol', sym, s)
             pos -= 1