Mercurial > public > mercurial-scm > hg
comparison mercurial/revset.py @ 23847:71402bb8d8b2
revset: check for collisions between alias argument names in the declaration
Before this patch, collisions between alias argument names in the
declaration are ignored, and this silently causes unexpected alias
evaluation.
This patch checks for such collisions, and aborts (or shows a warning) when
collisions are detected.
This patch doesn't add a test to "test-revset.t", because a doctest is
enough to test the collisions detection itself.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sat, 10 Jan 2015 23:18:11 +0900 |
parents | aac4a1a7920e |
children | caff3675cba5 |
comparison
equal
deleted
inserted
replaced
23846:aac4a1a7920e | 23847:71402bb8d8b2 |
---|---|
2201 ('foo("string")', None, None, 'invalid argument list') | 2201 ('foo("string")', None, None, 'invalid argument list') |
2202 >>> _parsealiasdecl('foo($1, $2') | 2202 >>> _parsealiasdecl('foo($1, $2') |
2203 ('foo($1, $2', None, None, 'at 10: unexpected token: end') | 2203 ('foo($1, $2', None, None, 'at 10: unexpected token: end') |
2204 >>> _parsealiasdecl('foo("string') | 2204 >>> _parsealiasdecl('foo("string') |
2205 ('foo("string', None, None, 'at 5: unterminated string') | 2205 ('foo("string', None, None, 'at 5: unterminated string') |
2206 >>> _parsealiasdecl('foo($1, $2, $1)') | |
2207 ('foo', None, None, 'argument names collide with each other') | |
2206 """ | 2208 """ |
2207 p = parser.parser(_tokenizealias, elements) | 2209 p = parser.parser(_tokenizealias, elements) |
2208 try: | 2210 try: |
2209 tree, pos = p.parse(decl) | 2211 tree, pos = p.parse(decl) |
2210 if (pos != len(decl)): | 2212 if (pos != len(decl)): |
2225 args = [] | 2227 args = [] |
2226 for arg in getfuncargs(tree): | 2228 for arg in getfuncargs(tree): |
2227 if not isvalidsymbol(arg): | 2229 if not isvalidsymbol(arg): |
2228 return (decl, None, None, _("invalid argument list")) | 2230 return (decl, None, None, _("invalid argument list")) |
2229 args.append(getsymbol(arg)) | 2231 args.append(getsymbol(arg)) |
2232 if len(args) != len(set(args)): | |
2233 return (name, None, None, | |
2234 _("argument names collide with each other")) | |
2230 return (name, ('func', ('symbol', name)), args, None) | 2235 return (name, ('func', ('symbol', name)), args, None) |
2231 | 2236 |
2232 return (decl, None, None, _("invalid format")) | 2237 return (decl, None, None, _("invalid format")) |
2233 except error.ParseError, inst: | 2238 except error.ParseError, inst: |
2234 return (decl, None, None, parseerrordetail(inst)) | 2239 return (decl, None, None, parseerrordetail(inst)) |