check-code: introduce function for using re2 when available
Do it similar as in mercurial.util. For simplicity only support flag
multiline which is the only one used.
--- a/contrib/check-code.py Sat Jun 08 20:20:14 2013 +0200
+++ b/contrib/check-code.py Sat Jun 08 20:20:14 2013 +0200
@@ -10,6 +10,20 @@
import re, glob, os, sys
import keyword
import optparse
+try:
+ import re2
+except ImportError:
+ re2 = None
+
+def compilere(pat, multiline=False):
+ if multiline:
+ pat = '(?m)' + pat
+ if re2:
+ try:
+ return re2.compile(pat)
+ except re2.error:
+ pass
+ return re.compile(pat)
def repquote(m):
t = re.sub(r"\w", "x", m.group('text'))