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

login
register
mail settings
Submitter Siddharth Agarwal
Date July 15, 2014, 11:15 p.m.
Message ID <a8ad4f53079750108dbf.1405466129@dev1738.prn1.facebook.com>
Download mbox | patch
Permalink /patch/5180/
State Accepted
Commit 50aad4609224ccc36dbe2d0117e3a481178c297b
Headers show

Comments

Siddharth Agarwal - July 15, 2014, 11:15 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@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.

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