comparison mercurial/util.py @ 1413:1c64c628d15f

Do not use 'glob' expansion by default on OS != 'nt'
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Wed, 19 Oct 2005 00:02:41 -0700
parents 9d2c2e6b32b5
children c6e6ca96a033
comparison
equal deleted inserted replaced
1412:c1e0aebfabc0 1413:1c64c628d15f
177 return '' 177 return ''
178 else: 178 else:
179 raise Abort('%s not under root' % myname) 179 raise Abort('%s not under root' % myname)
180 180
181 def matcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head=''): 181 def matcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head=''):
182 return _matcher(canonroot, cwd, names, inc, exc, head, 'glob')
183
184 def cmdmatcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head=''):
185 if os.name == 'nt':
186 dflt_pat = 'glob'
187 else:
188 dflt_pat = 'relpath'
189 return _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat)
190
191 def _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat):
182 """build a function to match a set of file patterns 192 """build a function to match a set of file patterns
183 193
184 arguments: 194 arguments:
185 canonroot - the canonical root of the tree you're matching against 195 canonroot - the canonical root of the tree you're matching against
186 cwd - the current working directory, if relevant 196 cwd - the current working directory, if relevant
206 216
207 todo: 217 todo:
208 make head regex a rooted bool 218 make head regex a rooted bool
209 """ 219 """
210 220
211 def patkind(name): 221 def patkind(name, dflt_pat='glob'):
212 for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre': 222 for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre':
213 if name.startswith(prefix + ':'): return name.split(':', 1) 223 if name.startswith(prefix + ':'): return name.split(':', 1)
224 return dflt_pat, name
225
226 def contains_glob(name):
214 for c in name: 227 for c in name:
215 if c in _globchars: return 'glob', name 228 if c in _globchars: return True
216 return 'relpath', name 229 return False
217 230
218 def regex(kind, name, tail): 231 def regex(kind, name, tail):
219 '''convert a pattern into a regular expression''' 232 '''convert a pattern into a regular expression'''
220 if kind == 're': 233 if kind == 're':
221 return name 234 return name
239 252
240 def globprefix(pat): 253 def globprefix(pat):
241 '''return the non-glob prefix of a path, e.g. foo/* -> foo''' 254 '''return the non-glob prefix of a path, e.g. foo/* -> foo'''
242 root = [] 255 root = []
243 for p in pat.split(os.sep): 256 for p in pat.split(os.sep):
244 if patkind(p)[0] == 'glob': break 257 if contains_glob(p): break
245 root.append(p) 258 root.append(p)
246 return '/'.join(root) 259 return '/'.join(root)
247 260
248 pats = [] 261 pats = []
249 files = [] 262 files = []
250 roots = [] 263 roots = []
251 for kind, name in map(patkind, names): 264 for kind, name in [patkind(p, dflt_pat) for p in names]:
252 if kind in ('glob', 'relpath'): 265 if kind in ('glob', 'relpath'):
253 name = canonpath(canonroot, cwd, name) 266 name = canonpath(canonroot, cwd, name)
254 if name == '': 267 if name == '':
255 kind, name = 'glob', '**' 268 kind, name = 'glob', '**'
256 if kind in ('glob', 'path', 're'): 269 if kind in ('glob', 'path', 're'):