comparison mercurial/match.py @ 43595:ecd11c4d3834

match: drop support for passing '.' for root dir to visit*() methods We said we'd drop support for it after 5.1, so it's time to clean it up now. Differential Revision: https://phab.mercurial-scm.org/D7249
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 29 Oct 2019 23:33:34 -0700
parents c21aca51b392
children 0b7733719d21
comparison
equal deleted inserted replaced
43594:ac140b85aae9 43595:ecd11c4d3834
545 self.matchfn 545 self.matchfn
546 ) 546 )
547 return b'<predicatenmatcher pred=%s>' % s 547 return b'<predicatenmatcher pred=%s>' % s
548 548
549 549
550 def normalizerootdir(dir, funcname):
551 if dir == b'.':
552 util.nouideprecwarn(
553 b"match.%s() no longer accepts '.', use '' instead." % funcname,
554 b'5.1',
555 )
556 return b''
557 return dir
558
559
560 class patternmatcher(basematcher): 550 class patternmatcher(basematcher):
561 """Matches a set of (kind, pat, source) against a 'root' directory. 551 """Matches a set of (kind, pat, source) against a 'root' directory.
562 552
563 >>> kindpats = [ 553 >>> kindpats = [
564 ... (b're', br'.*\.c$', b''), 554 ... (b're', br'.*\.c$', b''),
600 @propertycache 590 @propertycache
601 def _dirs(self): 591 def _dirs(self):
602 return set(pathutil.dirs(self._fileset)) 592 return set(pathutil.dirs(self._fileset))
603 593
604 def visitdir(self, dir): 594 def visitdir(self, dir):
605 dir = normalizerootdir(dir, b'visitdir')
606 if self._prefix and dir in self._fileset: 595 if self._prefix and dir in self._fileset:
607 return b'all' 596 return b'all'
608 return ( 597 return (
609 dir in self._fileset 598 dir in self._fileset
610 or dir in self._dirs 599 or dir in self._dirs
684 # parents are directories which are non-recursively included because 673 # parents are directories which are non-recursively included because
685 # they are needed to get to items in _dirs or _roots. 674 # they are needed to get to items in _dirs or _roots.
686 self._parents = parents 675 self._parents = parents
687 676
688 def visitdir(self, dir): 677 def visitdir(self, dir):
689 dir = normalizerootdir(dir, b'visitdir')
690 if self._prefix and dir in self._roots: 678 if self._prefix and dir in self._roots:
691 return b'all' 679 return b'all'
692 return ( 680 return (
693 dir in self._roots 681 dir in self._roots
694 or dir in self._dirs 682 or dir in self._dirs
765 @propertycache 753 @propertycache
766 def _dirs(self): 754 def _dirs(self):
767 return set(pathutil.dirs(self._fileset)) 755 return set(pathutil.dirs(self._fileset))
768 756
769 def visitdir(self, dir): 757 def visitdir(self, dir):
770 dir = normalizerootdir(dir, b'visitdir')
771 return dir in self._dirs 758 return dir in self._dirs
772 759
773 def visitchildrenset(self, dir): 760 def visitchildrenset(self, dir):
774 dir = normalizerootdir(dir, b'visitchildrenset')
775
776 if not self._fileset or dir not in self._dirs: 761 if not self._fileset or dir not in self._dirs:
777 return set() 762 return set()
778 763
779 candidates = self._fileset | self._dirs - {b''} 764 candidates = self._fileset | self._dirs - {b''}
780 if dir != b'': 765 if dir != b'':
1007 # from the inputs. Instead, we override matchfn() and visitdir() to 992 # from the inputs. Instead, we override matchfn() and visitdir() to
1008 # call the original matcher with the subdirectory path prepended. 993 # call the original matcher with the subdirectory path prepended.
1009 return self._matcher.matchfn(self._path + b"/" + f) 994 return self._matcher.matchfn(self._path + b"/" + f)
1010 995
1011 def visitdir(self, dir): 996 def visitdir(self, dir):
1012 dir = normalizerootdir(dir, b'visitdir')
1013 if dir == b'': 997 if dir == b'':
1014 dir = self._path 998 dir = self._path
1015 else: 999 else:
1016 dir = self._path + b"/" + dir 1000 dir = self._path + b"/" + dir
1017 return self._matcher.visitdir(dir) 1001 return self._matcher.visitdir(dir)
1018 1002
1019 def visitchildrenset(self, dir): 1003 def visitchildrenset(self, dir):
1020 dir = normalizerootdir(dir, b'visitchildrenset')
1021 if dir == b'': 1004 if dir == b'':
1022 dir = self._path 1005 dir = self._path
1023 else: 1006 else:
1024 dir = self._path + b"/" + dir 1007 dir = self._path + b"/" + dir
1025 return self._matcher.visitchildrenset(dir) 1008 return self._matcher.visitchildrenset(dir)