comparison mercurial/match.py @ 25238:5a55ad6e8e24

match: add root to _buildmatch A future patch will make _buildmatch able to expand relative include patterns. Doing so will require knowing the root of the repo, so let's go ahead and pass it in.
author Durham Goode <durham@fb.com>
date Sat, 16 May 2015 16:12:00 -0700
parents 9789b4a7c595
children 714f612f2afc
comparison
equal deleted inserted replaced
25237:7504a7325e4c 25238:5a55ad6e8e24
92 92
93 matchfns = [] 93 matchfns = []
94 if include: 94 if include:
95 kindpats = self._normalize(include, 'glob', root, cwd, auditor) 95 kindpats = self._normalize(include, 'glob', root, cwd, auditor)
96 self.includepat, im = _buildmatch(ctx, kindpats, '(?:/|$)', 96 self.includepat, im = _buildmatch(ctx, kindpats, '(?:/|$)',
97 listsubrepos) 97 listsubrepos, root)
98 self._includeroots.update(_roots(kindpats)) 98 self._includeroots.update(_roots(kindpats))
99 self._includeroots.discard('.') 99 self._includeroots.discard('.')
100 self._includedirs.update(util.dirs(self._includeroots)) 100 self._includedirs.update(util.dirs(self._includeroots))
101 matchfns.append(im) 101 matchfns.append(im)
102 if exclude: 102 if exclude:
103 kindpats = self._normalize(exclude, 'glob', root, cwd, auditor) 103 kindpats = self._normalize(exclude, 'glob', root, cwd, auditor)
104 self.excludepat, em = _buildmatch(ctx, kindpats, '(?:/|$)', 104 self.excludepat, em = _buildmatch(ctx, kindpats, '(?:/|$)',
105 listsubrepos) 105 listsubrepos, root)
106 self._excluderoots.update(_roots(kindpats)) 106 self._excluderoots.update(_roots(kindpats))
107 self._excluderoots.discard('.') 107 self._excluderoots.discard('.')
108 matchfns.append(lambda f: not em(f)) 108 matchfns.append(lambda f: not em(f))
109 if exact: 109 if exact:
110 if isinstance(patterns, list): 110 if isinstance(patterns, list):
116 kindpats = self._normalize(patterns, default, root, cwd, auditor) 116 kindpats = self._normalize(patterns, default, root, cwd, auditor)
117 if not _kindpatsalwaysmatch(kindpats): 117 if not _kindpatsalwaysmatch(kindpats):
118 self._files = _roots(kindpats) 118 self._files = _roots(kindpats)
119 self._anypats = self._anypats or _anypats(kindpats) 119 self._anypats = self._anypats or _anypats(kindpats)
120 self.patternspat, pm = _buildmatch(ctx, kindpats, '$', 120 self.patternspat, pm = _buildmatch(ctx, kindpats, '$',
121 listsubrepos) 121 listsubrepos, root)
122 matchfns.append(pm) 122 matchfns.append(pm)
123 123
124 if not matchfns: 124 if not matchfns:
125 m = util.always 125 m = util.always
126 self._always = True 126 self._always = True
474 if pat.startswith('^'): 474 if pat.startswith('^'):
475 return pat 475 return pat
476 return '.*' + pat 476 return '.*' + pat
477 return _globre(pat) + globsuffix 477 return _globre(pat) + globsuffix
478 478
479 def _buildmatch(ctx, kindpats, globsuffix, listsubrepos): 479 def _buildmatch(ctx, kindpats, globsuffix, listsubrepos, root):
480 '''Return regexp string and a matcher function for kindpats. 480 '''Return regexp string and a matcher function for kindpats.
481 globsuffix is appended to the regexp of globs.''' 481 globsuffix is appended to the regexp of globs.'''
482 fset, kindpats = _expandsets(kindpats, ctx, listsubrepos) 482 fset, kindpats = _expandsets(kindpats, ctx, listsubrepos)
483 if not kindpats: 483 if not kindpats:
484 return "", fset.__contains__ 484 return "", fset.__contains__