lib/gitlab_git/blob.rb in gitlab_git-10.1.2 vs lib/gitlab_git/blob.rb in gitlab_git-10.1.3
- old
+ new
@@ -5,14 +5,15 @@
module Git
class Blob
include Linguist::BlobHelper
include EncodingHelper
- # This number needs to be large enough to allow reliable content /
- # encoding detection (Linguist) and LFS pointer parsing. All other cases
- # where we need full blob data should use load_all_data!.
- DATA_FRAGMENT_SIZE = 1024
+ # This number is the maximum amount of data that we want to display to
+ # the user. We load as much as we can for encoding detection
+ # (Linguist) and LFS pointer parsing. All other cases where we need full
+ # blob data should use load_all_data!.
+ MAX_DATA_DISPLAY_SIZE = 10485760
attr_accessor :name, :path, :size, :data, :mode, :id, :commit_id
class << self
def find(repository, sha, path)
@@ -31,11 +32,11 @@
if blob
Blob.new(
id: blob.oid,
name: blob_entry[:name],
size: blob.size,
- data: blob.content(DATA_FRAGMENT_SIZE),
+ data: blob.content(MAX_DATA_DISPLAY_SIZE),
mode: blob_entry[:filemode].to_s(8),
path: path,
commit_id: sha,
)
end
@@ -46,11 +47,11 @@
blob = repository.lookup(sha)
Blob.new(
id: blob.oid,
size: blob.size,
- data: blob.content(DATA_FRAGMENT_SIZE),
+ data: blob.content(MAX_DATA_DISPLAY_SIZE),
)
end
# Recursive search of blob id by path
#
@@ -222,11 +223,11 @@
def data
encode! @data
end
- # Load all blob data (not just the first DATA_FRAGMENT_SIZE bytes) into
+ # Load all blob data (not just the first MAX_DATA_DISPLAY_SIZE bytes) into
# memory as a Ruby string.
def load_all_data!(repository)
return if @data == '' # don't mess with submodule blobs
return @data if @loaded_all_data
@@ -261,9 +262,13 @@
size = data.match(/(?<=size )([0-9]+)/)
return size[1] if size
end
nil
+ end
+
+ def truncated?
+ size > data.size
end
private
def has_lfs_version_key?