Mercurial > public > mercurial-scm > hg-stable
diff mercurial/util.py @ 814:0902ffece4b4
Merge with BOS
author | mpm@selenic.com |
---|---|
date | Sat, 30 Jul 2005 09:00:14 -0800 |
parents | 8f5637f0a0c0 b65af904d6d7 |
children | 89985a1b3427 0932bc2fb2be 1fe3b14c7044 |
line wrap: on
line diff
--- a/mercurial/util.py Sat Jul 30 08:35:29 2005 -0800 +++ b/mercurial/util.py Sat Jul 30 09:00:14 2005 -0800 @@ -66,7 +66,15 @@ res += re.escape(c) return head + res + tail -def matcher(cwd, pats, inc, exc, head = ''): +_globchars = {'[': 1, '{': 1, '*': 1, '?': 1} + +def matcher(cwd, names, inc, exc, head = ''): + def patlike(name): + for prefix in 're:', 'glob:', 'path:': + if name.startswith(prefix): return True + for c in name: + if c in _globchars: return True + def regex(name, tail): '''convert a pattern into a regular expression''' if name.startswith('re:'): @@ -77,6 +85,8 @@ return head + globre(name[5:], '', tail) return head + globre(name, '', tail) + cwdsep = cwd + os.sep + def under(fn): """check if fn is under our cwd""" return not cwd or fn.startswith(cwdsep) @@ -86,16 +96,25 @@ if pats: pat = '(?:%s)' % '|'.join([regex(p, tail) for p in pats]) if cwd: - pat = re.escape(cwd + os.sep) + pat + pat = re.escape(cwdsep) + pat return re.compile(pat).match - cwdsep = cwd + os.sep - patmatch = matchfn(pats, '$') or (lambda fn: True) + pats = filter(patlike, names) + files = [n for n in names if not patlike(n)] + if pats: plain = [] + elif cwd: plain = [cwdsep + f for f in files] + else: plain = files + + patmatch = matchfn(pats, '$') + filematch = matchfn(files, '(?:/|$)') incmatch = matchfn(inc, '(?:/|$)') or under excmatch = matchfn(exc, '(?:/|$)') or (lambda fn: False) - return lambda fn: (incmatch(fn) and not excmatch(fn) and - (fn.endswith('/') or patmatch(fn))) + return plain, lambda fn: (incmatch(fn) and not excmatch(fn) and + (fn.endswith('/') or + (not pats and not files) or + (pats and patmatch(fn)) or + (files and filematch(fn)))) def system(cmd, errprefix=None): """execute a shell command that must succeed"""