changeset 19720:f0b992a9be9c

revset: add helper function to get functions used in a revset parse tree Will be used to determine whether all functions used in a hgweb search query are allowed there.
author Alexander Plavin <alexander@plav.in>
date Wed, 07 Aug 2013 01:21:31 +0400
parents 2f9d5c5256ea
children d8ca6d965230
files mercurial/revset.py
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Fri Aug 09 22:52:58 2013 +0400
+++ b/mercurial/revset.py	Wed Aug 07 01:21:31 2013 +0400
@@ -1941,5 +1941,16 @@
     else:
         return 0
 
+def funcsused(tree):
+    if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
+        return set()
+    else:
+        funcs = set()
+        for s in tree[1:]:
+            funcs |= funcsused(s)
+        if tree[0] == 'func':
+            funcs.add(tree[1][1])
+        return funcs
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()