changeset 21913:50aad4609224

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.
author Siddharth Agarwal <sid0@fb.com>
date Tue, 15 Jul 2014 15:01:52 -0700
parents b6ef4469191d
children 10e99839a7a4
files mercurial/util.py
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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