Patchwork [3,of,5,V4] revset: add helper function to get functions used in a revset parse tree

login
register
mail settings
Submitter Alexander Plavin
Date Sept. 4, 2013, 7:13 p.m.
Message ID <c670daa7b41d00d9be9e.1378321986@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/2326/
State Superseded
Commit f0b992a9be9c3a5574de8abb9219a2897619516f
Delegated to: Kevin Bullock
Headers show

Comments

Alexander Plavin - Sept. 4, 2013, 7:13 p.m.
# HG changeset patch
# User Alexander Plavin <alexander@plav.in>
# Date 1375824091 -14400
#      Wed Aug 07 01:21:31 2013 +0400
# Node ID c670daa7b41d00d9be9ebeae910e2ea743f02e5b
# Parent  a7a859be2d42f36c3932b403db662e4b403e93a6
revset: add helper function to get functions used in a revset parse tree

Patch

diff -r a7a859be2d42 -r c670daa7b41d 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
@@ -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()