You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by di...@apache.org on 2022/05/25 18:12:59 UTC
[allura] 01/01: [#8432] diffs - add max file size
This is an automated email from the ASF dual-hosted git repository.
dill0wn pushed a commit to branch dw/8432
in repository https://gitbox.apache.org/repos/asf/allura.git
commit 04ffb3fb676cd27cc700ab02abea37730ab9423f
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Wed May 25 18:12:51 2022 +0000
[#8432] diffs - add max file size
---
Allura/allura/controllers/repository.py | 16 +++++++++-------
Allura/development.ini | 3 +++
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 933b6f378..55a0135bc 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -909,6 +909,12 @@ class FileBrowser(BaseController):
if not self._blob.has_html_view:
diff = "Cannot display: file marked as a binary type."
return dict(a=a, b=b, diff=diff)
+
+ if max(a.size, b.size) > asint(tg.config.get('scm.view.max_diff_bytes', 2000000)):
+ # 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 = 'File too large to view diff'
+ return dict(a=a, b=b, diff=diff)
# could consider making Blob.__iter__ do unicode conversion?
# py2 unified_diff can handle some unicode but not consistently, so best to do ensure_str (can drop it on py3)
@@ -922,14 +928,10 @@ class FileBrowser(BaseController):
else:
web_session['diformat'] = fmt
web_session.save()
+
if fmt == 'sidebyside':
- 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 = '<em>File too large for side-by-side view</em>'
- else:
- hd = HtmlSideBySideDiff()
- diff = hd.make_table(la, lb, adesc, bdesc)
+ hd = HtmlSideBySideDiff()
+ diff = hd.make_table(la, lb, adesc, bdesc)
else:
# py2 unified_diff can handle some unicode but not consistently, so best to do str() and ensure_str()
# (can drop it on py3)
diff --git a/Allura/development.ini b/Allura/development.ini
index d7ff83ebd..6bbfb8458 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -433,6 +433,9 @@ scm.view.max_syntax_highlight_bytes = 500000
; Max size for viewing a file from a repo, can take a lot of template processing (even with syntax highlighting disabled)
scm.view.max_file_bytes = 5000000
+; Default limit for when to stop performing a diff (both side-by-side and default)
+scm.view.max_diff_bytes = 2000000
+
; Max size for download a raw file from a repo
scm.download.max_file_bytes = 30000000