From patchwork Wed Aug 5 14:44:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1, of, 3] revset: extend match() to accept list of specs that will be OR-ed From: Yuya Nishihara X-Patchwork-Id: 10105 Message-Id: <983e70e0f872ff4b273e.1438785861@mimosa> To: mercurial-devel@selenic.com Date: Wed, 05 Aug 2015 23:44:21 +0900 # HG changeset patch # User Yuya Nishihara # 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)