D5309: match: remove obsolete catching of OverflowError
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Wed Nov 28 18:26:15 UTC 2018
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
Since https://phab.mercurial-scm.org/rHG0f6a1bdf89fb9b8e6c260a56a96063df3d57a636 (match: handle large regexes, 2007-08-19), we catch
an OverflowError from the regex engine and split up the regex if that
happens. In https://phab.mercurial-scm.org/rHG59a9dc9562e24d5e5890c7d957ef2b91cb12e8a0 (ignore: split up huge patterns, 2008-02-11),
that was extended to raise an OverflowError in our code even if the
regex engine doesn't raise it. It's unclear if there was a range of
regex sizes where the OverflowError would be raised from the regex
engine but that were still below the limit we added in our
code. Either way, both limitations were probably removed in Python
2.7.4 when the regex code width was extended from 16bit to 32bit (or
Py_UCS4) integer (thanks to Yuya for finding that out).
If at least the first limitation was removed, we no longer should be
using OverflowError for flow control, so this patch changes that.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D5309
AFFECTED FILES
mercurial/match.py
CHANGE DETAILS
diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -1190,16 +1190,15 @@
try:
regex = '(?:%s)' % '|'.join([_regex(k, p, globsuffix)
for (k, p, s) in kindpats])
- if len(regex) > 20000:
- raise OverflowError
- return regex, _rematcher(regex)
- except OverflowError:
+ if len(regex) < 20000:
+ return regex, _rematcher(regex)
# We're using a Python with a tiny regex engine and we
# made it explode, so we'll divide the pattern list in two
# until it works
l = len(kindpats)
if l < 2:
- raise
+ # TODO: raise error.Abort here
+ raise OverflowError
regexa, a = _buildregexmatch(kindpats[:l//2], globsuffix)
regexb, b = _buildregexmatch(kindpats[l//2:], globsuffix)
return regex, lambda s: a(s) or b(s)
To: martinvonz, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list