match: handle large regexes
authorMatt Mackall <mpm@selenic.com>
Sun, 19 Aug 2007 14:03:56 -0500
changeset 5201 0f6a1bdf89fb
parent 5190 6d5ed61c508c
child 5202 1108c952cca1
child 5211 bddb4ff134c0
match: handle large regexes Some Python versions don't handle large regexes, so when we hit an overflow, split our regex in two.
mercurial/util.py
--- a/mercurial/util.py	Fri Aug 17 22:43:38 2007 -0300
+++ b/mercurial/util.py	Sun Aug 19 14:03:56 2007 -0500
@@ -476,6 +476,15 @@
         try:
             pat = '(?:%s)' % '|'.join([regex(k, p, tail) for (k, p) in pats])
             return re.compile(pat).match
+        except OverflowError:
+            # We're using a Python with a tiny regex engine and we
+            # made it explode, so we'll divide the pattern list in two
+            # until it works
+            l = len(pats)
+            if l < 2:
+                raise
+            a, b = matchfn(pats[:l/2], tail), matchfn(pats[l/2:], tail)
+            return lambda s: a(s) or b(s)
         except re.error:
             for k, p in pats:
                 try: