[PATCH 6 of 6 V2] revset: check collision between alias argument names in the declaration

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sat Jan 10 08:25:46 CST 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1420899491 -32400
#      Sat Jan 10 23:18:11 2015 +0900
# Node ID c623e015a449750d89ca412a1c26f0175362c778
# Parent  950ed266b47516098bc350b1b835c3de085c5e9f
revset: check collision between alias argument names in the declaration

Before this patch, collision between alias argument names in the
declaration is ignored, and this silently causes unexpected alias
evaluation.

This patch checks such collision, and aborts (or show warning) when
collision is detected.

This patch doesn't add test to "test-revset.t", because doctest is
enough to test error detection itself.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2166,6 +2166,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:
@@ -2190,6 +2192,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"))


More information about the Mercurial-devel mailing list