changeset 37674:f83cb91b052e

revset: pass in lookup function instead of repo (API) And document that it's only for legacy lookup. If we have a repo, we're likely to do more things where that shouldn't be done.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 14 Apr 2018 12:57:32 +0900
parents 0c6b1ec75b73
children 5b8a260769a2
files mercurial/hgweb/webcommands.py mercurial/localrepo.py mercurial/revset.py mercurial/templatefuncs.py tests/test-revset.t
diffstat 5 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/webcommands.py	Sat Apr 14 12:44:40 2018 +0900
+++ b/mercurial/hgweb/webcommands.py	Sat Apr 14 12:57:32 2018 +0900
@@ -276,7 +276,8 @@
         if not funcsused.issubset(revset.safesymbols):
             return MODE_KEYWORD, query
 
-        mfunc = revset.match(web.repo.ui, revdef, repo=web.repo)
+        mfunc = revset.match(web.repo.ui, revdef,
+                             lookup=revset.lookupfn(web.repo))
         try:
             revs = mfunc(web.repo)
             return MODE_REVSET, revs
--- a/mercurial/localrepo.py	Sat Apr 14 12:44:40 2018 +0900
+++ b/mercurial/localrepo.py	Sat Apr 14 12:57:32 2018 +0900
@@ -905,7 +905,8 @@
         ``{name: definitionstring}``.
         '''
         if user:
-            m = revset.matchany(self.ui, specs, repo=self,
+            m = revset.matchany(self.ui, specs,
+                                lookup=revset.lookupfn(self),
                                 localalias=localalias)
         else:
             m = revset.matchany(None, specs, localalias=localalias)
--- a/mercurial/revset.py	Sat Apr 14 12:44:40 2018 +0900
+++ b/mercurial/revset.py	Sat Apr 14 12:57:32 2018 +0900
@@ -2169,14 +2169,17 @@
 def lookupfn(repo):
     return lambda symbol: scmutil.isrevsymbol(repo, symbol)
 
-def match(ui, spec, repo=None):
+def match(ui, spec, lookup=None):
     """Create a matcher for a single revision spec"""
-    return matchany(ui, [spec], repo=repo)
+    return matchany(ui, [spec], lookup=None)
 
-def matchany(ui, specs, repo=None, localalias=None):
+def matchany(ui, specs, lookup=None, localalias=None):
     """Create a matcher that will include any revisions matching one of the
     given specs
 
+    If lookup function is not None, the parser will first attempt to handle
+    old-style ranges, which may contain operator characters.
+
     If localalias is not None, it is a dict {name: definitionstring}. It takes
     precedence over [revsetalias] config section.
     """
@@ -2186,9 +2189,6 @@
         return mfunc
     if not all(specs):
         raise error.ParseError(_("empty query"))
-    lookup = None
-    if repo:
-        lookup = lookupfn(repo)
     if len(specs) == 1:
         tree = revsetlang.parse(specs[0], lookup)
     else:
--- a/mercurial/templatefuncs.py	Sat Apr 14 12:44:40 2018 +0900
+++ b/mercurial/templatefuncs.py	Sat Apr 14 12:57:32 2018 +0900
@@ -522,7 +522,7 @@
     repo = ctx.repo()
 
     def query(expr):
-        m = revsetmod.match(repo.ui, expr, repo=repo)
+        m = revsetmod.match(repo.ui, expr, lookup=revsetmod.lookupfn(repo))
         return m(repo)
 
     if len(args) > 1:
--- a/tests/test-revset.t	Sat Apr 14 12:44:40 2018 +0900
+++ b/tests/test-revset.t	Sat Apr 14 12:57:32 2018 +0900
@@ -60,7 +60,7 @@
   >             opttree = revsetlang.optimize(revsetlang.analyze(tree))
   >             ui.note(b"* optimized:\n", revsetlang.prettyformat(opttree),
   >                     b"\n")
-  >     func = revset.match(ui, expr, repo)
+  >     func = revset.match(ui, expr, lookup=revset.lookupfn(repo))
   >     revs = func(repo)
   >     if ui.verbose:
   >         ui.note(b"* set:\n", smartset.prettyformat(revs), b"\n")