changeset 37350:e32dfff71529

revset: use revsymbol() for checking if a symbol is valid Differential Revision: https://phab.mercurial-scm.org/D3078
author Martin von Zweigbergk <martinvonz@google.com>
date Sun, 01 Apr 2018 22:48:32 -0700
parents 36b2a304216c
children fdd22bf6398f
files mercurial/debugcommands.py mercurial/revset.py mercurial/scmutil.py tests/test-revset.t
diffstat 4 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/debugcommands.py	Tue Apr 03 15:08:14 2018 -0700
+++ b/mercurial/debugcommands.py	Sun Apr 01 22:48:32 2018 -0700
@@ -2210,7 +2210,7 @@
 
     treebystage = {}
     printedtree = None
-    tree = revsetlang.parse(expr, lookup=repo.__contains__)
+    tree = revsetlang.parse(expr, lookup=revset.lookupfn(repo))
     for n, f in stages:
         treebystage[n] = tree = f(tree)
         if n in showalways or (n in showchanged and tree != printedtree):
--- a/mercurial/revset.py	Tue Apr 03 15:08:14 2018 -0700
+++ b/mercurial/revset.py	Sun Apr 01 22:48:32 2018 -0700
@@ -2170,6 +2170,9 @@
     # hook for extensions to execute code on the optimized tree
     pass
 
+def lookupfn(repo):
+    return lambda symbol: scmutil.isrevsymbol(repo, symbol)
+
 def match(ui, spec, repo=None):
     """Create a matcher for a single revision spec"""
     return matchany(ui, [spec], repo=repo)
@@ -2189,7 +2192,7 @@
         raise error.ParseError(_("empty query"))
     lookup = None
     if repo:
-        lookup = repo.__contains__
+        lookup = lookupfn(repo)
     if len(specs) == 1:
         tree = revsetlang.parse(specs[0], lookup)
     else:
--- a/mercurial/scmutil.py	Tue Apr 03 15:08:14 2018 -0700
+++ b/mercurial/scmutil.py	Sun Apr 01 22:48:32 2018 -0700
@@ -433,6 +433,13 @@
         hexfunc = short
     return '%d:%s' % (rev, hexfunc(node))
 
+def isrevsymbol(repo, symbol):
+    try:
+        revsymbol(repo, symbol)
+        return True
+    except error.RepoLookupError:
+        return False
+
 def revsymbol(repo, symbol):
     """Returns a context given a single revision symbol (as string).
 
--- a/tests/test-revset.t	Tue Apr 03 15:08:14 2018 -0700
+++ b/tests/test-revset.t	Sun Apr 01 22:48:32 2018 -0700
@@ -54,7 +54,7 @@
   >         args = map(nodemod.bin, args)
   >     expr = revsetlang.formatspec(fmt, list(args))
   >     if ui.verbose:
-  >         tree = revsetlang.parse(expr, lookup=repo.__contains__)
+  >         tree = revsetlang.parse(expr, lookup=revset.lookupfn(repo))
   >         ui.note(revsetlang.prettyformat(tree), b"\n")
   >         if opts["optimize"]:
   >             opttree = revsetlang.optimize(revsetlang.analyze(tree))