Patchwork [4,of,5] match: move normalize() call out of matcher constructors

login
register
mail settings
Submitter via Mercurial-devel
Date May 30, 2017, 6:50 a.m.
Message ID <7a00646bfff19e958992.1496127034@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/21060/
State Accepted
Headers show

Comments

via Mercurial-devel - May 30, 2017, 6:50 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1495223265 25200
#      Fri May 19 12:47:45 2017 -0700
# Node ID 7a00646bfff19e9589927a5c0fa46502baaea2aa
# Parent  f563ef561ef7f41b2628039c52e17b335e3764e3
match: move normalize() call out of matcher constructors

By passing in the result of the normalize() call, we prepare for
moving the special handling of patterns that always match out of the
patternmatcher.

It also lets us remove many of the arguments from the matcher, because
they were passed only the the normalize function (we could have
removed the arguments by binding them to the function instead of
moving the normalize() call out).

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -145,9 +145,9 @@ 
     if exact:
         m = exactmatcher(root, cwd, patterns, badfn)
     elif patterns:
-        m = patternmatcher(root, cwd, normalize, patterns, default=default,
-                           auditor=auditor, ctx=ctx, listsubrepos=listsubrepos,
-                           warn=warn, badfn=badfn)
+        kindpats = normalize(patterns, default, root, cwd, auditor, warn)
+        m = patternmatcher(root, cwd, kindpats, ctx=ctx,
+                           listsubrepos=listsubrepos, badfn=badfn)
     else:
         # It's a little strange that no patterns means to match everything.
         # Consider changing this to match nothing (probably adding a
@@ -155,14 +155,14 @@ 
         m = alwaysmatcher(root, cwd, badfn)
 
     if include:
-        im = includematcher(root, cwd, normalize, include, auditor=auditor,
-                            ctx=ctx, listsubrepos=listsubrepos, warn=warn,
-                            badfn=None)
+        kindpats = normalize(include, 'glob', root, cwd, auditor, warn)
+        im = includematcher(root, cwd, kindpats, ctx=ctx,
+                            listsubrepos=listsubrepos, badfn=None)
         m = intersectmatchers(m, im)
     if exclude:
-        em = includematcher(root, cwd, normalize, exclude, auditor=auditor,
-                            ctx=ctx, listsubrepos=listsubrepos, warn=warn,
-                            badfn=None)
+        kindpats = normalize(exclude, 'glob', root, cwd, auditor, warn)
+        em = includematcher(root, cwd, kindpats, ctx=ctx,
+                            listsubrepos=listsubrepos, badfn=None)
         m = differencematcher(m, em)
     return m
 
@@ -338,12 +338,10 @@ 
 
 class patternmatcher(basematcher):
 
-    def __init__(self, root, cwd, normalize, patterns, default='glob',
-                 auditor=None, ctx=None, listsubrepos=False, warn=None,
+    def __init__(self, root, cwd, kindpats, ctx=None, listsubrepos=False,
                  badfn=None):
         super(patternmatcher, self).__init__(root, cwd, badfn)
 
-        kindpats = normalize(patterns, default, root, cwd, auditor, warn)
         if not _kindpatsalwaysmatch(kindpats):
             self._files = _explicitfiles(kindpats)
             self._anypats = _anypats(kindpats)
@@ -383,11 +381,10 @@ 
 
 class includematcher(basematcher):
 
-    def __init__(self, root, cwd, normalize, include, auditor=None, ctx=None,
-                 listsubrepos=False, warn=None, badfn=None):
+    def __init__(self, root, cwd, kindpats, ctx=None, listsubrepos=False,
+                 badfn=None):
         super(includematcher, self).__init__(root, cwd, badfn)
 
-        kindpats = normalize(include, 'glob', root, cwd, auditor, warn)
         self.includepat, im = _buildmatch(ctx, kindpats, '(?:/|$)',
                                           listsubrepos, root)
         self._anypats = _anypats(kindpats)