diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/extracts_path.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/checks/change_access.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/checks/lfs_integrity.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/git/blob.rb | 25 | ||||
-rw-r--r-- | lib/gitlab/git/raw_diff_change.rb | 4 |
5 files changed, 34 insertions, 7 deletions
diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb index a9b04c183ad..48e3d81e860 100644 --- a/lib/extracts_path.rb +++ b/lib/extracts_path.rb @@ -138,8 +138,7 @@ module ExtractsPath end def lfs_blob_ids - blob_ids = tree.blobs.map(&:id) - @lfs_blob_ids = Gitlab::Git::Blob.batch_lfs_pointers(@project.repository, blob_ids).map(&:id) # rubocop:disable Gitlab/ModuleWithInstanceVariables + @lfs_blob_ids = Gitlab::Git::Blob.lfs_pointers_from_tree(@project.repository, tree).map(&:id) # rubocop:disable Gitlab/ModuleWithInstanceVariables end private diff --git a/lib/gitlab/checks/change_access.rb b/lib/gitlab/checks/change_access.rb index 51ba09aa129..e2326fa882c 100644 --- a/lib/gitlab/checks/change_access.rb +++ b/lib/gitlab/checks/change_access.rb @@ -169,7 +169,7 @@ module Gitlab end def lfs_objects_exist_check - lfs_check = Checks::LfsIntegrity.new(project, newrev) + lfs_check = Checks::LfsIntegrity.new(project, oldrev, newrev) if lfs_check.objects_missing? raise GitAccess::UnauthorizedError, ERROR_MESSAGES[:lfs_objects_missing] diff --git a/lib/gitlab/checks/lfs_integrity.rb b/lib/gitlab/checks/lfs_integrity.rb index f0e5773ec3c..603cb36d85d 100644 --- a/lib/gitlab/checks/lfs_integrity.rb +++ b/lib/gitlab/checks/lfs_integrity.rb @@ -1,17 +1,16 @@ module Gitlab module Checks class LfsIntegrity - REV_LIST_OBJECT_LIMIT = 2_000 - - def initialize(project, newrev) + def initialize(project, oldrev, newrev) @project = project + @oldrev = oldrev @newrev = newrev end def objects_missing? return false unless @newrev && @project.lfs_enabled? - new_lfs_pointers = Gitlab::Git::LfsChanges.new(@project.repository, @newrev).new_pointers(object_limit: REV_LIST_OBJECT_LIMIT) + new_lfs_pointers = Gitlab::Git::Blob.lfs_pointers_between(@project.repository, @oldrev, @newrev) return false unless new_lfs_pointers.present? diff --git a/lib/gitlab/git/blob.rb b/lib/gitlab/git/blob.rb index 156d077a69c..f90f90fbe26 100644 --- a/lib/gitlab/git/blob.rb +++ b/lib/gitlab/git/blob.rb @@ -85,6 +85,31 @@ module Gitlab end end + # Find LFS blobs old_rev and new_rev + # old_rev and new_rev are commit ID's + # Returns array of Gitlab::Git::Blob + # Does not guarantee blob data will be set + def lfs_pointers_between(repository, old_rev, new_rev) + revs_with_paths = repository.raw_changes_between(old_rev, new_rev) + .reject { |c| c.deleted? } + .select { |c| size_could_be_lfs?(c.blob_size) } + .map! { |c| [new_rev, c.new_path] } + + return [] if revs_with_paths.blank? + + batch(repository, revs_with_paths, blob_size_limit: LFS_POINTER_MAX_SIZE) + .select(&:lfs_pointer?) + end + + def lfs_pointers_from_tree(repository, tree) + revs_with_paths = tree.blobs.map! { |blob| [tree.sha, blob.path] } + + return [] if revs_with_paths.blank? + + batch(repository, revs_with_paths, blob_size_limit: LFS_POINTER_MAX_SIZE) + .select { |blob| size_could_be_lfs?(blob.size) && blob.lfs_pointer? } + end + def binary?(data) EncodingHelper.detect_libgit2_binary?(data) end diff --git a/lib/gitlab/git/raw_diff_change.rb b/lib/gitlab/git/raw_diff_change.rb index 98de9328071..a2815c5603d 100644 --- a/lib/gitlab/git/raw_diff_change.rb +++ b/lib/gitlab/git/raw_diff_change.rb @@ -17,6 +17,10 @@ module Gitlab end end + def deleted? + operation == :deleted + end + private # Input data has the following format: |