Commit 6d0dcb6614fc0743d50ffe68bf61c2c50728c1d6
1 parent
1ea0dd0f
Exists in
master
and in
4 other branches
Reduce max commit diff size. Added Commit::DIFF_SAFE_SIZE
Showing
4 changed files
with
11 additions
and
5 deletions
Show diff stats
app/assets/stylesheets/gitlab_bootstrap/common.scss
@@ -26,6 +26,7 @@ | @@ -26,6 +26,7 @@ | ||
26 | .underlined { border-bottom: 1px solid #CCC; } | 26 | .underlined { border-bottom: 1px solid #CCC; } |
27 | .no-borders { border:none; } | 27 | .no-borders { border:none; } |
28 | .vlink { color: $link_color !important; } | 28 | .vlink { color: $link_color !important; } |
29 | +.underlined_link { text-decoration: underline; } | ||
29 | .borders { border: 1px solid #ccc; @include shade; } | 30 | .borders { border: 1px solid #ccc; @include shade; } |
30 | .hint { font-style: italic; color: #999; } | 31 | .hint { font-style: italic; color: #999; } |
31 | 32 |
app/contexts/commit_load_context.rb
@@ -21,7 +21,7 @@ class CommitLoadContext < BaseContext | @@ -21,7 +21,7 @@ class CommitLoadContext < BaseContext | ||
21 | result[:notes_count] = line_notes.count + project.commit_notes(commit).count | 21 | result[:notes_count] = line_notes.count + project.commit_notes(commit).count |
22 | 22 | ||
23 | begin | 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 | rescue Grit::Git::GitTimeout | 25 | rescue Grit::Git::GitTimeout |
26 | result[:suppress_diff] = true | 26 | result[:suppress_diff] = true |
27 | result[:status] = :huge_commit | 27 | result[:status] = :huge_commit |
app/models/commit.rb
@@ -4,6 +4,11 @@ class Commit | @@ -4,6 +4,11 @@ class Commit | ||
4 | include StaticModel | 4 | include StaticModel |
5 | extend ActiveModel::Naming | 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 | attr_accessor :commit, :head, :refs | 12 | attr_accessor :commit, :head, :refs |
8 | 13 | ||
9 | delegate :message, :authored_date, :committed_date, :parents, :sha, | 14 | delegate :message, :authored_date, :committed_date, :parents, :sha, |
app/views/commits/_diffs.html.haml
1 | - if @suppress_diff | 1 | - if @suppress_diff |
2 | .alert-message.block-message | 2 | .alert-message.block-message |
3 | %p | 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 | %p To prevent performance issue we rejected diff information. | 5 | %p To prevent performance issue we rejected diff information. |
6 | %p | 6 | %p |
7 | But if you still want to see diff | 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 | %p.cgray | 10 | %p.cgray |
11 | Showing #{pluralize(diffs.count, "changed file")} | 11 | Showing #{pluralize(diffs.count, "changed file")} |
@@ -35,10 +35,10 @@ | @@ -35,10 +35,10 @@ | ||
35 | - if file.text? | 35 | - if file.text? |
36 | = render "commits/text_file", diff: diff, index: i | 36 | = render "commits/text_file", diff: diff, index: i |
37 | - elsif file.image? | 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 | .diff_file_content_image | 39 | .diff_file_content_image |
40 | %img{class: image_diff_class(diff), src: "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"} | 40 | %img{class: image_diff_class(diff), src: "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"} |
41 | - - else | 41 | + - else |
42 | - old_file = (@commit.prev_commit.tree / diff.old_path) | 42 | - old_file = (@commit.prev_commit.tree / diff.old_path) |
43 | .diff_file_content_image.img_compared | 43 | .diff_file_content_image.img_compared |
44 | %img{class: "diff_image_removed", src: "data:#{file.mime_type};base64,#{Base64.encode64(old_file.data)}"} | 44 | %img{class: "diff_image_removed", src: "data:#{file.mime_type};base64,#{Base64.encode64(old_file.data)}"} |