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

login
register
mail settings
Submitter Alexander Plavin
Date Aug. 16, 2013, 8:03 p.m.
Message ID <916a7171b59f37173275.1376683408@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/2187/
State Superseded
Headers show

Comments

Alexander Plavin - Aug. 16, 2013, 8:03 p.m.
# HG changeset patch
# User Alexander Plavin <alexander@plav.in>
# Date 1375824091 -14400
#      Wed Aug 07 01:21:31 2013 +0400
# Node ID 916a7171b59f371732758ab473c4bf5467631a13
# Parent  3a09bc2bf256789aa7a4d5c50dedf9fb50886873
revset: add helper function to get functions used in a revset parse tree

Patch

diff -r 3a09bc2bf256 -r 916a7171b59f 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()