comparison mercurial/util.py @ 5206:0f6a1bdf89fb

match: handle large regexes Some Python versions don't handle large regexes, so when we hit an overflow, split our regex in two.
author Matt Mackall <mpm@selenic.com>
date Sun, 19 Aug 2007 14:03:56 -0500
parents 84b10dc3dccc
children 1108c952cca1 b0bc8cf41ffc
comparison
equal deleted inserted replaced
5195:6d5ed61c508c 5206:0f6a1bdf89fb
474 if not pats: 474 if not pats:
475 return 475 return
476 try: 476 try:
477 pat = '(?:%s)' % '|'.join([regex(k, p, tail) for (k, p) in pats]) 477 pat = '(?:%s)' % '|'.join([regex(k, p, tail) for (k, p) in pats])
478 return re.compile(pat).match 478 return re.compile(pat).match
479 except OverflowError:
480 # We're using a Python with a tiny regex engine and we
481 # made it explode, so we'll divide the pattern list in two
482 # until it works
483 l = len(pats)
484 if l < 2:
485 raise
486 a, b = matchfn(pats[:l/2], tail), matchfn(pats[l/2:], tail)
487 return lambda s: a(s) or b(s)
479 except re.error: 488 except re.error:
480 for k, p in pats: 489 for k, p in pats:
481 try: 490 try:
482 re.compile('(?:%s)' % regex(k, p, tail)) 491 re.compile('(?:%s)' % regex(k, p, tail))
483 except re.error: 492 except re.error: