diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-05-05 12:31:10 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-05-05 12:31:10 +0200 |
commit | e944fd7064b5a04a334b6c500c9ee7db29a46538 (patch) | |
tree | 7418e54f3774ca676040a16a30a4a9cd7c922100 /app/models/blob.rb | |
parent | 3aa92cb5cbe8456c845e16d14489591dd81dbcb3 (diff) | |
parent | 3a2b60f7a0109cdb84e8727a2625318a746e84dc (diff) | |
download | gitlab-ce-fix/gb/hide-environment-external-url-btn-when-not-provided.tar.gz |
Merge commit '3a2b60f7a' from 'master'fix/gb/hide-environment-external-url-btn-when-not-provided
* commit '3a2b60f7a0109cdb84e8727a2625318a746e84dc': (254 commits)
Fixed Karma spec
Reject EE reserved namespace paths in CE as well
Updated webpack config
Include the bundler:audit job into the static-analysis job
Document serializers
Add artifact file page that uses the blob viewer
Pipeline table mini graph dropdown remains open when table is refreshed
Adds off for event hub
Compile gitlab-shell go executables
Allow to create new branch and empty WIP merge request from issue page
Moved to a view spec
Improving copy of CONTRIBUTING.md, PROCESS.md, and code_review.md
Convert seconds to minutes and hours on chat notifations
Disable navigation to Pages config if Pages is disabled
Sort the network graph both by commit date and topographically.
Add tooltips to note action buttons
Add breadcrumb, build header and pipelines submenu to artifacts browser
Update todos screenshots
removes the possibility of commit messages having carriage returns
Handle incoming emails from aliases correctly
...
Diffstat (limited to 'app/models/blob.rb')
-rw-r--r-- | app/models/blob.rb | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/app/models/blob.rb b/app/models/blob.rb index 1cdb8811cff..a4fae22a0c4 100644 --- a/app/models/blob.rb +++ b/app/models/blob.rb @@ -28,7 +28,7 @@ class Blob < SimpleDelegator BlobViewer::Sketch, BlobViewer::Video, - + BlobViewer::PDF, BlobViewer::BinarySTL, @@ -75,19 +75,37 @@ class Blob < SimpleDelegator end def no_highlighting? - size && size > MAXIMUM_TEXT_HIGHLIGHT_SIZE + raw_size && raw_size > MAXIMUM_TEXT_HIGHLIGHT_SIZE + end + + def empty? + raw_size == 0 end def too_large? size && truncated? end + def external_storage_error? + if external_storage == :lfs + !project&.lfs_enabled? + else + false + end + end + + def stored_externally? + return @stored_externally if defined?(@stored_externally) + + @stored_externally = external_storage && !external_storage_error? + end + # Returns the size of the file that this blob represents. If this blob is an # LFS pointer, this is the size of the file stored in LFS. Otherwise, this is # the size of the blob itself. def raw_size - if valid_lfs_pointer? - lfs_size + if stored_externally? + external_size else size end @@ -98,9 +116,13 @@ class Blob < SimpleDelegator # text-based rich blob viewer matched on the file's extension. Otherwise, this # depends on the type of the blob itself. def raw_binary? - if valid_lfs_pointer? + if stored_externally? if rich_viewer rich_viewer.binary? + elsif Linguist::Language.find_by_filename(name).any? + false + elsif _mime_type + _mime_type.binary? else true end @@ -118,15 +140,7 @@ class Blob < SimpleDelegator end def readable_text? - text? && !valid_lfs_pointer? && !too_large? - end - - def valid_lfs_pointer? - lfs_pointer? && project&.lfs_enabled? - end - - def invalid_lfs_pointer? - lfs_pointer? && !project&.lfs_enabled? + text? && !stored_externally? && !too_large? end def simple_viewer @@ -165,10 +179,10 @@ class Blob < SimpleDelegator end def rich_viewer_class - return if invalid_lfs_pointer? || empty? + return if empty? || external_storage_error? classes = - if valid_lfs_pointer? + if stored_externally? BINARY_VIEWERS + TEXT_VIEWERS elsif binary? BINARY_VIEWERS |