You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by ke...@apache.org on 2019/11/19 18:39:18 UTC
[allura] branch master updated: [#8341] skip unified diff &
side-by-side diffs when files are too large
This is an automated email from the ASF dual-hosted git repository.
kentontaylor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
The following commit(s) were added to refs/heads/master by this push:
new f920b55 [#8341] skip unified diff & side-by-side diffs when files are too large
f920b55 is described below
commit f920b55cbbd4a6e2b896ba7de6dc4562a8b06871
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Mon Nov 18 17:19:15 2019 -0500
[#8341] skip unified diff & side-by-side diffs when files are too large
---
Allura/allura/controllers/repository.py | 11 ++++++++---
Allura/allura/lib/app_globals.py | 14 ++++++++------
Allura/allura/lib/custom_middleware.py | 2 ++
3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 783af70..0b8e87c 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -24,7 +24,7 @@ from collections import defaultdict, OrderedDict
from ming.utils import LazyProperty
-from paste.deploy.converters import asbool
+from paste.deploy.converters import asbool, asint
from tg import tmpl_context as c, app_globals as g
from tg import request, response
from webob import exc
@@ -913,8 +913,13 @@ class FileBrowser(BaseController):
web_session['diformat'] = fmt
web_session.save()
if fmt == 'sidebyside':
- hd = HtmlSideBySideDiff()
- diff = hd.make_table(la, lb, adesc, bdesc)
+ if max(a.size, b.size) > asint(tg.config.get('scm.view.max_syntax_highlight_bytes', 500000)):
+ # have to check the original file size, not diff size, because difflib._mdiff inside HtmlSideBySideDiff
+ # can take an extremely long time on large files (and its even a generator)
+ diff = u'<em>File too large for side-by-side view</em>'
+ else:
+ hd = HtmlSideBySideDiff()
+ diff = hd.make_table(la, lb, adesc, bdesc)
else:
diff = ''.join(difflib.unified_diff(la, lb, adesc, bdesc))
return dict(a=a, b=b, diff=diff)
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index c748579..1fb9162 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -412,14 +412,16 @@ class Globals(object):
lexer = pygments.lexers.get_lexer_for_filename(filename, encoding='chardet')
except pygments.util.ClassNotFound:
pass
- if lexer is None:
- # no highlighting, but we should escape, encode, and wrap it in
- # a <pre>
- text = cgi.escape(text)
- return h.html.literal(u'<pre>' + text + u'</pre>')
else:
lexer = pygments.lexers.get_lexer_by_name(lexer, encoding='chardet')
- return h.html.literal(pygments.highlight(text, lexer, formatter))
+
+ if lexer is None or len(text) >= asint(config.get('scm.view.max_syntax_highlight_bytes', 500000)):
+ # no highlighting, but we should escape, encode, and wrap it in
+ # a <pre>
+ text = cgi.escape(text)
+ return h.html.literal(u'<pre>' + text + u'</pre>')
+ else:
+ return h.html.literal(pygments.highlight(text, lexer, formatter))
def forge_markdown(self, **kwargs):
'''return a markdown.Markdown object on which you can call convert'''
diff --git a/Allura/allura/lib/custom_middleware.py b/Allura/allura/lib/custom_middleware.py
index 27aa2bd..cc87d44 100644
--- a/Allura/allura/lib/custom_middleware.py
+++ b/Allura/allura/lib/custom_middleware.py
@@ -296,6 +296,7 @@ class AlluraTimerMiddleware(TimerMiddleware):
import urllib2
import activitystream
import pygments
+ import difflib
timers = self.entry_point_timers() + [
Timer(
@@ -342,6 +343,7 @@ class AlluraTimerMiddleware(TimerMiddleware):
Timer('base_repo_tool.{method_name}',
allura.model.repository.RepositoryImplementation, 'last_commit_ids'),
Timer('pygments', pygments, 'highlight'), # often called from within a template so will overlap w/ jinja
+ Timer('difflib', difflib, '_mdiff', 'unified_diff'),
] + [Timer('sidebar', ep.load(), 'sidebar_menu') for ep in tool_entry_points]
try: