Patchwork [6,of,6,V3] match: raise an Abort error instead of OverflowError

login
register
mail settings
Submitter Boris Feld
Date Nov. 23, 2018, 2:12 p.m.
Message ID <0aed4a6bdbfb848a8a6d.1542982369@localhost.localdomain>
Download mbox | patch
Permalink /patch/36748/
State Accepted
Headers show

Comments

Boris Feld - Nov. 23, 2018, 2:12 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1542904870 -3600
#      Thu Nov 22 17:41:10 2018 +0100
# Node ID 0aed4a6bdbfb848a8a6d10581721a40bd5d7d508
# Parent  b41a4db20b0898e57f9fa0bb9ebdabb30a53df75
# EXP-Topic perf-ignore
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 0aed4a6bdbfb
match: raise an Abort error instead of OverflowError

This case of OverflowError (one single pattern being too large) has never been
properly caught in the past.

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -1201,7 +1201,7 @@  def _buildregexmatch(kindpats, globsuffi
     ... ], '$')
     Traceback (most recent call last):
     ...
-    OverflowError
+    Abort: matcher pattern is too long (20009 bytes)
     """
     try:
         allgroups = []
@@ -1213,7 +1213,8 @@  def _buildregexmatch(kindpats, globsuffi
         for idx, r in enumerate(regexps):
             piecesize = len(r)
             if (piecesize + 4) > MAX_RE_SIZE:
-                raise OverflowError
+                msg = _("matcher pattern is too long (%d bytes)") % piecesize
+                raise error.Abort(msg)
             elif (groupsize + 1 + piecesize) > MAX_RE_SIZE:
                 group = regexps[startidx:idx]
                 allgroups.append(_joinregexes(group))