[PATCH 1 of 3] revset: extend match() to accept list of specs that will be OR-ed
Yuya Nishihara
yuya at tcha.org
Wed Aug 5 14:44:21 UTC 2015
# HG changeset patch
# User Yuya Nishihara <yuya at 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.
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)
More information about the Mercurial-devel
mailing list