util.re: move check for re2 into a separate method
authorSiddharth Agarwal <sid0@fb.com>
Tue, 15 Jul 2014 15:01:52 -0700
changeset 21913 50aad4609224
parent 21912 b6ef4469191d
child 21914 10e99839a7a4
util.re: move check for re2 into a separate method We're going to use the same check for another method in an upcoming patch.
mercurial/util.py
--- a/mercurial/util.py	Tue Jul 15 14:52:40 2014 -0700
+++ b/mercurial/util.py	Tue Jul 15 15:01:52 2014 -0700
@@ -717,19 +717,22 @@
     _re2 = False
 
 class _re(object):
+    def _checkre2(self):
+        global _re2
+        try:
+            # check if match works, see issue3964
+            _re2 = bool(re2.match(r'\[([^\[]+)\]', '[ui]'))
+        except ImportError:
+            _re2 = False
+
     def compile(self, pat, flags=0):
         '''Compile a regular expression, using re2 if possible
 
         For best performance, use only re2-compatible regexp features. The
         only flags from the re module that are re2-compatible are
         IGNORECASE and MULTILINE.'''
-        global _re2
         if _re2 is None:
-            try:
-                # check if match works, see issue3964
-                _re2 = bool(re2.match(r'\[([^\[]+)\]', '[ui]'))
-            except ImportError:
-                _re2 = False
+            self._checkre2()
         if _re2 and (flags & ~(remod.IGNORECASE | remod.MULTILINE)) == 0:
             if flags & remod.IGNORECASE:
                 pat = '(?i)' + pat