340 break |
340 break |
341 name = dirname |
341 name = dirname |
342 |
342 |
343 raise Abort('%s not under root' % myname) |
343 raise Abort('%s not under root' % myname) |
344 |
344 |
345 def matcher(canonroot, cwd='', names=[], inc=[], exc=[], src=None, dflt_pat='glob'): |
345 def matcher(canonroot, cwd='', names=[], inc=[], exc=[], dflt_pat='glob'): |
346 """build a function to match a set of file patterns |
346 """build a function to match a set of file patterns |
347 |
347 |
348 arguments: |
348 arguments: |
349 canonroot - the canonical root of the tree you're matching against |
349 canonroot - the canonical root of the tree you're matching against |
350 cwd - the current working directory, if relevant |
350 cwd - the current working directory, if relevant |
351 names - patterns to find |
351 names - patterns to find |
352 inc - patterns to include |
352 inc - patterns to include |
353 exc - patterns to exclude |
353 exc - patterns to exclude |
354 dflt_pat - if a pattern in names has no explicit type, assume this one |
354 dflt_pat - if a pattern in names has no explicit type, assume this one |
355 src - where these patterns came from (e.g. .hgignore) |
|
356 |
355 |
357 a pattern is one of: |
356 a pattern is one of: |
358 'glob:<glob>' - a glob relative to cwd |
357 'glob:<glob>' - a glob relative to cwd |
359 're:<regexp>' - a regular expression |
358 're:<regexp>' - a regular expression |
360 'path:<path>' - a path relative to canonroot |
359 'path:<path>' - a path relative to canonroot |
420 except re.error: |
419 except re.error: |
421 for k, p in pats: |
420 for k, p in pats: |
422 try: |
421 try: |
423 re.compile('(?:%s)' % regex(k, p, tail)) |
422 re.compile('(?:%s)' % regex(k, p, tail)) |
424 except re.error: |
423 except re.error: |
425 if src: |
424 raise Abort("invalid pattern (%s): %s" % (k, p)) |
426 raise Abort("%s: invalid pattern (%s): %s" % |
|
427 (src, k, p)) |
|
428 else: |
|
429 raise Abort("invalid pattern (%s): %s" % (k, p)) |
|
430 raise Abort("invalid pattern") |
425 raise Abort("invalid pattern") |
431 |
426 |
432 def globprefix(pat): |
427 def globprefix(pat): |
433 '''return the non-glob prefix of a path, e.g. foo/* -> foo''' |
428 '''return the non-glob prefix of a path, e.g. foo/* -> foo''' |
434 root = [] |
429 root = [] |