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

login
register
mail settings
Submitter Boris Feld
Date Nov. 22, 2018, 10:17 p.m.
Message ID <0f01e9775b9732270e22.1542925043@localhost.localdomain>
Download mbox | patch
Permalink /patch/36728/
State Superseded
Headers show

Comments

Boris Feld - Nov. 22, 2018, 10:17 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 0f01e9775b9732270e22dd899465c09e832e612e
# Parent  018578f3ab597d5ea573107e7310470de76a3907
# EXP-Topic perf-ignore-2
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 0f01e9775b97
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) > MAXRESIZE:
-                raise OverflowError
+                msg = _("matcher pattern is too long (%d bytes)") % piecesize
+                raise error.Abort(msg)
             elif (groupsize + 1 + piecesize) > MAXRESIZE:
                 group = regexps[startidx:idx]
                 allgroups.append(_groupregexps(group))