Mercurial > public > mercurial-scm > hg-stable
diff mercurial/revsetlang.py @ 37760:29eb4cafeeb8
revset: skip legacy lookup for revspec wrapped in 'revset(...)'
Currently, multiple labels can take forms that can be confused with revset
(eg: "rev(0)" is a valid tag). Since we look up for tags before evaluating
revset, this means a tag can shadow a valid revset at any time.
We now enforce the strict revset parsing when wrapped with 'revset(...)'. For
now, This only work on a whole revspec (but can be used within the revset
without effect). This might change in the future if we improve the
implementation.
The feature is undocumented for now, keeping it in the experimental namespace.
In case a better approach to achieve the same goal is found.
The syntax looks like a revset but is not implemented as such for now. Since the
goal is to avoid some preprocessing that happens before revset parsing, we
cannot simply implement it as a revset predicate.
There was other approaches discussed over the mailing-list but they were less
convincing.
Having a configuration flag to disable legacy lookup have been considered but
discarded. There are too many common uses of ambiguous identifier (eg: '+',
'-' or '..') to have the legacy lookup mechanism turned off.
In addition, the approach can control the parsing of each revset, making
it more flexible. For example, a revset used as the value of an existing
configuration option (eg: pushrev) could enforce its resolution as a revset (by
using the prefix) while user inputs would still use the legacy lookup.
In addition of offering a way to unambiguously input a revset, this prefix
allow skipping the name lookup providing a significant speedup in some case.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Tue, 10 Apr 2018 16:06:52 +0200 |
parents | f0b6fbea00cf |
children | 03d7f885d5f2 |
line wrap: on
line diff
--- a/mercurial/revsetlang.py Thu Mar 01 11:37:16 2018 -0500 +++ b/mercurial/revsetlang.py Tue Apr 10 16:06:52 2018 +0200 @@ -352,6 +352,9 @@ elif op == 'keyvalue': return (op, x[1], _analyze(x[2])) elif op == 'func': + f = getsymbol(x[1]) + if f == 'revset': + return _analyze(x[2]) return (op, x[1], _analyze(x[2])) raise ValueError('invalid operator %r' % op) @@ -482,6 +485,8 @@ ... ParseError: ('invalid token', 4) """ + if lookup and spec.startswith('revset(') and spec.endswith(')'): + lookup = None p = parser.parser(elements) tree, pos = p.parse(tokenize(spec, lookup=lookup, syminitletters=syminitletters))