##// END OF EJS Templates
revsetlang: add utility function to return hash like symbols from the tree...
Pulkit Goyal -
r35510:dd911f95 default
parent child Browse files
Show More
@@ -661,3 +661,34 b' def funcsused(tree):'
661 if tree[0] == 'func':
661 if tree[0] == 'func':
662 funcs.add(tree[1][1])
662 funcs.add(tree[1][1])
663 return funcs
663 return funcs
664
665 _hashre = util.re.compile('[0-9a-fA-F]{1,40}$')
666
667 def _ishashlikesymbol(symbol):
668 """returns true if the symbol looks like a hash"""
669 return _hashre.match(symbol)
670
671 def gethashlikesymbols(tree):
672 """returns the list of symbols of the tree that look like hashes
673
674 >>> gethashlikesymbols(('dagrange', ('symbol', '3'), ('symbol', 'abe3ff')))
675 ['3', 'abe3ff']
676 >>> gethashlikesymbols(('func', ('symbol', 'precursors'), ('symbol', '.')))
677 []
678 >>> gethashlikesymbols(('func', ('symbol', 'precursors'), ('symbol', '34')))
679 ['34']
680 >>> gethashlikesymbols(('symbol', 'abe3ffZ'))
681 []
682 """
683 if not tree:
684 return []
685
686 if tree[0] == "symbol":
687 if _ishashlikesymbol(tree[1]):
688 return [tree[1]]
689 elif len(tree) >= 3:
690 results = []
691 for subtree in tree[1:]:
692 results += gethashlikesymbols(subtree)
693 return results
694 return []
General Comments 0
You need to be logged in to leave comments. Login now