revset: add matchany() to construct OR expression from a list of specs
authorYuya Nishihara <yuya@tcha.org>
Fri, 07 Aug 2015 21:39:38 +0900
changeset 25927 44da63623fca
parent 25926 996102be8b91
child 25928 4ee4f7415095
revset: add matchany() to construct OR expression from a list of specs This will allow us to optimize "-rREV1 -rREV2 ..." command-line options.
mercurial/revset.py
--- a/mercurial/revset.py	Fri Aug 07 21:31:16 2015 +0900
+++ b/mercurial/revset.py	Fri Aug 07 21:39:38 2015 +0900
@@ -2669,6 +2669,24 @@
     tree = parse(spec, lookup)
     return _makematcher(ui, tree, repo)
 
+def matchany(ui, specs, repo=None):
+    """Create a matcher that will include any revisions matching one of the
+    given specs"""
+    if not specs:
+        def mfunc(repo, subset=None):
+            return baseset()
+        return mfunc
+    if not all(specs):
+        raise error.ParseError(_("empty query"))
+    lookup = None
+    if repo:
+        lookup = repo.__contains__
+    if len(specs) == 1:
+        tree = parse(specs[0], lookup)
+    else:
+        tree = ('or',) + tuple(parse(s, lookup) for s in specs)
+    return _makematcher(ui, tree, repo)
+
 def _makematcher(ui, tree, repo):
     if ui:
         tree = findaliases(ui, tree, showwarning=ui.warn)