[PATCH 7 of 9] util.re: move check for re2 into a separate method

Siddharth Agarwal sid0 at fb.com
Tue Jul 15 18:15:29 CDT 2014


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1405461712 25200
#      Tue Jul 15 15:01:52 2014 -0700
# Node ID a8ad4f53079750108dbfa35f6f57e0a1a1f5b8b3
# Parent  51d37941762aac1a4a80c9b53537edaa8fe5df2e
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.

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -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


More information about the Mercurial-devel mailing list