equal
deleted
inserted
replaced
11 import os |
11 import os |
12 import re |
12 import re |
13 |
13 |
14 from .i18n import _ |
14 from .i18n import _ |
15 from . import ( |
15 from . import ( |
|
16 encoding, |
16 error, |
17 error, |
17 pathutil, |
18 pathutil, |
18 util, |
19 util, |
19 ) |
20 ) |
20 |
21 |
343 |
344 |
344 def visitdir(self, dir): |
345 def visitdir(self, dir): |
345 return 'all' |
346 return 'all' |
346 |
347 |
347 def __repr__(self): |
348 def __repr__(self): |
348 return '<alwaysmatcher>' |
349 return r'<alwaysmatcher>' |
349 |
350 |
350 class nevermatcher(basematcher): |
351 class nevermatcher(basematcher): |
351 '''Matches nothing.''' |
352 '''Matches nothing.''' |
352 |
353 |
353 def __init__(self, root, cwd, badfn=None): |
354 def __init__(self, root, cwd, badfn=None): |
366 |
367 |
367 def visitdir(self, dir): |
368 def visitdir(self, dir): |
368 return False |
369 return False |
369 |
370 |
370 def __repr__(self): |
371 def __repr__(self): |
371 return '<nevermatcher>' |
372 return r'<nevermatcher>' |
372 |
373 |
373 class patternmatcher(basematcher): |
374 class patternmatcher(basematcher): |
374 |
375 |
375 def __init__(self, root, cwd, kindpats, ctx=None, listsubrepos=False, |
376 def __init__(self, root, cwd, kindpats, ctx=None, listsubrepos=False, |
376 badfn=None): |
377 badfn=None): |
395 for parentdir in util.finddirs(dir))) |
396 for parentdir in util.finddirs(dir))) |
396 |
397 |
397 def prefix(self): |
398 def prefix(self): |
398 return self._prefix |
399 return self._prefix |
399 |
400 |
|
401 @encoding.strmethod |
400 def __repr__(self): |
402 def __repr__(self): |
401 return ('<patternmatcher patterns=%r>' % self._pats) |
403 return ('<patternmatcher patterns=%r>' % self._pats) |
402 |
404 |
403 class includematcher(basematcher): |
405 class includematcher(basematcher): |
404 |
406 |
422 dir in self._roots or |
424 dir in self._roots or |
423 dir in self._dirs or |
425 dir in self._dirs or |
424 any(parentdir in self._roots |
426 any(parentdir in self._roots |
425 for parentdir in util.finddirs(dir))) |
427 for parentdir in util.finddirs(dir))) |
426 |
428 |
|
429 @encoding.strmethod |
427 def __repr__(self): |
430 def __repr__(self): |
428 return ('<includematcher includes=%r>' % self._pats) |
431 return ('<includematcher includes=%r>' % self._pats) |
429 |
432 |
430 class exactmatcher(basematcher): |
433 class exactmatcher(basematcher): |
431 '''Matches the input files exactly. They are interpreted as paths, not |
434 '''Matches the input files exactly. They are interpreted as paths, not |
450 return dir in self._dirs |
453 return dir in self._dirs |
451 |
454 |
452 def isexact(self): |
455 def isexact(self): |
453 return True |
456 return True |
454 |
457 |
|
458 @encoding.strmethod |
455 def __repr__(self): |
459 def __repr__(self): |
456 return ('<exactmatcher files=%r>' % self._files) |
460 return ('<exactmatcher files=%r>' % self._files) |
457 |
461 |
458 class differencematcher(basematcher): |
462 class differencematcher(basematcher): |
459 '''Composes two matchers by matching if the first matches and the second |
463 '''Composes two matchers by matching if the first matches and the second |
490 return bool(self._m1.visitdir(dir)) |
494 return bool(self._m1.visitdir(dir)) |
491 |
495 |
492 def isexact(self): |
496 def isexact(self): |
493 return self._m1.isexact() |
497 return self._m1.isexact() |
494 |
498 |
|
499 @encoding.strmethod |
495 def __repr__(self): |
500 def __repr__(self): |
496 return ('<differencematcher m1=%r, m2=%r>' % (self._m1, self._m2)) |
501 return ('<differencematcher m1=%r, m2=%r>' % (self._m1, self._m2)) |
497 |
502 |
498 def intersectmatchers(m1, m2): |
503 def intersectmatchers(m1, m2): |
499 '''Composes two matchers by matching if both of them match. |
504 '''Composes two matchers by matching if both of them match. |
556 return self._m1.always() and self._m2.always() |
561 return self._m1.always() and self._m2.always() |
557 |
562 |
558 def isexact(self): |
563 def isexact(self): |
559 return self._m1.isexact() or self._m2.isexact() |
564 return self._m1.isexact() or self._m2.isexact() |
560 |
565 |
|
566 @encoding.strmethod |
561 def __repr__(self): |
567 def __repr__(self): |
562 return ('<intersectionmatcher m1=%r, m2=%r>' % (self._m1, self._m2)) |
568 return ('<intersectionmatcher m1=%r, m2=%r>' % (self._m1, self._m2)) |
563 |
569 |
564 class subdirmatcher(basematcher): |
570 class subdirmatcher(basematcher): |
565 """Adapt a matcher to work on a subdirectory only. |
571 """Adapt a matcher to work on a subdirectory only. |
636 return self._always |
642 return self._always |
637 |
643 |
638 def prefix(self): |
644 def prefix(self): |
639 return self._matcher.prefix() and not self._always |
645 return self._matcher.prefix() and not self._always |
640 |
646 |
|
647 @encoding.strmethod |
641 def __repr__(self): |
648 def __repr__(self): |
642 return ('<subdirmatcher path=%r, matcher=%r>' % |
649 return ('<subdirmatcher path=%r, matcher=%r>' % |
643 (self._path, self._matcher)) |
650 (self._path, self._matcher)) |
644 |
651 |
645 class unionmatcher(basematcher): |
652 class unionmatcher(basematcher): |
669 if v == 'all': |
676 if v == 'all': |
670 return v |
677 return v |
671 r |= v |
678 r |= v |
672 return r |
679 return r |
673 |
680 |
|
681 @encoding.strmethod |
674 def __repr__(self): |
682 def __repr__(self): |
675 return ('<unionmatcher matchers=%r>' % self._matchers) |
683 return ('<unionmatcher matchers=%r>' % self._matchers) |
676 |
684 |
677 def patkind(pattern, default=None): |
685 def patkind(pattern, default=None): |
678 '''If pattern is 'kind:pat' with a known kind, return kind.''' |
686 '''If pattern is 'kind:pat' with a known kind, return kind.''' |