lib/gitlab_git/blob.rb in gitlab_git-7.2.24 vs lib/gitlab_git/blob.rb in gitlab_git-8.0.0

- old
+ new

@@ -5,10 +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 + attr_accessor :name, :path, :size, :data, :mode, :id, :commit_id class << self def find(repository, sha, path) commit = repository.lookup(sha) @@ -26,11 +31,11 @@ if blob Blob.new( id: blob.oid, name: blob_entry[:name], size: blob.size, - data: blob.content, + data: blob.content(DATA_FRAGMENT_SIZE), mode: blob_entry[:filemode].to_s(8), path: path, commit_id: sha, ) end @@ -41,11 +46,11 @@ blob = repository.lookup(sha) Blob.new( id: blob.oid, size: blob.size, - data: blob.content, + data: blob.content(DATA_FRAGMENT_SIZE), ) end # Recursive search of blob id by path # @@ -213,9 +218,17 @@ !data || data == '' end def data encode! @data + end + + # Load all blob data (not just the first DATA_FRAGMENT_SIZE bytes) into + # memory as a Ruby string. + def load_all_data!(repository) + return if @data == '' # don't mess with submodule blobs + + @data = repository.lookup(id).content end def name encode! @name end