# HG changeset patch # User Bryan O'Sullivan # Date 1363028773 25200 # Node ID 5b05ceb24a8db1a5d76e721bb57b4119b596cddd # Parent 64b5562550e2bab150ef10cb1c35e6305d5dfc62 util: add flag support to compilere diff -r 64b5562550e2 -r 5b05ceb24a8d mercurial/util.py --- a/mercurial/util.py Wed Mar 13 10:43:51 2013 -0700 +++ b/mercurial/util.py Mon Mar 11 12:06:13 2013 -0700 @@ -662,10 +662,12 @@ except ImportError: _re2 = False -def compilere(pat): +def compilere(pat, flags=0): '''Compile a regular expression, using re2 if possible - For best performance, use only re2-compatible regexp features.''' + 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: @@ -673,12 +675,16 @@ _re2 = True except ImportError: _re2 = False - if _re2: + if _re2 and (flags & ~(re.IGNORECASE | re.MULTILINE)) == 0: + if flags & re.IGNORECASE: + pat = '(?i)' + pat + if flags & re.MULTILINE: + pat = '(?m)' + pat try: return re2.compile(pat) except re2.error: pass - return re.compile(pat) + return re.compile(pat, flags) _fspathcache = {} def fspath(name, root):