Patchwork [5,of,5,V4] match: raise an Abort error instead of OverflowError

login
register
mail settings
Submitter Boris Feld
Date Dec. 1, 2018, 12:07 p.m.
Message ID <fb26ffdf255f07c57f6b.1543666055@pc62.home>
Download mbox | patch
Permalink /patch/36897/
State Accepted
Headers show

Comments

Boris Feld - Dec. 1, 2018, 12:07 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 fb26ffdf255f07c57f6b18f31f8b146e9f86bd72
# Parent  0a28ff17100a67c21a99ef363f15aef09e4dfa8b
# EXP-Topic perf-ignore
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r fb26ffdf255f
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))