Patchwork D3078: revset: use revsymbol() for checking if a symbol is valid

login
register
mail settings
Submitter phabricator
Date April 5, 2018, 12:51 a.m.
Message ID <ff8e8677e0d80057b1910cc087dd4ea1@localhost.localdomain>
Download mbox | patch
Permalink /patch/30314/
State Not Applicable
Headers show

Comments

phabricator - April 5, 2018, 12:51 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGe32dfff71529: revset: use revsymbol() for checking if a symbol is valid (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3078?vs=7652&id=7664

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

AFFECTED FILES
  mercurial/debugcommands.py
  mercurial/revset.py
  mercurial/scmutil.py
  tests/test-revset.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel

Patch

diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -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))
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -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).
 
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -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:
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -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):