From 92f4bde427652a33ccb42e93de1cc781289a6c8a Mon Sep 17 00:00:00 2001 From: James Lopez Date: Thu, 5 May 2016 12:39:18 +0200 Subject: [PATCH] use git bundle in import and add wiki repo to import --- lib/gitlab/import_export/command_line_util.rb | 6 ++++++ lib/gitlab/import_export/import_service.rb | 16 ++++++++++++++-- lib/gitlab/import_export/repo_restorer.rb | 11 +++++------ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/gitlab/import_export/command_line_util.rb b/lib/gitlab/import_export/command_line_util.rb index 5ff72f5ff8d..f32e2715997 100644 --- a/lib/gitlab/import_export/command_line_util.rb +++ b/lib/gitlab/import_export/command_line_util.rb @@ -23,6 +23,12 @@ module Gitlab status.zero? end + def git_unbundle(git_bin_path: Gitlab.config.git.bin_path, repo_path:, bundle_path:) + cmd = %W(#{git_bin_path} clone --bare #{bundle_path} #{repo_path}) + _output, status = Gitlab::Popen.popen(cmd) + status.zero? + end + def tar_with_options(archive:, dir:, options:) cmd = %W(tar -#{options} #{archive} -C #{dir} .) _output, status = Gitlab::Popen.popen(cmd) diff --git a/lib/gitlab/import_export/import_service.rb b/lib/gitlab/import_export/import_service.rb index 97ee8a7fc90..6878f4bbc8c 100644 --- a/lib/gitlab/import_export/import_service.rb +++ b/lib/gitlab/import_export/import_service.rb @@ -15,7 +15,7 @@ module Gitlab def execute Gitlab::ImportExport::Importer.import(archive_file: @archive_file, storage_path: storage_path) - project_tree.project if [restore_project_tree, restore_repo].all? + project_tree.project if [restore_project_tree, restore_repo, restore_wiki_repo].all? end private @@ -29,7 +29,11 @@ module Gitlab end def restore_repo - Gitlab::ImportExport::RepoRestorer.new(path: storage_path, project: project_tree.project).restore + Gitlab::ImportExport::RepoRestorer.new(path: repo_path, project: project_tree.project).restore + end + + def restore_wiki_repo + Gitlab::ImportExport::RepoRestorer.new(path: wiki_repo_path, project: project_tree.project).restore end def storage_path @@ -39,6 +43,14 @@ module Gitlab def path_with_namespace File.join(@namespace.path, @project_path) end + + def repo_path + File.join('storage_path', 'project.bundle') + end + + def wiki_repo_path + File.join('storage_path', 'project.wiki.bundle') + end end end end diff --git a/lib/gitlab/import_export/repo_restorer.rb b/lib/gitlab/import_export/repo_restorer.rb index b34581deeb5..dc45238bf2a 100644 --- a/lib/gitlab/import_export/repo_restorer.rb +++ b/lib/gitlab/import_export/repo_restorer.rb @@ -3,19 +3,18 @@ module Gitlab class RepoRestorer include Gitlab::ImportExport::CommandLineUtil - def initialize(project:, path:) + def initialize(project:, path_to_bundle: ) @project = project - # TODO remove magic keyword and move it to a shared config - @path = File.join(path, 'project.bundle') + @path_to_bundle = path_to_bundle end def restore - return false unless File.exists?(@path) - # Move repos dir to 'repositories.old' dir + return true unless File.exists?(@path) FileUtils.mkdir_p(repos_path) FileUtils.mkdir_p(path_to_repo) - untar_xf(archive: @path, dir: path_to_repo) + + git_unbundle(git_bin_path: Gitlab.config.git.bin_path, repo_path: path_to_repo, bundle_path: @path_to_bundle) end private