Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revsetlang.py @ 35498:dd911f95cbda
revsetlang: add utility function to return hash like symbols from the tree
Functionalities like unhiding changesets whose rev/hash is passed by the user
required the knowledge of rev/hashes in the user provided specs. This patch adds
functions which can parse tree object and return a list of such values.
Differential Revision: https://phab.mercurial-scm.org/D1732
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Fri, 15 Dec 2017 04:25:32 +0530 |
parents | b0790bebfcf8 |
children | beb667c9880f |
comparison
equal
deleted
inserted
replaced
35497:3c9c05a38d78 | 35498:dd911f95cbda |
---|---|
659 for s in tree[1:]: | 659 for s in tree[1:]: |
660 funcs |= funcsused(s) | 660 funcs |= funcsused(s) |
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 [] |