Skip to content
Snippets Groups Projects
Commit aed0387f authored by Douwe Maan's avatar Douwe Maan
Browse files

Consistent diff and blob size limit names

parent 1ac12698
No related branches found
No related tags found
No related merge requests found
Showing
with 48 additions and 62 deletions
Loading
Loading
@@ -18,7 +18,7 @@ module RendersBlob
}
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
Loading
Loading
@@ -27,7 +27,7 @@ class Projects::ArtifactsController < Projects::ApplicationController
 
def file
blob = @entry.blob
override_max_blob_size(blob)
conditionally_expand_blob(blob)
 
respond_to do |format|
format.html do
Loading
Loading
Loading
Loading
@@ -35,7 +35,7 @@ class Projects::BlobController < Projects::ApplicationController
end
 
def show
override_max_blob_size(@blob)
conditionally_expand_blob(@blob)
 
respond_to do |format|
format.html do
Loading
Loading
Loading
Loading
@@ -56,7 +56,7 @@ class Projects::SnippetsController < Projects::ApplicationController
 
def show
blob = @snippet.blob
override_max_blob_size(blob)
conditionally_expand_blob(blob)
 
respond_to do |format|
format.html do
Loading
Loading
Loading
Loading
@@ -58,7 +58,7 @@ class SnippetsController < ApplicationController
 
def show
blob = @snippet.blob
override_max_blob_size(blob)
conditionally_expand_blob(blob)
 
@note = Note.new(noteable: @snippet)
@noteable = @snippet
Loading
Loading
Loading
Loading
@@ -240,14 +240,10 @@ module BlobHelper
 
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
Loading
Loading
@@ -264,8 +260,8 @@ module BlobHelper
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,
Loading
Loading
Loading
Loading
@@ -8,8 +8,8 @@ module DiffHelper
[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
Loading
Loading
@@ -22,10 +22,10 @@ module DiffHelper
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
 
Loading
Loading
Loading
Loading
@@ -102,10 +102,6 @@ class Blob < SimpleDelegator
raw_size == 0
end
 
def too_large?
size && truncated?
end
def external_storage_error?
if external_storage == :lfs
!project&.lfs_enabled?
Loading
Loading
@@ -160,7 +156,7 @@ class Blob < SimpleDelegator
end
 
def readable_text?
text? && !stored_externally? && !too_large?
text? && !stored_externally? && !truncated?
end
 
def simple_viewer
Loading
Loading
@@ -187,9 +183,9 @@ class Blob < SimpleDelegator
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
Loading
Loading
Loading
Loading
@@ -7,8 +7,8 @@ module BlobViewer
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)
Loading
Loading
Loading
Loading
@@ -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
 
Loading
Loading
@@ -61,24 +61,16 @@ module BlobViewer
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
Loading
Loading
@@ -95,6 +87,8 @@ module BlobViewer
def render_error
if too_large?
:too_large
elsif collapsed?
:collapsed
end
end
 
Loading
Loading
Loading
Loading
@@ -4,8 +4,8 @@ module BlobViewer
 
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
Loading
Loading
@@ -4,8 +4,8 @@ module BlobViewer
 
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!
Loading
Loading
Loading
Loading
@@ -5,7 +5,7 @@ module BlobViewer
 
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
Loading
Loading
@@ -220,10 +220,10 @@ class MergeRequest < ActiveRecord::Base
 
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
Loading
Loading
Loading
Loading
@@ -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)
Loading
Loading
Loading
Loading
@@ -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')
Loading
Loading
Loading
Loading
@@ -176,7 +176,7 @@ module 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)
 
Loading
Loading
Loading
Loading
@@ -331,7 +331,7 @@ module API
 
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
 
Loading
Loading
@@ -344,7 +344,7 @@ module API
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
 
Loading
Loading
@@ -548,7 +548,7 @@ module API
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|
Loading
Loading
Loading
Loading
@@ -167,7 +167,7 @@ module 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)
 
Loading
Loading
Loading
Loading
@@ -226,7 +226,7 @@ module API
 
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
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment