Mercurial > hg
comparison mercurial/match.py @ 8576:ec4ed21db4b2
match: split up _normalizepats
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 24 May 2009 02:56:14 -0500 |
parents | aa4fcb5c46f1 |
children | c7bab7fede4c |
comparison
equal
deleted
inserted
replaced
8575:aa4fcb5c46f1 | 8576:ec4ed21db4b2 |
---|---|
166 root.append(p) | 166 root.append(p) |
167 return '/'.join(root) or '.' | 167 return '/'.join(root) or '.' |
168 | 168 |
169 def _normalizepats(names, default, canonroot, cwd): | 169 def _normalizepats(names, default, canonroot, cwd): |
170 pats = [] | 170 pats = [] |
171 roots = [] | |
172 anypats = False | |
173 for kind, name in [_patsplit(p, default) for p in names]: | 171 for kind, name in [_patsplit(p, default) for p in names]: |
174 if kind in ('glob', 'relpath'): | 172 if kind in ('glob', 'relpath'): |
175 name = util.canonpath(canonroot, cwd, name) | 173 name = util.canonpath(canonroot, cwd, name) |
176 elif kind in ('relglob', 'path'): | 174 elif kind in ('relglob', 'path'): |
177 name = util.normpath(name) | 175 name = util.normpath(name) |
178 | 176 |
179 pats.append((kind, name)) | 177 pats.append((kind, name)) |
180 | 178 return pats |
179 | |
180 def _roots(patterns): | |
181 r = [] | |
182 for kind, name in patterns: | |
183 if kind == 'glob': | |
184 r.append(_globprefix(name)) | |
185 elif kind in ('relpath', 'path'): | |
186 r.append(name or '.') | |
187 elif kind == 'relglob': | |
188 r.append('.') | |
189 return r | |
190 | |
191 def _anypats(patterns): | |
192 for kind, name in patterns: | |
181 if kind in ('glob', 're', 'relglob', 'relre'): | 193 if kind in ('glob', 're', 'relglob', 'relre'): |
182 anypats = True | 194 return True |
183 | |
184 if kind == 'glob': | |
185 root = _globprefix(name) | |
186 roots.append(root) | |
187 elif kind in ('relpath', 'path'): | |
188 roots.append(name or '.') | |
189 elif kind == 'relglob': | |
190 roots.append('.') | |
191 return roots, pats, anypats | |
192 | 195 |
193 def _matcher(root, cwd='', names=[], inc=[], exc=[], dflt_pat='glob'): | 196 def _matcher(root, cwd='', names=[], inc=[], exc=[], dflt_pat='glob'): |
194 """build a function to match a set of file patterns | 197 """build a function to match a set of file patterns |
195 | 198 |
196 arguments: | 199 arguments: |
221 | 224 |
222 # a common case: no patterns at all | 225 # a common case: no patterns at all |
223 if not names and not inc and not exc: | 226 if not names and not inc and not exc: |
224 return [], lambda f: True, False | 227 return [], lambda f: True, False |
225 | 228 |
226 roots, pats, anypats = _normalizepats(names, dflt_pat, root, cwd) | 229 pats = _normalizepats(names, dflt_pat, root, cwd) |
230 roots = _roots(pats) | |
231 anypats = _anypats(pats) | |
227 | 232 |
228 if names: | 233 if names: |
229 patmatch = _matchfn(pats, '$') | 234 patmatch = _matchfn(pats, '$') |
230 if inc: | 235 if inc: |
231 dummy, inckinds, dummy = _normalizepats(inc, 'glob', root, cwd) | 236 inckinds = _normalizepats(inc, 'glob', root, cwd) |
232 incmatch = _matchfn(inckinds, '(?:/|$)') | 237 incmatch = _matchfn(inckinds, '(?:/|$)') |
233 if exc: | 238 if exc: |
234 dummy, exckinds, dummy = _normalizepats(exc, 'glob', root, cwd) | 239 exckinds = _normalizepats(exc, 'glob', root, cwd) |
235 excmatch = _matchfn(exckinds, '(?:/|$)') | 240 excmatch = _matchfn(exckinds, '(?:/|$)') |
236 | 241 |
237 if names: | 242 if names: |
238 if inc: | 243 if inc: |
239 if exc: | 244 if exc: |