diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index c2a19e4ac10a73f07d3abad3ca19756236110625..6307790d4e70d75ed642f0b755cf3c4f80a0859e 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -1,16 +1,20 @@ module DiffHelper - def safe_diff_files(diffs) + def allowed_diff_size if diff_hard_limit_enabled? - diffs.first(Commit::DIFF_HARD_LIMIT_FILES) + Commit::DIFF_HARD_LIMIT_FILES else - diffs.first(Commit::DIFF_SAFE_FILES) - end.map do |diff| + Commit::DIFF_SAFE_FILES + end + end + + def safe_diff_files(diffs) + diffs.first(allowed_diff_size).map do |diff| Gitlab::Diff::File.new(diff) end end def show_diff_size_warninig?(diffs) - safe_diff_files(diffs).size < diffs.size + diffs.size > allowed_diff_size end def diff_hard_limit_enabled? diff --git a/app/views/projects/diffs/_diffs.html.haml b/app/views/projects/diffs/_diffs.html.haml index c4eb78158667a2cc1503b588d3f3484e84e69591..49b3dc6941a648c4245155ad9280ed41806bdde6 100644 --- a/app/views/projects/diffs/_diffs.html.haml +++ b/app/views/projects/diffs/_diffs.html.haml @@ -11,6 +11,7 @@ - params_copy[:view] = 'inline' = link_to "Inline Diff", url_for(params_copy), {id: "commit-diff-viewtype"} + - if show_diff_size_warninig?(diffs) = render 'projects/diffs/warning', diffs: diffs diff --git a/app/views/projects/diffs/_warning.html.haml b/app/views/projects/diffs/_warning.html.haml index ee85956d876777ab0720a050dec6a65444060a10..86ed6bbeaa26ccecbe3a213045e9c4f57199ddf3 100644 --- a/app/views/projects/diffs/_warning.html.haml +++ b/app/views/projects/diffs/_warning.html.haml @@ -14,6 +14,6 @@ = link_to "Email patch", project_merge_request_path(@project, @merge_request, format: :patch), class: "btn btn-warning btn-small" %p To preserve performance only - %strong #{safe_diff_files(@project, diffs).size} of #{diffs.size} + %strong #{allowed_diff_size} of #{diffs.size} files displayed.