comparison mercurial/util.py @ 6074:59a9dc9562e2

ignore: split up huge patterns Some versions of Python silently mishandle large regexes, so split them up at a conservative 20k.
author Matt Mackall <mpm@selenic.com>
date Mon, 11 Feb 2008 16:13:43 -0600
parents 3c3b126e5619
children 41aa0a37d9be
comparison
equal deleted inserted replaced
6073:89c70d496175 6074:59a9dc9562e2
457 """build a matching function from a set of patterns""" 457 """build a matching function from a set of patterns"""
458 if not pats: 458 if not pats:
459 return 459 return
460 try: 460 try:
461 pat = '(?:%s)' % '|'.join([regex(k, p, tail) for (k, p) in pats]) 461 pat = '(?:%s)' % '|'.join([regex(k, p, tail) for (k, p) in pats])
462 if len(pat) > 20000:
463 raise OverflowError()
462 return re.compile(pat).match 464 return re.compile(pat).match
463 except OverflowError: 465 except OverflowError:
464 # We're using a Python with a tiny regex engine and we 466 # We're using a Python with a tiny regex engine and we
465 # made it explode, so we'll divide the pattern list in two 467 # made it explode, so we'll divide the pattern list in two
466 # until it works 468 # until it works