##// END OF EJS Templates
match: move _normalize() into the match class...
Matt Harbison -
r24789:0b1577c8 default
parent child Browse files
Show More
@@ -79,11 +79,11 b' class match(object):'
79
79
80 matchfns = []
80 matchfns = []
81 if include:
81 if include:
82 kindpats = _normalize(include, 'glob', root, cwd, auditor)
82 kindpats = self._normalize(include, 'glob', root, cwd, auditor)
83 self.includepat, im = _buildmatch(ctx, kindpats, '(?:/|$)')
83 self.includepat, im = _buildmatch(ctx, kindpats, '(?:/|$)')
84 matchfns.append(im)
84 matchfns.append(im)
85 if exclude:
85 if exclude:
86 kindpats = _normalize(exclude, 'glob', root, cwd, auditor)
86 kindpats = self._normalize(exclude, 'glob', root, cwd, auditor)
87 self.excludepat, em = _buildmatch(ctx, kindpats, '(?:/|$)')
87 self.excludepat, em = _buildmatch(ctx, kindpats, '(?:/|$)')
88 matchfns.append(lambda f: not em(f))
88 matchfns.append(lambda f: not em(f))
89 if exact:
89 if exact:
@@ -93,7 +93,7 b' class match(object):'
93 self._files = list(patterns)
93 self._files = list(patterns)
94 matchfns.append(self.exact)
94 matchfns.append(self.exact)
95 elif patterns:
95 elif patterns:
96 kindpats = _normalize(patterns, default, root, cwd, auditor)
96 kindpats = self._normalize(patterns, default, root, cwd, auditor)
97 if not _kindpatsalwaysmatch(kindpats):
97 if not _kindpatsalwaysmatch(kindpats):
98 self._files = _roots(kindpats)
98 self._files = _roots(kindpats)
99 self._anypats = self._anypats or _anypats(kindpats)
99 self._anypats = self._anypats or _anypats(kindpats)
@@ -189,6 +189,31 b' class match(object):'
189 def isexact(self):
189 def isexact(self):
190 return self.matchfn == self.exact
190 return self.matchfn == self.exact
191
191
192 def _normalize(self, patterns, default, root, cwd, auditor):
193 '''Convert 'kind:pat' from the patterns list to tuples with kind and
194 normalized and rooted patterns and with listfiles expanded.'''
195 kindpats = []
196 for kind, pat in [_patsplit(p, default) for p in patterns]:
197 if kind in ('glob', 'relpath'):
198 pat = pathutil.canonpath(root, cwd, pat, auditor)
199 elif kind in ('relglob', 'path'):
200 pat = util.normpath(pat)
201 elif kind in ('listfile', 'listfile0'):
202 try:
203 files = util.readfile(pat)
204 if kind == 'listfile0':
205 files = files.split('\0')
206 else:
207 files = files.splitlines()
208 files = [f for f in files if f]
209 except EnvironmentError:
210 raise util.Abort(_("unable to read file list (%s)") % pat)
211 kindpats += self._normalize(files, default, root, cwd, auditor)
212 continue
213 # else: re or relre - which cannot be normalized
214 kindpats.append((kind, pat))
215 return kindpats
216
192 def exact(root, cwd, files):
217 def exact(root, cwd, files):
193 return match(root, cwd, files, exact=True)
218 return match(root, cwd, files, exact=True)
194
219
@@ -398,31 +423,6 b' def _buildregexmatch(kindpats, globsuffi'
398 raise util.Abort(_("invalid pattern (%s): %s") % (k, p))
423 raise util.Abort(_("invalid pattern (%s): %s") % (k, p))
399 raise util.Abort(_("invalid pattern"))
424 raise util.Abort(_("invalid pattern"))
400
425
401 def _normalize(patterns, default, root, cwd, auditor):
402 '''Convert 'kind:pat' from the patterns list to tuples with kind and
403 normalized and rooted patterns and with listfiles expanded.'''
404 kindpats = []
405 for kind, pat in [_patsplit(p, default) for p in patterns]:
406 if kind in ('glob', 'relpath'):
407 pat = pathutil.canonpath(root, cwd, pat, auditor)
408 elif kind in ('relglob', 'path'):
409 pat = util.normpath(pat)
410 elif kind in ('listfile', 'listfile0'):
411 try:
412 files = util.readfile(pat)
413 if kind == 'listfile0':
414 files = files.split('\0')
415 else:
416 files = files.splitlines()
417 files = [f for f in files if f]
418 except EnvironmentError:
419 raise util.Abort(_("unable to read file list (%s)") % pat)
420 kindpats += _normalize(files, default, root, cwd, auditor)
421 continue
422 # else: re or relre - which cannot be normalized
423 kindpats.append((kind, pat))
424 return kindpats
425
426 def _roots(kindpats):
426 def _roots(kindpats):
427 '''return roots and exact explicitly listed files from patterns
427 '''return roots and exact explicitly listed files from patterns
428
428
General Comments 0
You need to be logged in to leave comments. Login now