Commit 70b180df authored by Yuya Nishihara's avatar Yuya Nishihara
Browse files

revset: split language services to revsetlang module (API)

New revsetlang module hosts parser, tokenizer, and miscellaneous functions
working on parsed tree. It does not include functions for evaluation such as
getset() and match().

  2288 mercurial/revset.py
   684 mercurial/revsetlang.py
  2972 total

get*() functions are aliased since they are common in revset.py.
parent aea06029919e
......@@ -89,7 +89,7 @@ from mercurial import (
phases,
pycompat,
registrar,
revset,
revsetlang,
scmutil,
smartset,
subrepo,
......@@ -3568,7 +3568,7 @@ revsetpredicate = registrar.revsetpredicate()
def revsetmq(repo, subset, x):
"""Changesets managed by MQ.
"""
revset.getargs(x, 0, 0, _("mq takes no arguments"))
revsetlang.getargs(x, 0, 0, _("mq takes no arguments"))
applied = set([repo[r.node].rev() for r in repo.mq.applied])
return smartset.baseset([r for r in subset if r in applied])
......
......@@ -44,7 +44,7 @@ from . import (
patch,
phases,
pycompat,
revset,
revsetlang,
scmutil,
server,
sshserver,
......@@ -3414,7 +3414,7 @@ def log(ui, repo, *pats, **opts):
"""
if opts.get('follow') and opts.get('rev'):
opts['rev'] = [revset.formatspec('reverse(::%lr)', opts.get('rev'))]
opts['rev'] = [revsetlang.formatspec('reverse(::%lr)', opts.get('rev'))]
del opts['follow']
if opts.get('graph'):
......@@ -4093,7 +4093,7 @@ def push(ui, repo, dest=None, **opts):
elif path.pushrev:
# It doesn't make any sense to specify ancestor revisions. So limit
# to DAG heads to make discovery simpler.
expr = revset.formatspec('heads(%r)', path.pushrev)
expr = revsetlang.formatspec('heads(%r)', path.pushrev)
revs = scmutil.revrange(repo, [expr])
revs = [repo[rev].node() for rev in revs]
if not revs:
......
......@@ -52,6 +52,7 @@ from . import (
repair,
revlog,
revset,
revsetlang,
scmutil,
setdiscovery,
simplemerge,
......@@ -1794,10 +1795,10 @@ def debugrevspec(ui, repo, expr, **opts):
"""
stages = [
('parsed', lambda tree: tree),
('expanded', lambda tree: revset.expandaliases(ui, tree)),
('concatenated', revset.foldconcat),
('analyzed', revset.analyze),
('optimized', revset.optimize),
('expanded', lambda tree: revsetlang.expandaliases(ui, tree)),
('concatenated', revsetlang.foldconcat),
('analyzed', revsetlang.analyze),
('optimized', revsetlang.optimize),
]
if opts['no_optimized']:
stages = stages[:-1]
......@@ -1826,13 +1827,13 @@ def debugrevspec(ui, repo, expr, **opts):
treebystage = {}
printedtree = None
tree = revset.parse(expr, lookup=repo.__contains__)
tree = revsetlang.parse(expr, lookup=repo.__contains__)
for n, f in stages:
treebystage[n] = tree = f(tree)
if n in showalways or (n in showchanged and tree != printedtree):
if opts['show_stage'] or n != 'parsed':
ui.write(("* %s:\n") % n)
ui.write(revset.prettyformat(tree), "\n")
ui.write(revsetlang.prettyformat(tree), "\n")
printedtree = tree
if opts['verify_optimized']:
......
......@@ -32,6 +32,7 @@ from .. import (
error,
graphmod,
revset,
revsetlang,
scmutil,
smartset,
templatefilters,
......@@ -239,20 +240,20 @@ def _search(web, req, tmpl):
revdef = 'reverse(%s)' % query
try:
tree = revset.parse(revdef)
tree = revsetlang.parse(revdef)
except error.ParseError:
# can't parse to a revset tree
return MODE_KEYWORD, query
if revset.depth(tree) <= 2:
if revsetlang.depth(tree) <= 2:
# no revset syntax used
return MODE_KEYWORD, query
if any((token, (value or '')[:3]) == ('string', 're:')
for token, value, pos in revset.tokenize(revdef)):
for token, value, pos in revsetlang.tokenize(revdef)):
return MODE_KEYWORD, query
funcsused = revset.funcsused(tree)
funcsused = revsetlang.funcsused(tree)
if not funcsused.issubset(revset.safesymbols):
return MODE_KEYWORD, query
......
......@@ -50,6 +50,7 @@ from . import (
pushkey,
repoview,
revset,
revsetlang,
scmutil,
store,
subrepo,
......@@ -573,7 +574,7 @@ class localrepository(object):
'''Find revisions matching a revset.
The revset is specified as a string ``expr`` that may contain
%-formatting to escape certain types. See ``revset.formatspec``.
%-formatting to escape certain types. See ``revsetlang.formatspec``.
Revset aliases from the configuration are not expanded. To expand
user aliases, consider calling ``scmutil.revrange()``.
......@@ -581,7 +582,7 @@ class localrepository(object):
Returns a revset.abstractsmartset, which is a list-like interface
that contains integer revisions.
'''
expr = revset.formatspec(expr, *args)
expr = revsetlang.formatspec(expr, *args)
m = revset.match(None, expr)
return m(self)
......
This diff is collapsed.
This diff is collapsed.
......@@ -30,6 +30,7 @@ from . import (
phases,
pycompat,
revset,
revsetlang,
similar,
util,
)
......@@ -890,7 +891,7 @@ def revsingle(repo, revspec, default='.'):
return repo[l.last()]
def _pairspec(revspec):
tree = revset.parse(revspec)
tree = revsetlang.parse(revspec)
return tree and tree[0] in ('range', 'rangepre', 'rangepost', 'rangeall')
def revpair(repo, revs):
......@@ -936,7 +937,7 @@ def revrange(repo, specs):
revision numbers.
It is assumed the revsets are already formatted. If you have arguments
that need to be expanded in the revset, call ``revset.formatspec()``
that need to be expanded in the revset, call ``revsetlang.formatspec()``
and pass the result as an element of ``specs``.
Specifying a single revset is allowed.
......@@ -947,7 +948,7 @@ def revrange(repo, specs):
allspecs = []
for spec in specs:
if isinstance(spec, int):
spec = revset.formatspec('rev(%d)', spec)
spec = revsetlang.formatspec('rev(%d)', spec)
allspecs.append(spec)
m = revset.matchany(repo.ui, allspecs, repo)
return m(repo)
......
......@@ -20,6 +20,7 @@ from . import (
pycompat,
registrar,
revset as revsetmod,
revsetlang,
templatefilters,
templatekw,
util,
......@@ -778,7 +779,7 @@ def revset(context, mapping, args):
if len(args) > 1:
formatargs = [evalfuncarg(context, mapping, a) for a in args[1:]]
revs = query(revsetmod.formatspec(raw, *formatargs))
revs = query(revsetlang.formatspec(raw, *formatargs))
revs = list(revs)
else:
revsetcache = mapping['cache'].setdefault("revsetcache", {})
......
......@@ -28,7 +28,7 @@ testmod('mercurial.minirst')
testmod('mercurial.patch')
testmod('mercurial.pathutil')
testmod('mercurial.parser')
testmod('mercurial.revset')
testmod('mercurial.revsetlang')
testmod('mercurial.smartset')
testmod('mercurial.store')
testmod('mercurial.subrepo')
......
......@@ -82,18 +82,18 @@ o (0) root
> }
$ cat > printrevset.py <<EOF
> from mercurial import extensions, revset, commands, cmdutil
> from mercurial import extensions, revsetlang, commands, cmdutil
>
> def uisetup(ui):
> def printrevset(orig, ui, repo, *pats, **opts):
> if opts.get('print_revset'):
> expr = cmdutil.getgraphlogrevs(repo, pats, opts)[1]
> if expr:
> tree = revset.parse(expr)
> tree = revsetlang.parse(expr)
> else:
> tree = []
> ui.write('%r\n' % (opts.get('rev', []),))
> ui.write(revset.prettyformat(tree) + '\n')
> ui.write(revsetlang.prettyformat(tree) + '\n')
> return 0
> return orig(ui, repo, *pats, **opts)
> entry = extensions.wrapcommand(commands.table, 'log', printrevset)
......
......@@ -40,6 +40,7 @@ these predicates use '\0' as a separator:
> cmdutil,
> node as nodemod,
> revset,
> revsetlang,
> smartset,
> )
> cmdtable = {}
......@@ -50,13 +51,14 @@ these predicates use '\0' as a separator:
> def debugrevlistspec(ui, repo, fmt, *args, **opts):
> if opts['bin']:
> args = map(nodemod.bin, args)
> expr = revset.formatspec(fmt, list(args))
> expr = revsetlang.formatspec(fmt, list(args))
> if ui.verbose:
> tree = revset.parse(expr, lookup=repo.__contains__)
> ui.note(revset.prettyformat(tree), "\n")
> tree = revsetlang.parse(expr, lookup=repo.__contains__)
> ui.note(revsetlang.prettyformat(tree), "\n")
> if opts["optimize"]:
> opttree = revset.optimize(revset.analyze(tree))
> ui.note("* optimized:\n", revset.prettyformat(opttree), "\n")
> opttree = revsetlang.optimize(revsetlang.analyze(tree))
> ui.note("* optimized:\n", revsetlang.prettyformat(opttree),
> "\n")
> func = revset.match(ui, expr, repo)
> revs = func(repo)
> if ui.verbose:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment