# HG changeset patch # User Matt Harbison # Date 1618281767 14400 # Node ID 856820b497fcf31b7904e0b160c318437581d0c0 # Parent 631001150e136d8c35f08a6aa6742eee308c03fd# Parent bc268ea9f9843d65586186c0c735001510dd1daf merge with stable diff -r 631001150e13 -r 856820b497fc mercurial/upgrade_utils/actions.py --- a/mercurial/upgrade_utils/actions.py Fri Apr 09 17:41:48 2021 -0400 +++ b/mercurial/upgrade_utils/actions.py Mon Apr 12 22:42:47 2021 -0400 @@ -5,6 +5,9 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. +# See https://github.com/google/pytype/issues/860 +# pytype: skip-file + from __future__ import absolute_import from ..i18n import _ diff -r 631001150e13 -r 856820b497fc mercurial/util.py --- a/mercurial/util.py Fri Apr 09 17:41:48 2021 -0400 +++ b/mercurial/util.py Mon Apr 12 22:42:47 2021 -0400 @@ -2177,6 +2177,7 @@ return True +_re2_input = lambda x: x try: import re2 # pytype: disable=import-error @@ -2188,11 +2189,21 @@ class _re(object): def _checkre2(self): global _re2 + global _re2_input try: # check if match works, see issue3964 - _re2 = bool(re2.match(br'\[([^\[]+)\]', b'[ui]')) + check_pattern = br'\[([^\[]+)\]' + check_input = b'[ui]' + _re2 = bool(re2.match(check_pattern, check_input)) except ImportError: _re2 = False + except TypeError: + # the `pyre-2` project provides a re2 module that accept bytes + # the `fb-re2` project provides a re2 module that acccept sysstr + check_pattern = pycompat.sysstr(check_pattern) + check_input = pycompat.sysstr(check_input) + _re2 = bool(re2.match(check_pattern, check_input)) + _re2_input = pycompat.sysstr def compile(self, pat, flags=0): """Compile a regular expression, using re2 if possible @@ -2208,7 +2219,7 @@ if flags & remod.MULTILINE: pat = b'(?m)' + pat try: - return re2.compile(pat) + return re2.compile(_re2_input(pat)) except re2.error: pass return remod.compile(pat, flags)