revset: check for collisions between alias argument names in the declaration
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Sat, 10 Jan 2015 23:18:11 +0900
changeset 23847 71402bb8d8b2
parent 23846 aac4a1a7920e
child 23848 c5456b64eb07
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.
mercurial/revset.py
--- a/mercurial/revset.py	Sat Jan 10 23:18:11 2015 +0900
+++ b/mercurial/revset.py	Sat Jan 10 23:18:11 2015 +0900
@@ -2203,6 +2203,8 @@
     ('foo($1, $2', None, None, 'at 10: unexpected token: end')
     >>> _parsealiasdecl('foo("string')
     ('foo("string', None, None, 'at 5: unterminated string')
+    >>> _parsealiasdecl('foo($1, $2, $1)')
+    ('foo', None, None, 'argument names collide with each other')
     """
     p = parser.parser(_tokenizealias, elements)
     try:
@@ -2227,6 +2229,9 @@
                 if not isvalidsymbol(arg):
                     return (decl, None, None, _("invalid argument list"))
                 args.append(getsymbol(arg))
+            if len(args) != len(set(args)):
+                return (name, None, None,
+                        _("argument names collide with each other"))
             return (name, ('func', ('symbol', name)), args, None)
 
         return (decl, None, None, _("invalid format"))