Patchwork [6,of,6] revset: check collision between alias argument names in the declaration

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Jan. 8, 2015, 10:37 a.m.
Message ID <90362acd8d4809f7ab5d.1420713434@feefifofum>
Download mbox | patch
Permalink /patch/7384/
State Changes Requested
Headers show

Comments

Katsunori FUJIWARA - Jan. 8, 2015, 10:37 a.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1420712143 -32400
#      Thu Jan 08 19:15:43 2015 +0900
# Node ID 90362acd8d4809f7ab5d74ceccfb3e73246ed0a1
# Parent  f6735b97843b1d24bfff33f0e2636b2a9233551a
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.

Patch

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