D1678: revset: pass pre-optimized tree in revset.matchany()

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Wed Dec 13 01:55:31 UTC 2017


pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This is a part of series where we move logic around so that we can get the tree
  at a higher level function such as repo.anyrevs(). This will help us in reading
  the tree and doing certain operations like updating visibility exceptions on
  base of that.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/localrepo.py
  mercurial/revset.py

CHANGE DETAILS

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2163,26 +2163,25 @@
 
 def match(ui, spec, repo=None):
     """Create a matcher for a single revision spec"""
-    return matchany(ui, [spec], repo=repo)
+
+    if not specs:
+        return emptymatcher
+    if not all(specs):
+        raise error.ParseError(_("empty query"))
+
+    tree = buildtree([spec], repo)
+    return matchany(ui, tree, repo=repo)
 
 def emptymatcher(repo, subset=None):
     """ Matcher for empty specs """
     return baseset()
 
-def matchany(ui, specs, repo=None, localalias=None):
-    """Create a matcher that will include any revisions matching one of the
-    given specs
+def matchany(ui, tree, repo=None, localalias=None):
+    """Create a matcher for the tree
 
     If localalias is not None, it is a dict {name: definitionstring}. It takes
     precedence over [revsetalias] config section.
     """
-    if not specs:
-        return emptymatcher
-    if not all(specs):
-        raise error.ParseError(_("empty query"))
-
-    tree = buildtree(specs, repo)
-
     aliases = []
     warn = None
     if ui:
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -804,11 +804,19 @@
         definitions overriding user aliases, set ``localalias`` to
         ``{name: definitionstring}``.
         '''
+
+        if not specs:
+            return revset.emptymatcher(self)
+        if not all(specs):
+            raise error.ParseError(_("empty query"))
+
         if user:
-            m = revset.matchany(self.ui, specs, repo=self,
+            tree = revset.buildtree(specs, self)
+            m = revset.matchany(self.ui, tree, repo=self,
                                 localalias=localalias)
         else:
-            m = revset.matchany(None, specs, localalias=localalias)
+            tree = revset.buildtree(specs)
+            m = revset.matchany(None, tree, localalias=localalias)
         return m(self)
 
     def url(self):



To: pulkit, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list