Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 46903:856820b497fc
merge with stable
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 12 Apr 2021 22:42:47 -0400 |
parents | 51841b23670b 112826b59476 |
children | ffd3e823a7e5 |
comparison
equal
deleted
inserted
replaced
46902:631001150e13 | 46903:856820b497fc |
---|---|
2175 return True | 2175 return True |
2176 except OSError: | 2176 except OSError: |
2177 return True | 2177 return True |
2178 | 2178 |
2179 | 2179 |
2180 _re2_input = lambda x: x | |
2180 try: | 2181 try: |
2181 import re2 # pytype: disable=import-error | 2182 import re2 # pytype: disable=import-error |
2182 | 2183 |
2183 _re2 = None | 2184 _re2 = None |
2184 except ImportError: | 2185 except ImportError: |
2186 | 2187 |
2187 | 2188 |
2188 class _re(object): | 2189 class _re(object): |
2189 def _checkre2(self): | 2190 def _checkre2(self): |
2190 global _re2 | 2191 global _re2 |
2192 global _re2_input | |
2191 try: | 2193 try: |
2192 # check if match works, see issue3964 | 2194 # check if match works, see issue3964 |
2193 _re2 = bool(re2.match(br'\[([^\[]+)\]', b'[ui]')) | 2195 check_pattern = br'\[([^\[]+)\]' |
2196 check_input = b'[ui]' | |
2197 _re2 = bool(re2.match(check_pattern, check_input)) | |
2194 except ImportError: | 2198 except ImportError: |
2195 _re2 = False | 2199 _re2 = False |
2200 except TypeError: | |
2201 # the `pyre-2` project provides a re2 module that accept bytes | |
2202 # the `fb-re2` project provides a re2 module that acccept sysstr | |
2203 check_pattern = pycompat.sysstr(check_pattern) | |
2204 check_input = pycompat.sysstr(check_input) | |
2205 _re2 = bool(re2.match(check_pattern, check_input)) | |
2206 _re2_input = pycompat.sysstr | |
2196 | 2207 |
2197 def compile(self, pat, flags=0): | 2208 def compile(self, pat, flags=0): |
2198 """Compile a regular expression, using re2 if possible | 2209 """Compile a regular expression, using re2 if possible |
2199 | 2210 |
2200 For best performance, use only re2-compatible regexp features. The | 2211 For best performance, use only re2-compatible regexp features. The |
2206 if flags & remod.IGNORECASE: | 2217 if flags & remod.IGNORECASE: |
2207 pat = b'(?i)' + pat | 2218 pat = b'(?i)' + pat |
2208 if flags & remod.MULTILINE: | 2219 if flags & remod.MULTILINE: |
2209 pat = b'(?m)' + pat | 2220 pat = b'(?m)' + pat |
2210 try: | 2221 try: |
2211 return re2.compile(pat) | 2222 return re2.compile(_re2_input(pat)) |
2212 except re2.error: | 2223 except re2.error: |
2213 pass | 2224 pass |
2214 return remod.compile(pat, flags) | 2225 return remod.compile(pat, flags) |
2215 | 2226 |
2216 @propertycache | 2227 @propertycache |