Patchwork [1,of,3] revset: extend match() to accept list of specs that will be OR-ed

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 5, 2015, 2:44 p.m.
Message ID <983e70e0f872ff4b273e.1438785861@mimosa>
Download mbox | patch
Permalink /patch/10105/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 5, 2015, 2:44 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1436067142 -32400
#      Sun Jul 05 12:32:22 2015 +0900
# Node ID 983e70e0f872ff4b273e485526670ccfc8c6738a
# Parent  80149d0b6842713b8fdebf34404fc3520306c7a2
revset: extend match() to accept list of specs that will be OR-ed

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

If we prefer a separate function than parameter overloading, I'll add
matchany(ui, specs, repo=None) function instead.
Pierre-Yves David - Aug. 6, 2015, 10:05 p.m.
On 08/05/2015 07:44 AM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1436067142 -32400
> #      Sun Jul 05 12:32:22 2015 +0900
> # Node ID 983e70e0f872ff4b273e485526670ccfc8c6738a
> # Parent  80149d0b6842713b8fdebf34404fc3520306c7a2
> revset: extend match() to accept list of specs that will be OR-ed
>
> This will allow us to optimize "-rREV1 -rREV2 ..." command-line options.
>
> If we prefer a separate function than parameter overloading, I'll add
> matchany(ui, specs, repo=None) function instead.

I like the series but I think I would prefer an explicit function. 
Change of behavior on the argument type are a bit too magical.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2661,12 +2661,22 @@  def posttreebuilthook(tree, repo):
     pass
 
 def match(ui, spec, repo=None):
-    if not spec:
+    """Parse the given spec and create a matcher. If the spec is a list,
+    it will include any revisions that match one of the given spec.
+    """
+    if not isinstance(spec, list):
+        spec = [spec]
+    if not all(spec):
         raise error.ParseError(_("empty query"))
     lookup = None
     if repo:
         lookup = repo.__contains__
-    tree = parse(spec, lookup)
+    if not spec:
+        tree = None
+    elif len(spec) == 1:
+        tree = parse(spec[0], lookup)
+    else:
+        tree = ('or',) + tuple(parse(s, lookup) for s in spec)
     if ui:
         tree = findaliases(ui, tree, showwarning=ui.warn)
     tree = foldconcat(tree)
@@ -2675,7 +2685,9 @@  def match(ui, spec, repo=None):
     def mfunc(repo, subset=None):
         if subset is None:
             subset = fullreposet(repo)
-        if util.safehasattr(subset, 'isascending'):
+        if tree is None:
+            result = baseset()
+        elif util.safehasattr(subset, 'isascending'):
             result = getset(repo, subset, tree)
         else:
             result = getset(repo, baseset(subset), tree)