debian-mirror-gitlab/lib/gitlab/import_export/repo_saver.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.1 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2016-06-22 15:30:34 +05:30
module Gitlab
module ImportExport
class RepoSaver
include Gitlab::ImportExport::CommandLineUtil
2022-06-21 17:19:12 +05:30
include DurationMeasuring
2016-06-22 15:30:34 +05:30
2021-03-11 19:13:27 +05:30
attr_reader :exportable, :shared
2016-06-22 15:30:34 +05:30
2021-03-11 19:13:27 +05:30
def initialize(exportable:, shared:)
@exportable = exportable
2016-06-22 15:30:34 +05:30
@shared = shared
end
def save
2022-06-21 17:19:12 +05:30
with_duration_measuring do
# it's ok to have no repo
break true unless repository_exists?
2016-06-22 15:30:34 +05:30
2022-06-21 17:19:12 +05:30
bundle_to_disk
end
2016-06-22 15:30:34 +05:30
end
2021-03-11 19:13:27 +05:30
def repository
@repository ||= @exportable.repository
end
2016-06-22 15:30:34 +05:30
private
2019-12-21 20:55:43 +05:30
def repository_exists?
repository.exists? && !repository.empty?
end
def bundle_full_path
2021-03-11 19:13:27 +05:30
File.join(shared.export_path, bundle_filename)
end
def bundle_filename
::Gitlab::ImportExport.project_bundle_filename
2019-12-21 20:55:43 +05:30
end
2016-06-22 15:30:34 +05:30
def bundle_to_disk
2021-03-11 19:13:27 +05:30
mkdir_p(File.dirname(bundle_full_path))
2019-12-21 20:55:43 +05:30
repository.bundle_to_disk(bundle_full_path)
2021-06-08 01:23:25 +05:30
rescue StandardError => e
2019-12-21 20:55:43 +05:30
shared.error(e)
2016-06-22 15:30:34 +05:30
false
end
end
end
end