Commit 6d0dcb6614fc0743d50ffe68bf61c2c50728c1d6

Authored by Dmitriy Zaporozhets
1 parent 1ea0dd0f

Reduce max commit diff size. Added Commit::DIFF_SAFE_SIZE

app/assets/stylesheets/gitlab_bootstrap/common.scss
... ... @@ -26,6 +26,7 @@
26 26 .underlined { border-bottom: 1px solid #CCC; }
27 27 .no-borders { border:none; }
28 28 .vlink { color: $link_color !important; }
  29 +.underlined_link { text-decoration: underline; }
29 30 .borders { border: 1px solid #ccc; @include shade; }
30 31 .hint { font-style: italic; color: #999; }
31 32  
... ...
app/contexts/commit_load_context.rb
... ... @@ -21,7 +21,7 @@ class CommitLoadContext < BaseContext
21 21 result[:notes_count] = line_notes.count + project.commit_notes(commit).count
22 22  
23 23 begin
24   - result[:suppress_diff] = true if commit.diffs.size > 200 && !params[:force_show_diff]
  24 + result[:suppress_diff] = true if commit.diffs.size > Commit::DIFF_SAFE_SIZE && !params[:force_show_diff]
25 25 rescue Grit::Git::GitTimeout
26 26 result[:suppress_diff] = true
27 27 result[:status] = :huge_commit
... ...
app/models/commit.rb
... ... @@ -4,6 +4,11 @@ class Commit
4 4 include StaticModel
5 5 extend ActiveModel::Naming
6 6  
  7 + # Safe amount of files with diffs in one commit to render
  8 + # Used to prevent 500 error on huge commits by suppressing diff
  9 + #
  10 + DIFF_SAFE_SIZE = 100
  11 +
7 12 attr_accessor :commit, :head, :refs
8 13  
9 14 delegate :message, :authored_date, :committed_date, :parents, :sha,
... ...
app/views/commits/_diffs.html.haml
1 1 - if @suppress_diff
2 2 .alert-message.block-message
3 3 %p
4   - %strong Warning! Large commit with more then 200 files changed.
  4 + %strong Warning! Large commit with more then #{Commit::DIFF_SAFE_SIZE} files changed.
5 5 %p To prevent performance issue we rejected diff information.
6 6 %p
7 7 But if you still want to see diff
8   - = link_to "click this link", project_commit_path(@project, @commit, force_show_diff: true), class: "dark"
  8 + = link_to "click this link", project_commit_path(@project, @commit, force_show_diff: true), class: "underlined_link"
9 9  
10 10 %p.cgray
11 11 Showing #{pluralize(diffs.count, "changed file")}
... ... @@ -35,10 +35,10 @@
35 35 - if file.text?
36 36 = render "commits/text_file", diff: diff, index: i
37 37 - elsif file.image?
38   - - if diff.renamed_file || diff.new_file || diff.deleted_file
  38 + - if diff.renamed_file || diff.new_file || diff.deleted_file
39 39 .diff_file_content_image
40 40 %img{class: image_diff_class(diff), src: "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"}
41   - - else
  41 + - else
42 42 - old_file = (@commit.prev_commit.tree / diff.old_path)
43 43 .diff_file_content_image.img_compared
44 44 %img{class: "diff_image_removed", src: "data:#{file.mime_type};base64,#{Base64.encode64(old_file.data)}"}
... ...