# HG changeset patch # User Siddharth Agarwal # Date 1405461712 25200 # Node ID 50aad4609224ccc36dbe2d0117e3a481178c297b # Parent b6ef4469191dc96052167a826f2fb3c91e98877e 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 -r b6ef4469191d -r 50aad4609224 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