Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-06 15:10:44 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-06 15:10:44 +0300
commitba174c982f40d71a87fd511b091753807174f7e7 (patch)
treeb89d55c715288f2c2f76724c1b7ff4a6ebf90154 /lib/gitlab/import_export
parenteaea945e0355826c58c3dcf887496ea91064f85c (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/import_export')
-rw-r--r--lib/gitlab/import_export/json/ndjson_writer.rb59
-rw-r--r--lib/gitlab/import_export/project/tree_saver.rb18
2 files changed, 71 insertions, 6 deletions
diff --git a/lib/gitlab/import_export/json/ndjson_writer.rb b/lib/gitlab/import_export/json/ndjson_writer.rb
new file mode 100644
index 00000000000..e74fdd74049
--- /dev/null
+++ b/lib/gitlab/import_export/json/ndjson_writer.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module ImportExport
+ module JSON
+ class NdjsonWriter
+ include Gitlab::ImportExport::CommandLineUtil
+
+ def initialize(dir_path)
+ @dir_path = dir_path
+ end
+
+ def close
+ end
+
+ def write_attributes(exportable_path, hash)
+ # It will create:
+ # tree/project.json
+ with_file("#{exportable_path}.json") do |file|
+ file.write(hash.to_json)
+ end
+ end
+
+ def write_relation(exportable_path, relation, value)
+ # It will create:
+ # tree/project/ci_cd_setting.ndjson
+ with_file(exportable_path, "#{relation}.ndjson") do |file|
+ file.write(value.to_json)
+ end
+ end
+
+ def write_relation_array(exportable_path, relation, items)
+ # It will create:
+ # tree/project/merge_requests.ndjson
+ with_file(exportable_path, "#{relation}.ndjson") do |file|
+ items.each do |item|
+ file.write(item.to_json)
+ file.write("\n")
+ end
+ end
+ end
+
+ private
+
+ def with_file(*path)
+ file_path = File.join(@dir_path, *path)
+ raise ArgumentError, "The #{file_path} already exist" if File.exist?(file_path)
+
+ # ensure that path is created
+ mkdir_p(File.dirname(file_path))
+
+ File.open(file_path, "wb") do |file|
+ yield(file)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/import_export/project/tree_saver.rb b/lib/gitlab/import_export/project/tree_saver.rb
index 988776fe600..0017aa523c1 100644
--- a/lib/gitlab/import_export/project/tree_saver.rb
+++ b/lib/gitlab/import_export/project/tree_saver.rb
@@ -11,15 +11,9 @@ module Gitlab
@project = project
@current_user = current_user
@shared = shared
- @full_path = File.join(@shared.export_path, ImportExport.project_filename)
end
def save
- json_writer = ImportExport::JSON::LegacyWriter.new(
- @full_path,
- allowed_path: "project"
- )
-
ImportExport::JSON::StreamingSerializer.new(
exportable,
reader.project_tree,
@@ -57,6 +51,18 @@ module Gitlab
def presenter_class
Projects::ImportExport::ProjectExportPresenter
end
+
+ def json_writer
+ @json_writer ||= begin
+ if ::Feature.enabled?(:project_export_as_ndjson, @project.namespace)
+ full_path = File.join(@shared.export_path, 'tree')
+ Gitlab::ImportExport::JSON::NdjsonWriter.new(full_path)
+ else
+ full_path = File.join(@shared.export_path, ImportExport.project_filename)
+ Gitlab::ImportExport::JSON::LegacyWriter.new(full_path, allowed_path: 'project')
+ end
+ end
+ end
end
end
end