[PATCH 2 of 4 V2] revset: add helper function to get functions used in a tree

Alexander Plavin alexander at plav.in
Fri Aug 9 13:54:56 CDT 2013


# HG changeset patch
# User Alexander Plavin <alexander at plav.in>
# Date 1375824091 -14400
#      Wed Aug 07 01:21:31 2013 +0400
# Node ID dfc9d96b85a4ebb96d7ad876952aad1cd052c444
# Parent  10862e95f769e7555ee54c0647595d508d5672ef
revset: add helper function to get functions used in a tree

diff -r 10862e95f769 -r dfc9d96b85a4 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
@@ -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()


More information about the Mercurial-devel mailing list