changeset 16772:30e46d7138de stable

revset: fix infinite alias expansion detection The alias expansion code it changed from: 1- Get replacement tree 2- Substitute arguments in the replacement tree 3- Expand the replacement tree again into: 1- Get the replacement tree 2- Expand the replacement tree 3- Expand the arguments 4- Substitute the expanded arguments in the replacement tree and fixes cases like: [revsetalias] level1($1, $2) = $1 or $2 level2($1, $2) = level1($2, $1) $ hg log -r "level2(level1(1, 2), 3)" where the original version incorrectly aborted on infinite expansion error, because it was confusing the expanded aliases with their arguments.
author Patrick Mezard <patrick@mezard.eu>
date Sat, 19 May 2012 17:19:55 +0200
parents 2f3317d53d51
children 2ac08d8b21aa c17ce7cd5090 b748106fe616
files mercurial/revset.py tests/test-revset.t
diffstat 2 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Sat May 19 17:18:29 2012 +0200
+++ b/mercurial/revset.py	Sat May 19 17:19:55 2012 +0200
@@ -1377,16 +1377,15 @@
             raise error.ParseError(_('infinite expansion of revset alias "%s" '
                                      'detected') % alias.name)
         expanding.append(alias)
-        result = alias.replacement
+        result = _expandaliases(aliases, alias.replacement, expanding)
+        expanding.pop()
         if alias.args is not None:
             l = getlist(tree[2])
             if len(l) != len(alias.args):
                 raise error.ParseError(
                     _('invalid number of arguments: %s') % len(l))
+            l = [_expandaliases(aliases, a, []) for a in l]
             result = _expandargs(result, dict(zip(alias.args, l)))
-        # Recurse in place, the base expression may have been rewritten
-        result = _expandaliases(aliases, result, expanding)
-        expanding.pop()
     else:
         result = tuple(_expandaliases(aliases, t, expanding)
                        for t in tree)
--- a/tests/test-revset.t	Sat May 19 17:18:29 2012 +0200
+++ b/tests/test-revset.t	Sat May 19 17:19:55 2012 +0200
@@ -520,6 +520,27 @@
   hg: parse error: infinite expansion of revset alias "recurse1" detected
   [255]
 
+  $ echo 'level1($1, $2) = $1 or $2' >> .hg/hgrc
+  $ echo 'level2($1, $2) = level1($2, $1)' >> .hg/hgrc
+  $ try "level2(level1(1, 2), 3)"
+  (func
+    ('symbol', 'level2')
+    (list
+      (func
+        ('symbol', 'level1')
+        (list
+          ('symbol', '1')
+          ('symbol', '2')))
+      ('symbol', '3')))
+  (or
+    ('symbol', '3')
+    (or
+      ('symbol', '1')
+      ('symbol', '2')))
+  3
+  1
+  2
+
 test nesting and variable passing
 
   $ echo 'nested($1) = nested2($1)' >> .hg/hgrc