revset: explicitely tag alias arguments for expansion
The current revset alias expansion code works like:
1- Get the replacement tree
2- Substitute the variables in the replacement tree
3- Expand the replacement tree
It makes it easy to substitute alias arguments because the placeholders
are always replaced before the updated replacement tree is expanded
again. Unfortunately, to fix other alias expansion issues, we need to
reorder the sequence and delay the argument substitution. To solve this,
a new "virtual" construct called _aliasarg() is introduced and injected
when parsing the aliases definitions. Only _aliasarg() will be
substituted in the argument expansion phase instead of all regular
matching string. We also check user inputs do not contain unexpected
_aliasarg() instances to avoid argument injections.
from mercurial import wireproto
class proto(object):
def __init__(self, args):
self.args = args
def getargs(self, spec):
args = self.args
args.setdefault('*', {})
names = spec.split()
return [args[n] for n in names]
class clientrepo(wireproto.wirerepository):
def __init__(self, serverrepo):
self.serverrepo = serverrepo
def _call(self, cmd, **args):
return wireproto.dispatch(self.serverrepo, proto(args), cmd)
@wireproto.batchable
def greet(self, name):
f = wireproto.future()
yield wireproto.todict(name=mangle(name)), f
yield unmangle(f.value)
class serverrepo(object):
def greet(self, name):
return "Hello, " + name
def mangle(s):
return ''.join(chr(ord(c) + 1) for c in s)
def unmangle(s):
return ''.join(chr(ord(c) - 1) for c in s)
def greet(repo, proto, name):
return mangle(repo.greet(unmangle(name)))
wireproto.commands['greet'] = (greet, 'name',)
srv = serverrepo()
clt = clientrepo(srv)
print clt.greet("Foobar")
b = clt.batch()
fs = [b.greet(s) for s in ["Fo, =;o", "Bar"]]
b.submit()
print [f.value for f in fs]