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

login
register
mail settings
Submitter phabricator
Date April 4, 2018, 10:53 p.m.
Message ID <differential-rev-PHID-DREV-r3bdhzmtubthxm32esfo-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/30303/
State Superseded
Headers show

Comments

phabricator - April 4, 2018, 10:53 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

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
Cc: mercurial-devel
phabricator - April 5, 2018, 12:44 a.m.
indygreg accepted this revision.
indygreg added a comment.
This revision is now accepted and ready to land.


  I'm accepting this because it seems correct. But I'd really appreciate @yuya's review on this because I'm not sure if the change to `revset.matchany()` has unintended consequences.

REPOSITORY
  rHG Mercurial

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

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):