Commit adc44d24 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Project model and repo backups: apply Rubocop rules

--HG--
branch : heptapod
parent 30aed99d5f07
......@@ -39,7 +39,7 @@ class Project < ApplicationRecord
BoardLimitExceeded = Class.new(StandardError)
MERCURIAL_VCS_TYPES = ["hg", "hg_git"].freeze
MERCURIAL_VCS_TYPES = %w[hg hg_git].freeze
STATISTICS_ATTRIBUTE = 'repositories_count'
UNKNOWN_IMPORT_URL = 'http://unknown.git'
# Hashed Storage versions handle rolling out new storage to project and dependents models:
......@@ -888,7 +888,7 @@ def unlink_forks_upon_visibility_decrease_enabled?
end
def mercurial?
return MERCURIAL_VCS_TYPES.include?(vcs_type)
MERCURIAL_VCS_TYPES.include?(vcs_type)
end
def empty_repo?
......
......@@ -19,9 +19,7 @@ def initialize(progress)
def hg_cmd_details
[Gitlab.config.mercurial.bin_path,
backup_repos_path, # guaranteed to exist and not an hg repo
{ "HGRCPATH" => Gitlab::Mercurial.hgrc_path,
},
]
{ "HGRCPATH" => Gitlab::Mercurial.hgrc_path }]
end
def dump(max_concurrency:, max_storage_concurrency:)
......@@ -60,14 +58,17 @@ def backup_project(project)
# TODO make a project method out of this
has_git = ["git", "hg_git"].include?(project.vcs_type)
if has_git
Gitlab::GitalyClient::RepositoryService.new(project.repository)
.create_bundle(path_to_project_bundle)
backup_custom_hooks(project)
end
if project.mercurial?
backup_hg_repo(project)
end
rescue => e
progress_warn(project, e, 'Failed to backup repo')
end
......@@ -88,17 +89,16 @@ def backup_hg_repo(project)
'--ignore-failed-read',
'.hg/hgrc',
'.hg/hgrc.managed',
'.hg/git-mapfile',
]
'.hg/git-mapfile']
output, status = Gitlab::Popen.popen(cmd)
progress_warn(project, cmd.join(' '), output) unless status.zero?
progress_warn(project, cmd.join(' '), output) unless status == 0
# Backup the hg repository itself
cmd = [hg_exe, "-R", path_to_hg_repo,
"bundle", "--all", path_to_hg_project_bundle]
output, status = Gitlab::Popen.popen(cmd, hg_cwd, hg_env)
unless status.zero?
unless status == 0
progress_warn(project, cmd.join(' '), output)
raise StandardError, output.strip
end
......@@ -154,9 +154,11 @@ def restore
wiki.repository.create_from_bundle(path_to_wiki_bundle)
restore_custom_hooks(wiki)
end
if project.mercurial?
try_restore_hg_repo(wiki, !has_git)
end
progress.puts "[DONE]".color(:green)
rescue => e
progress.puts "[Failed] restoring #{wiki.full_path} wiki".color(:red)
......@@ -177,7 +179,8 @@ def restore
# a Git restoration happens first or not.
def try_restore_hg_repo(project, create_if_missing = true)
path_to_hg_project_bundle = path_to_hg_bundle(project)
if !File.exist?(path_to_hg_project_bundle)
unless File.exist?(path_to_hg_project_bundle)
project.repository.create_repository if create_if_missing
return
end
......@@ -188,21 +191,20 @@ def try_restore_hg_repo(project, create_if_missing = true)
# Create the Mercurial repository
cmd = [hg_exe, "init", path_to_hg_repo]
output, status = Gitlab::Popen.popen(cmd, hg_cwd, hg_env)
raise StandardError, output.strip unless status.zero?
raise StandardError, output.strip unless status == 0
# Untar the configuration and necessary caches
cmd = %W(tar -xf #{path_to_hg_tars(project, "config-and-cache")} -C #{path_to_hg_repo})
output, status = Gitlab::Popen.popen(cmd)
raise StandardError, output.strip unless status.zero?
raise StandardError, output.strip unless status == 0
# Unbundle the backup
cmd = [hg_exe, "-R", path_to_hg_repo,
"unbundle", path_to_hg_project_bundle]
output, status = Gitlab::Popen.popen(cmd, hg_cwd, hg_env)
raise StandardError, output.strip unless status.zero?
raise StandardError, output.strip unless status == 0
end
protected
def path_to_hg_repo(project)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment