D1732: revsetlang: add utility function to return hash like symbols from the tree

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Tue Dec 19 12:10:04 UTC 2017


pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1732

AFFECTED FILES
  mercurial/revsetlang.py

CHANGE DETAILS

diff --git a/mercurial/revsetlang.py b/mercurial/revsetlang.py
--- a/mercurial/revsetlang.py
+++ b/mercurial/revsetlang.py
@@ -661,3 +661,26 @@
         if tree[0] == 'func':
             funcs.add(tree[1][1])
         return funcs
+
+hashre = util.re.compile('[0-9a-fA-F]{1,40}')
+
+def _ishashlikesymbol(symbol):
+    """returns true if the symbol looks like a hash"""
+    return hashre.match(symbol)
+
+def gethashlikesymbols(tree):
+    """returns the list of symbols of the tree that look like hashes
+
+    for example for the revset 3::abe3ff it will return ('3', 'abe3ff')"""
+    if not tree:
+        return []
+
+    results = []
+    if tree[0] == "symbol":
+        results.append(tree[1])
+    elif len(tree) >= 3:
+        for subtree in tree[1:]:
+            results += gethashlikesymbols(subtree)
+        # return directly, we don't need to filter symbols again
+        return results
+    return [s for s in results if _ishashlikesymbol(s)]



To: pulkit, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list