Patchwork [2,of,2] revset: implement match() in terms of matchany()

login
register
mail settings
Submitter Gregory Szorc
Date June 26, 2016, 2:12 a.m.
Message ID <802176b09678e1b52a8d.1466907169@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/15629/
State Accepted
Headers show

Comments

Gregory Szorc - June 26, 2016, 2:12 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1466907046 25200
#      Sat Jun 25 19:10:46 2016 -0700
# Node ID 802176b09678e1b52a8d110c19c261a58b2cafbb
# Parent  4903c4201049a504ed7ca47557a41a1c02e9391f
revset: implement match() in terms of matchany()

match() is the special case of a single element list being passed
to matchany() with the additional error checking that the revset
spec is defined. Change the implementation to remove the redundant
code and have match() call matchany().
Pierre-Yves David - June 26, 2016, 2:25 a.m.
On 06/26/2016 04:12 AM, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1466907046 25200
> #      Sat Jun 25 19:10:46 2016 -0700
> # Node ID 802176b09678e1b52a8d110c19c261a58b2cafbb
> # Parent  4903c4201049a504ed7ca47557a41a1c02e9391f
> revset: implement match() in terms of matchany()

Hooray for less duplicated code. Pushed, thanks.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2529,23 +2529,20 @@  def foldconcat(tree):
 def parse(spec, lookup=None):
     return _parsewith(spec, lookup=lookup)
 
 def posttreebuilthook(tree, repo):
     # hook for extensions to execute code on the optimized tree
     pass
 
 def match(ui, spec, repo=None):
+    """Create a matcher for a single revision spec."""
     if not spec:
         raise error.ParseError(_("empty query"))
-    lookup = None
-    if repo:
-        lookup = repo.__contains__
-    tree = parse(spec, lookup)
-    return _makematcher(ui, tree, repo)
+    return matchany(ui, [spec], repo=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