# HG changeset patch # User Yuya Nishihara # Date 2018-04-14 03:57:32 # Node ID f83cb91b052e60432be75c8e33b2e5f3c7a37476 # Parent 0c6b1ec75b73509481fdedf0d72003c395eccbe4 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. diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py +++ b/mercurial/hgweb/webcommands.py @@ -276,7 +276,8 @@ def _search(web): 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 diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -905,7 +905,8 @@ class localrepository(object): ``{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) diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -2169,14 +2169,17 @@ methods = { 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 @@ def matchany(ui, specs, repo=None, local 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: diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py --- a/mercurial/templatefuncs.py +++ b/mercurial/templatefuncs.py @@ -522,7 +522,7 @@ def revset(context, mapping, args): 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: diff --git a/tests/test-revset.t b/tests/test-revset.t --- a/tests/test-revset.t +++ b/tests/test-revset.t @@ -60,7 +60,7 @@ these predicates use '\0' as a separator > 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")