diff options
author | James Edwards-Jones <jedwardsjones@gitlab.com> | 2018-03-14 23:45:57 +0000 |
---|---|---|
committer | James Edwards-Jones <jedwardsjones@gitlab.com> | 2018-03-15 21:49:00 +0000 |
commit | 237a32cc90d7e2c4b96e3a9ba0fd9e77ff3fc166 (patch) | |
tree | 1ad0bd7901dd016f0bf4c63a76a9bff927a5a10c /app/services/lfs | |
parent | 1baac9211238f60d2d2a50cccd0bea6979bfa6ba (diff) | |
download | gitlab-ce-237a32cc90d7e2c4b96e3a9ba0fd9e77ff3fc166.tar.gz |
Avoid failed integrity check by linking LfsObjectProjects sooner
Attempted commits were failing due to the pre-recieve LfsIntegrity
check. This is skipped during tests making this failure silent.
Diffstat (limited to 'app/services/lfs')
-rw-r--r-- | app/services/lfs/file_transformer.rb | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/app/services/lfs/file_transformer.rb b/app/services/lfs/file_transformer.rb index 7c93659b60d..0235d07e529 100644 --- a/app/services/lfs/file_transformer.rb +++ b/app/services/lfs/file_transformer.rb @@ -1,16 +1,15 @@ module Lfs - # Usage: Open a `.link_lfs_objects` block, call `new_file` on the yielded object - # as many times as needed. LfsObjectProject links will be saved if the - # return value of the block is truthy. + # Usage: Calling `new_file` check to see if a file should be in LFS and + # return a transformed result with `content` and `encoding` to commit. # - # Calling `new_file` will check the path to see if it should be in LFS, - # save and LFS pointer of needed and return its content to be saved in - # a commit. If the file isn't LFS the untransformed content is returned. + # For LFS an LfsObject linked to the project is stored and an LFS + # pointer returned. If the file isn't in LFS the untransformed content + # is returned to save in the commit. + # + # transformer = Lfs::FileTransformer.new(project, @branch_name) + # content_or_lfs_pointer = transformer.new_file(file_path, content).content + # create_transformed_commit(content_or_lfs_pointer) # - # Lfs::FileTransformer.link_lfs_objects(project, @branch_name) do |transformer| - # content_or_lfs_pointer = transformer.new_file(file_path, file_content) - # create_transformed_commit(content_or_lfs_pointer) - # end class FileTransformer attr_reader :project, :branch_name @@ -21,20 +20,12 @@ module Lfs @branch_name = branch_name end - def self.link_lfs_objects(project, branch_name) - transformer = new(project, branch_name) - result = yield(transformer) - transformer.after_transform! if result - - result - end - def new_file(file_path, file_content) if project.lfs_enabled? && lfs_file?(file_path) lfs_pointer_file = Gitlab::Git::LfsPointerFile.new(file_content) lfs_object = create_lfs_object!(lfs_pointer_file, file_content) - on_success_actions << -> { link_lfs_object!(lfs_object) } + link_lfs_object!(lfs_object) lfs_pointer_file.pointer else @@ -42,20 +33,12 @@ module Lfs end end - def after_transform! - on_success_actions.map(&:call) - end - private def lfs_file?(file_path) repository.attributes_at(branch_name, file_path)['filter'] == 'lfs' end - def on_success_actions - @on_success_actions ||= [] - end - def create_lfs_object!(lfs_pointer_file, file_content) LfsObject.find_or_create_by(oid: lfs_pointer_file.sha256, size: lfs_pointer_file.size) do |lfs_object| lfs_object.file = CarrierWaveStringFile.new(file_content) |