[PATCH 1 of 2] highlight: configurable file size limit (issue3005)
Yuya Nishihara
yuya at tcha.org
Tue Aug 4 10:03:25 CDT 2015
On Mon, 03 Aug 2015 22:54:04 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6 at dwimlabs.net>
> # Date 1438508200 -28800
> # Sun Aug 02 17:36:40 2015 +0800
> # Branch stable
> # Node ID 1426bfe350e2070e0fcaf7c0a083e4e385f83805
> # Parent 79f0cb97d7537a7c2948f8f9b0a89148825a3a1d
> highlight: configurable file size limit (issue3005)
>
> The issue is titled: "MemoryError when using highlight in hgweb", and one of
> the proposed solutions to the problem was to make a configurable limit for
> highlight extension so it doesn't pygmentize files above a certain size.
>
> Let's introduce such an option, named highlightmax and set its default to 5 MB
> (this value is, again, taken from the issue). If a file is above this limit,
> highlight extension skips it completely.
>
> diff --git a/hgext/highlight/__init__.py b/hgext/highlight/__init__.py
> --- a/hgext/highlight/__init__.py
> +++ b/hgext/highlight/__init__.py
> @@ -13,12 +13,11 @@
> It depends on the Pygments syntax highlighting library:
> http://pygments.org/
>
> -There is a single configuration option::
> +There are two configuration options::
>
> [web]
> - pygments_style = <style>
> -
> -The default is 'colorful'.
> + pygments_style = <style> (default: 'colorful')
> + highlightmax = <file size> (default: 5 MB)
> """
>
> import highlight
> @@ -41,7 +40,9 @@ def filerevision_highlight(orig, web, re
> # pygmentize a html file
> if 'html' in mt:
> style = web.config('web', 'pygments_style', 'colorful')
> - highlight.pygmentize('fileline', fctx, style, tmpl)
> + maxbytes = web.configbytes('web', 'highlightmax', '5 MB')
These patches look good to me.
Just an idea: it could be a fileset to mitigate a bug of pygments, for example,
to enable known-good parser for small .py files:
set:**.py and size('<5M')
More information about the Mercurial-devel
mailing list