Patchwork [2,of,4,V2] revset: add matchany() to construct OR expression from a list of specs

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 7, 2015, 2:45 p.m.
Message ID <0355c8788321b887e9e3.1438958745@mimosa>
Download mbox | patch
Permalink /patch/10131/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 7, 2015, 2:45 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1438951178 -32400
#      Fri Aug 07 21:39:38 2015 +0900
# Node ID 0355c8788321b887e9e3e3b41149e801ac111e37
# Parent  1eb76318ec555ffd3b465324988bf7880026241a
revset: add matchany() to construct OR expression from a list of specs

This will allow us to optimize "-rREV1 -rREV2 ..." command-line options.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2669,6 +2669,24 @@  def match(ui, spec, repo=None):
     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)