Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 8569:4fadac101818
util: privatize globre
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 24 May 2009 02:56:14 -0500 |
parents | 4fa1618bf495 |
children | 7fe2012b3bd0 |
comparison
equal
deleted
inserted
replaced
8568:4fa1618bf495 | 8569:4fadac101818 |
---|---|
212 actual pattern.""" | 212 actual pattern.""" |
213 for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre': | 213 for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre': |
214 if pat.startswith(prefix + ':'): return pat.split(':', 1) | 214 if pat.startswith(prefix + ':'): return pat.split(':', 1) |
215 return default, pat | 215 return default, pat |
216 | 216 |
217 def globre(pat, head='^', tail='$'): | 217 def _globre(pat, head='^', tail='$'): |
218 "convert a glob pattern into a regexp" | 218 "convert a glob pattern into a regexp" |
219 i, n = 0, len(pat) | 219 i, n = 0, len(pat) |
220 res = '' | 220 res = '' |
221 group = 0 | 221 group = 0 |
222 def peek(): return i < n and pat[i] | 222 def peek(): return i < n and pat[i] |
387 if kind == 're': | 387 if kind == 're': |
388 return name | 388 return name |
389 elif kind == 'path': | 389 elif kind == 'path': |
390 return '^' + re.escape(name) + '(?:/|$)' | 390 return '^' + re.escape(name) + '(?:/|$)' |
391 elif kind == 'relglob': | 391 elif kind == 'relglob': |
392 return globre(name, '(?:|.*/)', tail) | 392 return _globre(name, '(?:|.*/)', tail) |
393 elif kind == 'relpath': | 393 elif kind == 'relpath': |
394 return re.escape(name) + '(?:/|$)' | 394 return re.escape(name) + '(?:/|$)' |
395 elif kind == 'relre': | 395 elif kind == 'relre': |
396 if name.startswith('^'): | 396 if name.startswith('^'): |
397 return name | 397 return name |
398 return '.*' + name | 398 return '.*' + name |
399 return globre(name, '', tail) | 399 return _globre(name, '', tail) |
400 | 400 |
401 def matchfn(pats, tail): | 401 def matchfn(pats, tail): |
402 """build a matching function from a set of patterns""" | 402 """build a matching function from a set of patterns""" |
403 if not pats: | 403 if not pats: |
404 return | 404 return |