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

Alexander Plavin alexander at plav.in
Thu Aug 22 10:11:15 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 5734dd4b2bd2a859a2ef0be6e0f4485f028abf6e
# Parent  6db09c0cbf06af6f990fcb497449f8e1200fba86
revset: add helper function to get functions used in a revset parse tree

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()


More information about the Mercurial-devel mailing list