Patchwork [04,of,11,sparse,V3] match: move matchers from sparse into core

login
register
mail settings
Submitter Gregory Szorc
Date July 7, 2017, 1:18 a.m.
Message ID <1768212cea7afaa82188.1499390305@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/22076/
State Accepted
Headers show

Comments

Gregory Szorc - July 7, 2017, 1:18 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1499387964 25200
#      Thu Jul 06 17:39:24 2017 -0700
# Node ID 1768212cea7afaa821883d284690caad542c7af0
# Parent  1d856c7fb9c08bd71ed9bb802917d45f07fb8714
match: move matchers from sparse into core

The sparse extension contains some matcher types that are
generic and can exist in core.

As part of the move, the classes now inherit from basematcher.
always(), files(), and isexact() have been dropped because
they match the default implementations in basematcher.

Patch

diff --git a/hgext/sparse.py b/hgext/sparse.py
--- a/hgext/sparse.py
+++ b/hgext/sparse.py
@@ -75,7 +75,6 @@  certain files::
 from __future__ import absolute_import
 
 import collections
-import hashlib
 import os
 
 from mercurial.i18n import _
@@ -353,8 +352,8 @@  def _setupdirstate(ui):
 
             sparsematch = repo.sparsematch()
             if self.sparsematch != sparsematch or self.origignore != origignore:
-                self.func = unionmatcher([origignore,
-                                          negatematcher(sparsematch)])
+                self.func = matchmod.unionmatcher([
+                    origignore, matchmod.negatematcher(sparsematch)])
                 self.sparsematch = sparsematch
                 self.origignore = origignore
             return self.func
@@ -449,7 +448,8 @@  def _wraprepo(ui, repo):
                             include=includes, exclude=excludes,
                             default='relpath')
                         if subdirs:
-                            matcher = forceincludematcher(matcher, subdirs)
+                            matcher = matchmod.forceincludematcher(matcher,
+                                                                   subdirs)
                         matchers.append(matcher)
                 except IOError:
                     pass
@@ -460,11 +460,11 @@  def _wraprepo(ui, repo):
             elif len(matchers) == 1:
                 result = matchers[0]
             else:
-                result = unionmatcher(matchers)
+                result = matchmod.unionmatcher(matchers)
 
             if kwargs.get('includetemp', True):
                 tempincludes = sparse.readtemporaryincludes(self)
-                result = forceincludematcher(result, tempincludes)
+                result = matchmod.forceincludematcher(result, tempincludes)
 
             self._sparsematchercache[key] = result
 
@@ -862,83 +862,3 @@  def _verbose_output(ui, opts, profilecou
                          dropped)
             fm.condwrite(ui.verbose, 'files_conflicting',
                          'Files conflicting: %d\n', lookup)
-
-class forceincludematcher(object):
-    """A matcher that returns true for any of the forced includes before testing
-    against the actual matcher."""
-    def __init__(self, matcher, includes):
-        self._matcher = matcher
-        self._includes = includes
-
-    def __call__(self, value):
-        return value in self._includes or self._matcher(value)
-
-    def always(self):
-        return False
-
-    def files(self):
-        return []
-
-    def isexact(self):
-        return False
-
-    def anypats(self):
-        return True
-
-    def prefix(self):
-        return False
-
-    def __repr__(self):
-        return ('<forceincludematcher matcher=%r, includes=%r>' %
-                (self._matcher, sorted(self._includes)))
-
-class unionmatcher(object):
-    """A matcher that is the union of several matchers."""
-    def __init__(self, matchers):
-        self._matchers = matchers
-
-    def __call__(self, value):
-        for match in self._matchers:
-            if match(value):
-                return True
-        return False
-
-    def always(self):
-        return False
-
-    def files(self):
-        return []
-
-    def isexact(self):
-        return False
-
-    def anypats(self):
-        return True
-
-    def prefix(self):
-        return False
-
-    def __repr__(self):
-        return ('<unionmatcher matchers=%r>' % self._matchers)
-
-class negatematcher(object):
-    def __init__(self, matcher):
-        self._matcher = matcher
-
-    def __call__(self, value):
-        return not self._matcher(value)
-
-    def always(self):
-        return False
-
-    def files(self):
-        return []
-
-    def isexact(self):
-        return False
-
-    def anypats(self):
-        return True
-
-    def __repr__(self):
-        return ('<negatematcher matcher=%r>' % self._matcher)
diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -641,6 +641,59 @@  class subdirmatcher(basematcher):
         return ('<subdirmatcher path=%r, matcher=%r>' %
                 (self._path, self._matcher))
 
+class forceincludematcher(basematcher):
+    """A matcher that returns true for any of the forced includes before testing
+    against the actual matcher."""
+    def __init__(self, matcher, includes):
+        self._matcher = matcher
+        self._includes = includes
+
+    def __call__(self, value):
+        return value in self._includes or self._matcher(value)
+
+    def anypats(self):
+        return True
+
+    def prefix(self):
+        return False
+
+    def __repr__(self):
+        return ('<forceincludematcher matcher=%r, includes=%r>' %
+                (self._matcher, sorted(self._includes)))
+
+class unionmatcher(basematcher):
+    """A matcher that is the union of several matchers."""
+    def __init__(self, matchers):
+        self._matchers = matchers
+
+    def __call__(self, value):
+        for match in self._matchers:
+            if match(value):
+                return True
+        return False
+
+    def anypats(self):
+        return True
+
+    def prefix(self):
+        return False
+
+    def __repr__(self):
+        return ('<unionmatcher matchers=%r>' % self._matchers)
+
+class negatematcher(basematcher):
+    def __init__(self, matcher):
+        self._matcher = matcher
+
+    def __call__(self, value):
+        return not self._matcher(value)
+
+    def anypats(self):
+        return True
+
+    def __repr__(self):
+        return ('<negatematcher matcher=%r>' % self._matcher)
+
 def patkind(pattern, default=None):
     '''If pattern is 'kind:pat' with a known kind, return kind.'''
     return _patsplit(pattern, default)[0]