mercurial/util.py
changeset 21913 50aad4609224
parent 21912 b6ef4469191d
child 21914 10e99839a7a4
equal deleted inserted replaced
21912:b6ef4469191d 21913:50aad4609224
   715     _re2 = None
   715     _re2 = None
   716 except ImportError:
   716 except ImportError:
   717     _re2 = False
   717     _re2 = False
   718 
   718 
   719 class _re(object):
   719 class _re(object):
       
   720     def _checkre2(self):
       
   721         global _re2
       
   722         try:
       
   723             # check if match works, see issue3964
       
   724             _re2 = bool(re2.match(r'\[([^\[]+)\]', '[ui]'))
       
   725         except ImportError:
       
   726             _re2 = False
       
   727 
   720     def compile(self, pat, flags=0):
   728     def compile(self, pat, flags=0):
   721         '''Compile a regular expression, using re2 if possible
   729         '''Compile a regular expression, using re2 if possible
   722 
   730 
   723         For best performance, use only re2-compatible regexp features. The
   731         For best performance, use only re2-compatible regexp features. The
   724         only flags from the re module that are re2-compatible are
   732         only flags from the re module that are re2-compatible are
   725         IGNORECASE and MULTILINE.'''
   733         IGNORECASE and MULTILINE.'''
   726         global _re2
       
   727         if _re2 is None:
   734         if _re2 is None:
   728             try:
   735             self._checkre2()
   729                 # check if match works, see issue3964
       
   730                 _re2 = bool(re2.match(r'\[([^\[]+)\]', '[ui]'))
       
   731             except ImportError:
       
   732                 _re2 = False
       
   733         if _re2 and (flags & ~(remod.IGNORECASE | remod.MULTILINE)) == 0:
   736         if _re2 and (flags & ~(remod.IGNORECASE | remod.MULTILINE)) == 0:
   734             if flags & remod.IGNORECASE:
   737             if flags & remod.IGNORECASE:
   735                 pat = '(?i)' + pat
   738                 pat = '(?i)' + pat
   736             if flags & remod.MULTILINE:
   739             if flags & remod.MULTILINE:
   737                 pat = '(?m)' + pat
   740                 pat = '(?m)' + pat