match: replace icasefsmatch() function by flag to regular match()
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 18 May 2017 22:20:59 -0700
changeset 32401 284b18303f61
parent 32400 8802c63599e1
child 32402 c8e10565a113
match: replace icasefsmatch() function by flag to regular match() match() will soon gain more logic and we don't want to duplicate that in icasefsmatch(), so merge the two functions instead and use a flag to get case-insensitive behavior.
mercurial/context.py
mercurial/match.py
--- a/mercurial/context.py	Thu May 18 16:48:02 2017 -0700
+++ b/mercurial/context.py	Thu May 18 22:20:59 2017 -0700
@@ -1593,13 +1593,11 @@
 
         # Only a case insensitive filesystem needs magic to translate user input
         # to actual case in the filesystem.
-        matcherfunc = matchmod.match
-        if not util.fscasesensitive(r.root):
-            matcherfunc = matchmod.icasefsmatch
-        return matcherfunc(r.root, r.getcwd(), pats,
-                           include, exclude, default,
-                           auditor=r.auditor, ctx=self,
-                           listsubrepos=listsubrepos, badfn=badfn)
+        icasefs = not util.fscasesensitive(r.root)
+        return matchmod.match(r.root, r.getcwd(), pats, include, exclude,
+                              default, auditor=r.auditor, ctx=self,
+                              listsubrepos=listsubrepos, badfn=badfn,
+                              icasefs=icasefs)
 
     def _filtersuspectsymlink(self, files):
         if not files or self._repo.dirstate._checklink:
--- a/mercurial/match.py	Thu May 18 16:48:02 2017 -0700
+++ b/mercurial/match.py	Thu May 18 22:20:59 2017 -0700
@@ -86,7 +86,7 @@
 
 def match(root, cwd, patterns, include=None, exclude=None, default='glob',
           exact=False, auditor=None, ctx=None, listsubrepos=False, warn=None,
-          badfn=None):
+          badfn=None, icasefs=False):
     """build an object to match a set of file patterns
 
     arguments:
@@ -99,6 +99,8 @@
     exact - patterns are actually filenames (include/exclude still apply)
     warn - optional function used for printing warnings
     badfn - optional bad() callback for this matcher instead of the default
+    icasefs - make a matcher for wdir on case insensitive filesystems, which
+        normalizes the given patterns to the case in the filesystem
 
     a pattern is one of:
     'glob:<glob>' - a glob relative to cwd
@@ -116,39 +118,31 @@
                           the same directory
     '<something>' - a pattern of the specified default type
     """
-    return matcher(root, cwd, _donormalize, patterns, include=include,
+    normalize = _donormalize
+    if icasefs:
+        dirstate = ctx.repo().dirstate
+        dsnormalize = dirstate.normalize
+
+        def normalize(patterns, default, root, cwd, auditor, warn):
+            kp = _donormalize(patterns, default, root, cwd, auditor, warn)
+            kindpats = []
+            for kind, pats, source in kp:
+                if kind not in ('re', 'relre'):  # regex can't be normalized
+                    p = pats
+                    pats = dsnormalize(pats)
+
+                    # Preserve the original to handle a case only rename.
+                    if p != pats and p in dirstate:
+                        kindpats.append((kind, p, source))
+
+                kindpats.append((kind, pats, source))
+            return kindpats
+
+    return matcher(root, cwd, normalize, patterns, include=include,
                    exclude=exclude, default=default, exact=exact,
                    auditor=auditor, ctx=ctx, listsubrepos=listsubrepos,
                    warn=warn, badfn=badfn)
 
-def icasefsmatch(root, cwd, patterns, include=None, exclude=None,
-                 default='glob', auditor=None, ctx=None,
-                 listsubrepos=False, badfn=None):
-    """A matcher for wdir on case insensitive filesystems, which normalizes the
-    given patterns to the case in the filesystem.
-    """
-    dirstate = ctx.repo().dirstate
-    dsnormalize = dirstate.normalize
-
-    def normalize(patterns, default, root, cwd, auditor, warn):
-        kp = _donormalize(patterns, default, root, cwd, auditor, warn)
-        kindpats = []
-        for kind, pats, source in kp:
-            if kind not in ('re', 'relre'):  # regex can't be normalized
-                p = pats
-                pats = dsnormalize(pats)
-
-                # Preserve the original to handle a case only rename.
-                if p != pats and p in dirstate:
-                    kindpats.append((kind, p, source))
-
-            kindpats.append((kind, pats, source))
-        return kindpats
-
-    return matcher(root, cwd, normalize, patterns=patterns, include=include,
-                   exclude=exclude, default=default, auditor=auditor, ctx=ctx,
-                   listsubrepos=listsubrepos, badfn=badfn)
-
 def exact(root, cwd, files, badfn=None):
     return match(root, cwd, files, exact=True, badfn=badfn)