# HG changeset patch # User Daniel Dourvaris # Date 2019-08-23 18:34:01 # Node ID 66d4585824e2cd0c2d8e32071dd7fd0dc6d11eaf # Parent 4b32a14b2eda056981fa01d891bf731be5de82bb file-source: ensure over size limit files never do any content fetching when viewing the files. - otherwise we use lot of memory - we can easily hit msgpack 4gb size limit on svn repos which often store such non binary files diff --git a/rhodecode/apps/repository/views/repo_files.py b/rhodecode/apps/repository/views/repo_files.py --- a/rhodecode/apps/repository/views/repo_files.py +++ b/rhodecode/apps/repository/views/repo_files.py @@ -668,7 +668,10 @@ class RepoFilesView(RepoAppView): c.file_source_page = 'true' c.file_last_commit = c.file.last_commit - if c.file.size < c.visual.cut_off_limit_diff: + + c.file_size_too_big = c.file.size > c.visual.cut_off_limit_file + + if not c.file_size_too_big: if c.annotate: # annotation has precedence over renderer c.annotated_lines = filenode_as_annotated_lines_tokens( c.file diff --git a/rhodecode/templates/files/files_source.mako b/rhodecode/templates/files/files_source.mako --- a/rhodecode/templates/files/files_source.mako +++ b/rhodecode/templates/files/files_source.mako @@ -60,14 +60,28 @@
- ${c.file.lines()[0]} ${_ungettext('line', 'lines', c.file.lines()[0])} + + % if c.file_size_too_big: + 0 ${(_('lines'))} + % else: + ${c.file.lines()[0]} ${_ungettext('line', 'lines', c.file.lines()[0])} + % endif + | ${h.format_byte_size_binary(c.file.size)} % if c.lf_node: | ${_('LargeFile')} ${h.format_byte_size_binary(c.lf_node.size)} % endif - | ${c.file.mimetype} - | ${h.get_lexer_for_filenode(c.file).__class__.__name__} + + | ${c.file.mimetype} + + + % if not c.file_size_too_big: + | + ${h.get_lexer_for_filenode(c.file).__class__.__name__} + + % endif +
@@ -94,46 +108,45 @@
- %if c.file.is_binary: <% rendered_binary = h.render_binary(c.repo_name, c.file)%> % if rendered_binary: ${rendered_binary} % else:
- ${_('Binary file (%s)') % c.file.mimetype} + ${_('Binary file ({})').format(c.file.mimetype)}
% endif %else: - % if c.file.size < c.visual.cut_off_limit_file: - %if c.renderer and not c.annotate: - ## pick relative url based on renderer - <% - relative_urls = { - 'raw': h.route_path('repo_file_raw',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path), - 'standard': h.route_path('repo_files',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path), - } - %> - ${h.render(c.file.content, renderer=c.renderer, relative_urls=relative_urls)} - %else: - - %if c.annotate: - <% color_hasher = h.color_hasher() %> - %for annotation, lines in c.annotated_lines: - ${sourceblock.render_annotation_lines(annotation, lines, color_hasher)} - %endfor + % if c.file_size_too_big: + ${_('File size {} is bigger then allowed limit {}. ').format(h.format_byte_size_binary(c.file.size), h.format_byte_size_binary(c.visual.cut_off_limit_file))} ${h.link_to(_('Show as raw'), + h.route_path('repo_file_raw',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path))} + % else: + %if c.renderer and not c.annotate: + ## pick relative url based on renderer + <% + relative_urls = { + 'raw': h.route_path('repo_file_raw',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path), + 'standard': h.route_path('repo_files',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path), + } + %> + ${h.render(c.file.content, renderer=c.renderer, relative_urls=relative_urls)} %else: - %for line_num, tokens in enumerate(c.lines, 1): - ${sourceblock.render_line(line_num, tokens)} - %endfor +
+ %if c.annotate: + <% color_hasher = h.color_hasher() %> + %for annotation, lines in c.annotated_lines: + ${sourceblock.render_annotation_lines(annotation, lines, color_hasher)} + %endfor + %else: + %for line_num, tokens in enumerate(c.lines, 1): + ${sourceblock.render_line(line_num, tokens)} + %endfor + %endif +
%endif - - %endif - %else: - ${_('File size {} is bigger then allowed limit {}. ').format(h.format_byte_size_binary(c.file.size), h.format_byte_size_binary(c.visual.cut_off_limit_file))} ${h.link_to(_('Show as raw'), - h.route_path('repo_file_raw',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path))} + % endif %endif - %endif