##// END OF EJS Templates
match: pass in normalize() function to matchers...
Martin von Zweigbergk -
r32398:1c1f7c94 default
parent child Browse files
Show More
@@ -116,9 +116,10 b' def match(root, cwd, patterns, include=N'
116 the same directory
116 the same directory
117 '<something>' - a pattern of the specified default type
117 '<something>' - a pattern of the specified default type
118 """
118 """
119 return matcher(root, cwd, patterns, include=include, exclude=exclude,
119 return matcher(root, cwd, _donormalize, patterns, include=include,
120 default=default, exact=exact, auditor=auditor, ctx=ctx,
120 exclude=exclude, default=default, exact=exact,
121 listsubrepos=listsubrepos, warn=warn, badfn=badfn)
121 auditor=auditor, ctx=ctx, listsubrepos=listsubrepos,
122 warn=warn, badfn=badfn)
122
123
123 def icasefsmatch(root, cwd, patterns, include=None, exclude=None,
124 def icasefsmatch(root, cwd, patterns, include=None, exclude=None,
124 default='glob', auditor=None, ctx=None,
125 default='glob', auditor=None, ctx=None,
@@ -126,9 +127,28 b' def icasefsmatch(root, cwd, patterns, in'
126 """A matcher for wdir on case insensitive filesystems, which normalizes the
127 """A matcher for wdir on case insensitive filesystems, which normalizes the
127 given patterns to the case in the filesystem.
128 given patterns to the case in the filesystem.
128 """
129 """
129 return icasefsmatcher(root, cwd, patterns, include=include, exclude=exclude,
130 dirstate = ctx.repo().dirstate
130 default=default, auditor=auditor, ctx=ctx,
131 dsnormalize = dirstate.normalize
131 listsubrepos=listsubrepos, badfn=badfn)
132
133 def normalize(patterns, default, root, cwd, auditor, warn):
134 kp = _donormalize(patterns, default, root, cwd, auditor, warn)
135 kindpats = []
136 for kind, pats, source in kp:
137 if kind not in ('re', 'relre'): # regex can't be normalized
138 p = pats
139 pats = dsnormalize(pats)
140
141 # Preserve the original to handle a case only rename.
142 if p != pats and p in dirstate:
143 kindpats.append((kind, p, source))
144
145 kindpats.append((kind, pats, source))
146 return kindpats
147
148 return icasefsmatcher(root, cwd, normalize, patterns=patterns,
149 include=include, exclude=exclude, default=default,
150 auditor=auditor, ctx=ctx, listsubrepos=listsubrepos,
151 badfn=badfn)
132
152
133 def exact(root, cwd, files, badfn=None):
153 def exact(root, cwd, files, badfn=None):
134 return match(root, cwd, files, exact=True, badfn=badfn)
154 return match(root, cwd, files, exact=True, badfn=badfn)
@@ -187,9 +207,9 b' def _donormalize(patterns, default, root'
187
207
188 class matcher(object):
208 class matcher(object):
189
209
190 def __init__(self, root, cwd, patterns, include=None, exclude=None,
210 def __init__(self, root, cwd, normalize, patterns, include=None,
191 default='glob', exact=False, auditor=None, ctx=None,
211 exclude=None, default='glob', exact=False, auditor=None,
192 listsubrepos=False, warn=None, badfn=None):
212 ctx=None, listsubrepos=False, warn=None, badfn=None):
193 if include is None:
213 if include is None:
194 include = []
214 include = []
195 if exclude is None:
215 if exclude is None:
@@ -213,8 +233,7 b' class matcher(object):'
213
233
214 matchfns = []
234 matchfns = []
215 if include:
235 if include:
216 kindpats = self._normalize(include, 'glob', root, cwd, auditor,
236 kindpats = normalize(include, 'glob', root, cwd, auditor, warn)
217 warn)
218 self.includepat, im = _buildmatch(ctx, kindpats, '(?:/|$)',
237 self.includepat, im = _buildmatch(ctx, kindpats, '(?:/|$)',
219 listsubrepos, root)
238 listsubrepos, root)
220 roots, dirs = _rootsanddirs(kindpats)
239 roots, dirs = _rootsanddirs(kindpats)
@@ -222,8 +241,7 b' class matcher(object):'
222 self._includedirs.update(dirs)
241 self._includedirs.update(dirs)
223 matchfns.append(im)
242 matchfns.append(im)
224 if exclude:
243 if exclude:
225 kindpats = self._normalize(exclude, 'glob', root, cwd, auditor,
244 kindpats = normalize(exclude, 'glob', root, cwd, auditor, warn)
226 warn)
227 self.excludepat, em = _buildmatch(ctx, kindpats, '(?:/|$)',
245 self.excludepat, em = _buildmatch(ctx, kindpats, '(?:/|$)',
228 listsubrepos, root)
246 listsubrepos, root)
229 if not _anypats(kindpats):
247 if not _anypats(kindpats):
@@ -241,8 +259,7 b' class matcher(object):'
241 self._files = list(patterns)
259 self._files = list(patterns)
242 matchfns.append(self.exact)
260 matchfns.append(self.exact)
243 elif patterns:
261 elif patterns:
244 kindpats = self._normalize(patterns, default, root, cwd, auditor,
262 kindpats = normalize(patterns, default, root, cwd, auditor, warn)
245 warn)
246 if not _kindpatsalwaysmatch(kindpats):
263 if not _kindpatsalwaysmatch(kindpats):
247 self._files = _explicitfiles(kindpats)
264 self._files = _explicitfiles(kindpats)
248 self._anypats = self._anypats or _anypats(kindpats)
265 self._anypats = self._anypats or _anypats(kindpats)
@@ -365,9 +382,6 b' class matcher(object):'
365 def prefix(self):
382 def prefix(self):
366 return not self.always() and not self.isexact() and not self.anypats()
383 return not self.always() and not self.isexact() and not self.anypats()
367
384
368 def _normalize(self, patterns, default, root, cwd, auditor, warn):
369 return _donormalize(patterns, default, root, cwd, auditor, warn)
370
371 class subdirmatcher(matcher):
385 class subdirmatcher(matcher):
372 """Adapt a matcher to work on a subdirectory only.
386 """Adapt a matcher to work on a subdirectory only.
373
387
@@ -441,30 +455,13 b' class subdirmatcher(matcher):'
441
455
442 class icasefsmatcher(matcher):
456 class icasefsmatcher(matcher):
443
457
444 def __init__(self, root, cwd, patterns, include, exclude, default, auditor,
458 def __init__(self, root, cwd, normalize, patterns, include, exclude,
445 ctx, listsubrepos=False, badfn=None):
459 default, auditor, ctx, listsubrepos=False, badfn=None):
446 init = super(icasefsmatcher, self).__init__
460 init = super(icasefsmatcher, self).__init__
447 self._dirstate = ctx.repo().dirstate
448 self._dsnormalize = self._dirstate.normalize
449
450 init(root, cwd, patterns, include, exclude, default, auditor=auditor,
451 ctx=ctx, listsubrepos=listsubrepos, badfn=badfn)
452
461
453 def _normalize(self, patterns, default, root, cwd, auditor, warn):
462 init(root, cwd, normalize=normalize, patterns=patterns, include=include,
454 kp = super(icasefsmatcher, self)._normalize(patterns, default, root,
463 exclude=exclude, default=default, auditor=auditor,
455 cwd, auditor, warn)
464 ctx=ctx, listsubrepos=listsubrepos, badfn=badfn)
456 kindpats = []
457 for kind, pats, source in kp:
458 if kind not in ('re', 'relre'): # regex can't be normalized
459 p = pats
460 pats = self._dsnormalize(pats)
461
462 # Preserve the original to handle a case only rename.
463 if p != pats and p in self._dirstate:
464 kindpats.append((kind, p, source))
465
466 kindpats.append((kind, pats, source))
467 return kindpats
468
465
469 def patkind(pattern, default=None):
466 def patkind(pattern, default=None):
470 '''If pattern is 'kind:pat' with a known kind, return kind.'''
467 '''If pattern is 'kind:pat' with a known kind, return kind.'''
General Comments 0
You need to be logged in to leave comments. Login now