Commit aed0387f authored by Douwe Maan's avatar Douwe Maan
Browse files

Consistent diff and blob size limit names

parent e657d9bf3d81
......@@ -18,7 +18,7 @@ def render_blob_json(blob)
}
end
def override_max_blob_size(blob)
blob.override_max_size! if params[:override_max_size] == 'true'
def conditionally_expand_blob(blob)
blob.expand! if params[:expanded] == 'true'
end
end
......@@ -27,7 +27,7 @@ def browse
def file
blob = @entry.blob
override_max_blob_size(blob)
conditionally_expand_blob(blob)
respond_to do |format|
format.html do
......
......@@ -35,7 +35,7 @@ def create
end
def show
override_max_blob_size(@blob)
conditionally_expand_blob(@blob)
respond_to do |format|
format.html do
......
......@@ -56,7 +56,7 @@ def update
def show
blob = @snippet.blob
override_max_blob_size(blob)
conditionally_expand_blob(blob)
respond_to do |format|
format.html do
......
......@@ -58,7 +58,7 @@ def update
def show
blob = @snippet.blob
override_max_blob_size(blob)
conditionally_expand_blob(blob)
@note = Note.new(noteable: @snippet)
@noteable = @snippet
......
......@@ -240,14 +240,10 @@ def open_raw_blob_button(blob)
def blob_render_error_reason(viewer)
case viewer.render_error
when :collapsed
"it is larger than #{number_to_human_size(viewer.collapse_limit)}"
when :too_large
max_size =
if viewer.can_override_max_size?
viewer.overridable_max_size
else
viewer.max_size
end
"it is larger than #{number_to_human_size(max_size)}"
"it is larger than #{number_to_human_size(viewer.size_limit)}"
when :server_side_but_stored_externally
case viewer.blob.external_storage
when :lfs
......@@ -264,8 +260,8 @@ def blob_render_error_options(viewer)
error = viewer.render_error
options = []
if error == :too_large && viewer.can_override_max_size?
options << link_to('load it anyway', url_for(params.merge(viewer: viewer.type, override_max_size: true, format: nil)))
if error == :collapsed
options << link_to('load it anyway', url_for(params.merge(viewer: viewer.type, expanded: true, format: nil)))
end
# If the error is `:server_side_but_stored_externally`, the simple viewer will show the same error,
......
......@@ -8,8 +8,8 @@ def mark_inline_diffs(old_line, new_line)
[marked_old_line, marked_new_line]
end
def expand_all_diffs?
params[:expand_all_diffs].present?
def diffs_expanded?
params[:expanded].present?
end
def diff_view
......@@ -22,10 +22,10 @@ def diff_view
end
def diff_options
options = { ignore_whitespace_change: hide_whitespace?, no_collapse: expand_all_diffs? }
options = { ignore_whitespace_change: hide_whitespace?, expanded: diffs_expanded? }
if action_name == 'diff_for_path'
options[:no_collapse] = true
options[:expanded] = true
options[:paths] = params.values_at(:old_path, :new_path)
end
......
......@@ -102,10 +102,6 @@ def empty?
raw_size == 0
end
def too_large?
size && truncated?
end
def external_storage_error?
if external_storage == :lfs
!project&.lfs_enabled?
......@@ -160,7 +156,7 @@ def video?
end
def readable_text?
text? && !stored_externally? && !too_large?
text? && !stored_externally? && !truncated?
end
def simple_viewer
......@@ -187,9 +183,9 @@ def show_viewer_switcher?
rendered_as_text? && rich_viewer
end
def override_max_size!
simple_viewer&.override_max_size = true
rich_viewer&.override_max_size = true
def expand!
simple_viewer&.expanded = true
rich_viewer&.expanded = true
end
private
......
......@@ -7,8 +7,8 @@ module Auxiliary
included do
self.loading_partial_name = 'loading_auxiliary'
self.type = :auxiliary
self.overridable_max_size = 100.kilobytes
self.max_size = 100.kilobytes
self.collapse_limit = 100.kilobytes
self.size_limit = 100.kilobytes
end
def visible_to?(current_user)
......
......@@ -2,14 +2,14 @@ module BlobViewer
class Base
PARTIAL_PATH_PREFIX = 'projects/blob/viewers'.freeze
class_attribute :partial_name, :loading_partial_name, :type, :extensions, :file_types, :load_async, :binary, :switcher_icon, :switcher_title, :overridable_max_size, :max_size
class_attribute :partial_name, :loading_partial_name, :type, :extensions, :file_types, :load_async, :binary, :switcher_icon, :switcher_title, :collapse_limit, :size_limit
self.loading_partial_name = 'loading'
delegate :partial_path, :loading_partial_path, :rich?, :simple?, :text?, :binary?, to: :class
attr_reader :blob
attr_accessor :override_max_size
attr_accessor :expanded
delegate :project, to: :blob
......@@ -61,24 +61,16 @@ def load_async?
self.class.load_async? && render_error.nil?
end
def exceeds_overridable_max_size?
overridable_max_size && blob.raw_size > overridable_max_size
end
def exceeds_max_size?
max_size && blob.raw_size > max_size
end
def collapsed?
return @collapsed if defined?(@collapsed)
def can_override_max_size?
exceeds_overridable_max_size? && !exceeds_max_size?
@collapsed = !expanded && collapse_limit && blob.raw_size > collapse_limit
end
def too_large?
if override_max_size
exceeds_max_size?
else
exceeds_overridable_max_size?
end
return @too_large if defined?(@too_large)
@too_large = size_limit && blob.raw_size > size_limit
end
# This method is used on the server side to check whether we can attempt to
......@@ -95,6 +87,8 @@ def too_large?
def render_error
if too_large?
:too_large
elsif collapsed?
:collapsed
end
end
......
......@@ -4,8 +4,8 @@ module ClientSide
included do
self.load_async = false
self.overridable_max_size = 10.megabytes
self.max_size = 50.megabytes
self.collapse_limit = 10.megabytes
self.size_limit = 50.megabytes
end
end
end
......@@ -4,8 +4,8 @@ module ServerSide
included do
self.load_async = true
self.overridable_max_size = 2.megabytes
self.max_size = 5.megabytes
self.collapse_limit = 2.megabytes
self.size_limit = 5.megabytes
end
def prepare!
......
......@@ -5,7 +5,7 @@ class Text < Base
self.partial_name = 'text'
self.binary = false
self.overridable_max_size = 1.megabyte
self.max_size = 10.megabytes
self.collapse_limit = 1.megabyte
self.size_limit = 10.megabytes
end
end
......@@ -220,10 +220,10 @@ def raw_diffs(*args)
def diffs(diff_options = {})
if compare
# When saving MR diffs, `no_collapse` is implicitly added (because we need
# When saving MR diffs, `expanded` is implicitly added (because we need
# to save the entire contents to the DB), so add that here for
# consistency.
compare.diffs(diff_options.merge(no_collapse: true))
compare.diffs(diff_options.merge(expanded: true))
else
merge_request_diff.diffs(diff_options)
end
......
......@@ -3,7 +3,7 @@
.diff-content
- if diff_file.too_large?
.nothing-here-block This diff could not be displayed because it is too large.
- elsif blob.too_large?
- elsif blob.truncated?
.nothing-here-block The file could not be displayed because it is too large.
- elsif blob.readable_text?
- if !diff_file.repository.diffable?(blob)
......
......@@ -5,8 +5,8 @@
.content-block.oneline-block.files-changed
.inline-parallel-buttons
- if !expand_all_diffs? && diff_files.any? { |diff_file| diff_file.collapsed? }
= link_to 'Expand all', url_for(params.merge(expand_all_diffs: 1, format: nil)), class: 'btn btn-default'
- if !diffs_expanded? && diff_files.any? { |diff_file| diff_file.collapsed? }
= link_to 'Expand all', url_for(params.merge(expanded: 1, format: nil)), class: 'btn btn-default'
- if show_whitespace_toggle
- if current_controller?(:commit)
= commit_diff_whitespace_link(diffs.project, @commit, class: 'hidden-xs')
......
......@@ -176,7 +176,7 @@ class Commits < Grape::API
}
if params[:path]
commit.raw_diffs(all_diffs: true).each do |diff|
commit.raw_diffs(no_limits: true).each do |diff|
next unless diff.new_path == params[:path]
lines = Gitlab::Diff::Parser.new.parse(diff.diff.each_line)
......
......@@ -331,7 +331,7 @@ class MergeRequest < MergeRequestBasic
class MergeRequestChanges < MergeRequest
expose :diffs, as: :changes, using: Entities::RepoDiff do |compare, _|
compare.raw_diffs(all_diffs: true).to_a
compare.raw_diffs(no_limits: true).to_a
end
end
......@@ -344,7 +344,7 @@ class MergeRequestDiffFull < MergeRequestDiff
expose :commits, using: Entities::RepoCommit
expose :diffs, using: Entities::RepoDiff do |compare, _|
compare.raw_diffs(all_diffs: true).to_a
compare.raw_diffs(no_limits: true).to_a
end
end
......@@ -548,7 +548,7 @@ class Compare < Grape::Entity
end
expose :diffs, using: Entities::RepoDiff do |compare, options|
compare.diffs(all_diffs: true).to_a
compare.diffs(no_limits: true).to_a
end
expose :compare_timeout do |compare, options|
......
......@@ -167,7 +167,7 @@ class Commits < Grape::API
}
if params[:path]
commit.raw_diffs(all_diffs: true).each do |diff|
commit.raw_diffs(no_limits: true).each do |diff|
next unless diff.new_path == params[:path]
lines = Gitlab::Diff::Parser.new.parse(diff.diff.each_line)
......
......@@ -226,7 +226,7 @@ class Deployment < Grape::Entity
class MergeRequestChanges < MergeRequest
expose :diffs, as: :changes, using: ::API::Entities::RepoDiff do |compare, _|
compare.raw_diffs(all_diffs: true).to_a
compare.raw_diffs(no_limits: true).to_a
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment