You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2019/11/18 22:19:27 UTC

[allura] branch db/8341 created (now 7480bd5)

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a change to branch db/8341
in repository https://gitbox.apache.org/repos/asf/allura.git.


      at 7480bd5  [#8341] skip unified diff & side-by-side diffs when files are too large

This branch includes the following new commits:

     new 7480bd5  [#8341] skip unified diff & side-by-side diffs when files are too large

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[allura] 01/01: [#8341] skip unified diff & side-by-side diffs when files are too large

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/8341
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 7480bd5af0c8786d1d8be5033bbb3ebcbc527773
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 f558b74..5084977 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: