143 return kindpats |
143 return kindpats |
144 |
144 |
145 if exact: |
145 if exact: |
146 m = exactmatcher(root, cwd, patterns, badfn) |
146 m = exactmatcher(root, cwd, patterns, badfn) |
147 else: |
147 else: |
148 m = patternmatcher(root, cwd, normalize, patterns, include=None, |
148 m = patternmatcher(root, cwd, normalize, patterns, default=default, |
149 default=default, auditor=auditor, ctx=ctx, |
149 auditor=auditor, ctx=ctx, listsubrepos=listsubrepos, |
150 listsubrepos=listsubrepos, warn=warn, badfn=badfn) |
150 warn=warn, badfn=badfn) |
151 if include: |
151 if include: |
152 im = includematcher(root, cwd, normalize, include, auditor=auditor, |
152 im = includematcher(root, cwd, normalize, include, auditor=auditor, |
153 ctx=ctx, listsubrepos=listsubrepos, warn=warn, |
153 ctx=ctx, listsubrepos=listsubrepos, warn=warn, |
154 badfn=None) |
154 badfn=None) |
155 m = intersectmatchers(m, im) |
155 m = intersectmatchers(m, im) |
311 def prefix(self): |
311 def prefix(self): |
312 return not self.always() and not self.isexact() and not self.anypats() |
312 return not self.always() and not self.isexact() and not self.anypats() |
313 |
313 |
314 class patternmatcher(basematcher): |
314 class patternmatcher(basematcher): |
315 |
315 |
316 def __init__(self, root, cwd, normalize, patterns, include=None, |
316 def __init__(self, root, cwd, normalize, patterns, default='glob', |
317 default='glob', auditor=None, ctx=None, |
317 auditor=None, ctx=None, listsubrepos=False, warn=None, |
318 listsubrepos=False, warn=None, badfn=None): |
318 badfn=None): |
319 super(patternmatcher, self).__init__(root, cwd, badfn, |
319 super(patternmatcher, self).__init__(root, cwd, badfn, |
320 relativeuipath=bool(include or |
320 relativeuipath=bool(patterns)) |
321 patterns)) |
321 |
322 if include is None: |
322 self._anypats = False |
323 include = [] |
|
324 |
|
325 self._anypats = bool(include) |
|
326 self._anyincludepats = False |
|
327 self._always = False |
323 self._always = False |
328 self.patternspat = None |
324 self.patternspat = None |
329 self.includepat = None |
|
330 |
|
331 # roots are directories which are recursively included. |
|
332 self._includeroots = set() |
|
333 # dirs are directories which are non-recursively included. |
|
334 self._includedirs = set() |
|
335 |
325 |
336 matchfns = [] |
326 matchfns = [] |
337 if include: |
|
338 kindpats = normalize(include, 'glob', root, cwd, auditor, warn) |
|
339 self.includepat, im = _buildmatch(ctx, kindpats, '(?:/|$)', |
|
340 listsubrepos, root) |
|
341 self._anyincludepats = _anypats(kindpats) |
|
342 roots, dirs = _rootsanddirs(kindpats) |
|
343 self._includeroots.update(roots) |
|
344 self._includedirs.update(dirs) |
|
345 matchfns.append(im) |
|
346 if patterns: |
327 if patterns: |
347 kindpats = normalize(patterns, default, root, cwd, auditor, warn) |
328 kindpats = normalize(patterns, default, root, cwd, auditor, warn) |
348 if not _kindpatsalwaysmatch(kindpats): |
329 if not _kindpatsalwaysmatch(kindpats): |
349 self._files = _explicitfiles(kindpats) |
330 self._files = _explicitfiles(kindpats) |
350 self._anypats = self._anypats or _anypats(kindpats) |
331 self._anypats = self._anypats or _anypats(kindpats) |
371 return set(util.dirs(self._fileset)) | {'.'} |
352 return set(util.dirs(self._fileset)) | {'.'} |
372 |
353 |
373 def visitdir(self, dir): |
354 def visitdir(self, dir): |
374 if self.prefix() and dir in self._fileset: |
355 if self.prefix() and dir in self._fileset: |
375 return 'all' |
356 return 'all' |
376 if self._includeroots or self._includedirs: |
|
377 if (not self._anyincludepats and |
|
378 dir in self._includeroots): |
|
379 # The condition above is essentially self.prefix() for includes |
|
380 return 'all' |
|
381 if ('.' not in self._includeroots and |
|
382 dir not in self._includeroots and |
|
383 dir not in self._includedirs and |
|
384 not any(parent in self._includeroots |
|
385 for parent in util.finddirs(dir))): |
|
386 return False |
|
387 return (not self._fileset or |
357 return (not self._fileset or |
388 '.' in self._fileset or |
358 '.' in self._fileset or |
389 dir in self._fileset or |
359 dir in self._fileset or |
390 dir in self._dirs or |
360 dir in self._dirs or |
391 any(parentdir in self._fileset |
361 any(parentdir in self._fileset |
396 |
366 |
397 def always(self): |
367 def always(self): |
398 return self._always |
368 return self._always |
399 |
369 |
400 def __repr__(self): |
370 def __repr__(self): |
401 return ('<patternmatcher patterns=%r, includes=%r>' % |
371 return ('<patternmatcher patterns=%r>' % self.patternspat) |
402 (self.patternspat, self.includepat)) |
|
403 |
372 |
404 class includematcher(basematcher): |
373 class includematcher(basematcher): |
405 |
374 |
406 def __init__(self, root, cwd, normalize, include, auditor=None, ctx=None, |
375 def __init__(self, root, cwd, normalize, include, auditor=None, ctx=None, |
407 listsubrepos=False, warn=None, badfn=None): |
376 listsubrepos=False, warn=None, badfn=None): |