revset: add helper function to get functions used in a revset parse tree
authorAlexander Plavin <alexander@plav.in>
Wed, 07 Aug 2013 01:21:31 +0400
changeset 19720 f0b992a9be9c
parent 19719 2f9d5c5256ea
child 19721 d8ca6d965230
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.
mercurial/revset.py
--- 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()