Patchwork [2,of,4,V5] revset: add helper function to get functions used in a revset parse tree

login
register
mail settings
Submitter Alexander Plavin
Date Sept. 6, 2013, 9:35 a.m.
Message ID <138d070c107576094931.1378460135@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/2394/
State Accepted
Commit f0b992a9be9c3a5574de8abb9219a2897619516f
Headers show

Comments

Alexander Plavin - Sept. 6, 2013, 9:35 a.m.
# HG changeset patch
# User Alexander Plavin <alexander@plav.in>
# Date 1375824091 -14400
#      Wed Aug 07 01:21:31 2013 +0400
# Node ID 138d070c10757609493168d01da01b763e561f05
# Parent  e87a93bf4c2fb8229fe39acdfdfb54ba8736eef2
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.

Patch

diff -r e87a93bf4c2f -r 138d070c1075 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
@@ -1951,5 +1951,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()