comparison mercurial/match.py @ 8571:9f12e1a27a1b

match: refactor matchfn generation
author Matt Mackall <mpm@selenic.com>
date Sun, 24 May 2009 02:56:14 -0500
parents 7fe2012b3bd0
children dd46948a07fa
comparison
equal deleted inserted replaced
8570:7fe2012b3bd0 8571:9f12e1a27a1b
146 - a bool indicating if any patterns were passed in 146 - a bool indicating if any patterns were passed in
147 """ 147 """
148 148
149 # a common case: no patterns at all 149 # a common case: no patterns at all
150 if not names and not inc and not exc: 150 if not names and not inc and not exc:
151 return [], util.always, False 151 return [], lambda f: True, False
152 152
153 def contains_glob(name): 153 def contains_glob(name):
154 for c in name: 154 for c in name:
155 if c in _globchars: return True 155 if c in _globchars: return True
156 return False 156 return False
231 roots.append('.') 231 roots.append('.')
232 return roots, pats, anypats 232 return roots, pats, anypats
233 233
234 roots, pats, anypats = normalizepats(names, dflt_pat) 234 roots, pats, anypats = normalizepats(names, dflt_pat)
235 235
236 patmatch = matchfn(pats, '$') or util.always 236 patmatch = matchfn(pats, '$')
237 incmatch = util.always
238 if inc: 237 if inc:
239 dummy, inckinds, dummy = normalizepats(inc, 'glob') 238 dummy, inckinds, dummy = normalizepats(inc, 'glob')
240 incmatch = matchfn(inckinds, '(?:/|$)') 239 incmatch = matchfn(inckinds, '(?:/|$)')
241 excmatch = util.never
242 if exc: 240 if exc:
243 dummy, exckinds, dummy = normalizepats(exc, 'glob') 241 dummy, exckinds, dummy = normalizepats(exc, 'glob')
244 excmatch = matchfn(exckinds, '(?:/|$)') 242 excmatch = matchfn(exckinds, '(?:/|$)')
245 243
246 if not names and inc and not exc: 244 if names:
247 # common case: hgignore patterns 245 if inc:
248 matcher = incmatch 246 if exc:
247 m = lambda f: incmatch(f) and not excmatch(f) and patmatch(f)
248 else:
249 m = lambda f: incmatch(f) and patmatch(f)
250 else:
251 if exc:
252 m = lambda f: not excmatch(f) and patmatch(f)
253 else:
254 m = patmatch
249 else: 255 else:
250 matcher = lambda fn: incmatch(fn) and not excmatch(fn) and patmatch(fn) 256 if inc:
251 257 if exc:
252 return (roots, matcher, (inc or exc or anypats) and True) 258 m = lambda f: incmatch(f) and not excmatch(f)
259 else:
260 m = incmatch
261 else:
262 if exc:
263 m = lambda f: not excmatch(f)
264 else:
265 m = lambda f: True
266
267 return (roots, m, (inc or exc or anypats) and True)