[PATCH 4 of 5] check-code: introduce function for using re2 when available

Simon Heimberg simohe at besonet.ch
Sat Jun 8 18:57:02 UTC 2013


# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1370715614 -7200
# Node ID e12f745ed2b4c38ac0acb2c8f7c2cebe3b130f3f
# Parent  9ea9c7411f1540ee7d6960087774388d28438b39
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.

diff -r 9ea9c7411f15 -r e12f745ed2b4 contrib/check-code.py
--- a/contrib/check-code.py	Sam Jun 08 20:20:14 2013 +0200
+++ b/contrib/check-code.py	Sam 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'))



More information about the Mercurial-devel mailing list