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

login
register
mail settings
Submitter Alexander Plavin
Date Aug. 22, 2013, 3:11 p.m.
Message ID <5734dd4b2bd2a859a2ef.1377184275@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/2246/
State Superseded
Commit f0b992a9be9c3a5574de8abb9219a2897619516f
Headers show

Comments

Alexander Plavin - Aug. 22, 2013, 3:11 p.m.
# HG changeset patch
# User Alexander Plavin <alexander@plav.in>
# Date 1375824091 -14400
#      Wed Aug 07 01:21:31 2013 +0400
# Node ID 5734dd4b2bd2a859a2ef0be6e0f4485f028abf6e
# Parent  6db09c0cbf06af6f990fcb497449f8e1200fba86
revset: add helper function to get functions used in a revset parse tree

Patch

diff -r 6db09c0cbf06 -r 5734dd4b2bd2 mercurial/revset.py
--- a/mercurial/revset.py	Fri Aug 16 15:01:22 2013 +0400
+++ b/mercurial/revset.py	Wed Aug 07 01:21:31 2013 +0400
@@ -1978,5 +1978,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()