Show More
@@ -116,9 +116,10 b' def match(root, cwd, patterns, include=N' | |||
|
116 | 116 | the same directory |
|
117 | 117 | '<something>' - a pattern of the specified default type |
|
118 | 118 | """ |
|
119 |
return matcher(root, cwd, patterns, include=include, |
|
|
120 |
default=default, exact=exact, |
|
|
121 |
listsubrepos=listsubrepos, |
|
|
119 | return matcher(root, cwd, _donormalize, patterns, include=include, | |
|
120 | exclude=exclude, default=default, exact=exact, | |
|
121 | auditor=auditor, ctx=ctx, listsubrepos=listsubrepos, | |
|
122 | warn=warn, badfn=badfn) | |
|
122 | 123 | |
|
123 | 124 | def icasefsmatch(root, cwd, patterns, include=None, exclude=None, |
|
124 | 125 | default='glob', auditor=None, ctx=None, |
@@ -126,9 +127,28 b' def icasefsmatch(root, cwd, patterns, in' | |||
|
126 | 127 | """A matcher for wdir on case insensitive filesystems, which normalizes the |
|
127 | 128 | given patterns to the case in the filesystem. |
|
128 | 129 | """ |
|
129 | return icasefsmatcher(root, cwd, patterns, include=include, exclude=exclude, | |
|
130 | default=default, auditor=auditor, ctx=ctx, | |
|
131 | listsubrepos=listsubrepos, badfn=badfn) | |
|
130 | dirstate = ctx.repo().dirstate | |
|
131 | dsnormalize = dirstate.normalize | |
|
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 | 153 | def exact(root, cwd, files, badfn=None): |
|
134 | 154 | return match(root, cwd, files, exact=True, badfn=badfn) |
@@ -187,9 +207,9 b' def _donormalize(patterns, default, root' | |||
|
187 | 207 | |
|
188 | 208 | class matcher(object): |
|
189 | 209 | |
|
190 |
def __init__(self, root, cwd, patterns, include=None, |
|
|
191 |
default='glob', exact=False, auditor=None, |
|
|
192 | listsubrepos=False, warn=None, badfn=None): | |
|
210 | def __init__(self, root, cwd, normalize, patterns, include=None, | |
|
211 | exclude=None, default='glob', exact=False, auditor=None, | |
|
212 | ctx=None, listsubrepos=False, warn=None, badfn=None): | |
|
193 | 213 | if include is None: |
|
194 | 214 | include = [] |
|
195 | 215 | if exclude is None: |
@@ -213,8 +233,7 b' class matcher(object):' | |||
|
213 | 233 | |
|
214 | 234 | matchfns = [] |
|
215 | 235 | if include: |
|
216 |
kindpats = |
|
|
217 | warn) | |
|
236 | kindpats = normalize(include, 'glob', root, cwd, auditor, warn) | |
|
218 | 237 | self.includepat, im = _buildmatch(ctx, kindpats, '(?:/|$)', |
|
219 | 238 | listsubrepos, root) |
|
220 | 239 | roots, dirs = _rootsanddirs(kindpats) |
@@ -222,8 +241,7 b' class matcher(object):' | |||
|
222 | 241 | self._includedirs.update(dirs) |
|
223 | 242 | matchfns.append(im) |
|
224 | 243 | if exclude: |
|
225 |
kindpats = |
|
|
226 | warn) | |
|
244 | kindpats = normalize(exclude, 'glob', root, cwd, auditor, warn) | |
|
227 | 245 | self.excludepat, em = _buildmatch(ctx, kindpats, '(?:/|$)', |
|
228 | 246 | listsubrepos, root) |
|
229 | 247 | if not _anypats(kindpats): |
@@ -241,8 +259,7 b' class matcher(object):' | |||
|
241 | 259 | self._files = list(patterns) |
|
242 | 260 | matchfns.append(self.exact) |
|
243 | 261 | elif patterns: |
|
244 |
kindpats = |
|
|
245 | warn) | |
|
262 | kindpats = normalize(patterns, default, root, cwd, auditor, warn) | |
|
246 | 263 | if not _kindpatsalwaysmatch(kindpats): |
|
247 | 264 | self._files = _explicitfiles(kindpats) |
|
248 | 265 | self._anypats = self._anypats or _anypats(kindpats) |
@@ -365,9 +382,6 b' class matcher(object):' | |||
|
365 | 382 | def prefix(self): |
|
366 | 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 | 385 | class subdirmatcher(matcher): |
|
372 | 386 | """Adapt a matcher to work on a subdirectory only. |
|
373 | 387 | |
@@ -441,30 +455,13 b' class subdirmatcher(matcher):' | |||
|
441 | 455 | |
|
442 | 456 | class icasefsmatcher(matcher): |
|
443 | 457 | |
|
444 |
def __init__(self, root, cwd, patterns, include, exclude, |
|
|
445 | ctx, listsubrepos=False, badfn=None): | |
|
458 | def __init__(self, root, cwd, normalize, patterns, include, exclude, | |
|
459 | default, auditor, ctx, listsubrepos=False, badfn=None): | |
|
446 | 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): | |
|
454 | kp = super(icasefsmatcher, self)._normalize(patterns, default, root, | |
|
455 | cwd, auditor, warn) | |
|
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 | |
|
462 | init(root, cwd, normalize=normalize, patterns=patterns, include=include, | |
|
463 | exclude=exclude, default=default, auditor=auditor, | |
|
464 | ctx=ctx, listsubrepos=listsubrepos, badfn=badfn) | |
|
468 | 465 | |
|
469 | 466 | def patkind(pattern, default=None): |
|
470 | 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