Refactoring Project#write_repository_config

parent 9d575acc
......@@ -272,7 +272,7 @@ class Namespace < ActiveRecord::Base
def write_projects_full_path_config
all_projects.each do |project|
project.expires_full_path_cache # we need to clear cache to validate renames correctly
project.write_repository_config(:fullpath, project.full_path)
project.write_repository_config
end
end
end
......@@ -1420,10 +1420,7 @@ class Project < ActiveRecord::Base
end
def after_rename_repo
# We'd need to keep track of project full path otherwise directory tree
# created with hashed storage enabled cannot be usefully imported using
# the import rake task.
write_repository_config(:fullpath, full_path)
write_repository_config
path_before_change = previous_changes['path'].first
......@@ -1437,11 +1434,13 @@ class Project < ActiveRecord::Base
Gitlab::PagesTransfer.new.rename_project(path_before_change, self.path, namespace.full_path)
end
def write_repository_config(key, value, prefix: :gitlab)
key = [prefix, key].compact.join('.')
repo.config[key] = value
def write_repository_config(gl_full_path: full_path)
# We'd need to keep track of project full path otherwise directory tree
# created with hashed storage enabled cannot be usefully imported using
# the import rake task.
repo.config['gitlab.fullpath'] = gl_full_path
rescue Gitlab::Git::Repository::NoRepository => e
Rails.logger.error("Error writing key #{key} to .git/config for project #{full_path} (#{id}): #{e.message}.")
Rails.logger.error("Error writing to .git/config for project #{full_path} (#{id}): #{e.message}.")
nil
end
......
......@@ -88,11 +88,7 @@ module Projects
log_info("#{@project.owner.name} created a new project \"#{@project.name_with_namespace}\"")
unless @project.gitlab_project_import?
# We'd need to keep track of project full path otherwise directory tree
# created with hashed storage enabled cannot be usefully imported using
# the import rake task.
@project.write_repository_config(:fullpath, @project.full_path)
@project.write_repository_config
@project.create_wiki unless skip_wiki?
create_services_from_active_templates(@project)
......
......@@ -30,6 +30,8 @@ module Projects
unless result
rollback_folder_move
project.storage_version = nil
else
project.write_repository_config
end
project.repository_read_only = false
......@@ -39,13 +41,6 @@ module Projects
yield
end
# We'd need to keep track of project full path otherwise directory tree
# created with hashed storage enabled cannot be usefully imported using
# the import rake task.
if result
project.write_repository_config(:fullpath, project.full_path)
end
result
end
......
......@@ -101,10 +101,7 @@ module Projects
end
def write_repository_config(full_path)
# We'd need to keep track of project full path otherwise directory tree
# created with hashed storage enabled cannot be usefully imported using
# the import rake task.
project.write_repository_config(:fullpath, full_path)
project.write_repository_config(:gl_fullpath, full_path)
end
def refresh_permissions
......
......@@ -20,7 +20,7 @@ module Gitlab
next
end
log "Processing #{repo_path} -> #{bare_repo.project_full_path}".color(:yellow)
log "Processing #{repo_path}".color(:yellow)
new(user, bare_repo).create_project_if_needed
end
......@@ -62,10 +62,7 @@ module Gitlab
if project.persisted? && mv_repo(project)
log " * Created #{project.name} (#{project_full_path})".color(:green)
# We'd need to keep track of project full path otherwise directory tree
# created with hashed storage enabled cannot be usefully imported using
# the import rake task.
project.write_repository_config(:fullpath, project.full_path)
project.write_repository_config
ProjectCacheWorker.perform_async(project.id)
else
......
......@@ -2630,9 +2630,9 @@ describe Project do
it 'updates project full path in .git/config' do
allow(project_storage).to receive(:rename_repo).and_return(true)
expect(project).to receive(:write_repository_config).with(:fullpath, project.full_path)
project.rename_repo
expect(project.repo.config['gitlab.fullpath']).to eq(project.full_path)
end
end
......@@ -2678,12 +2678,10 @@ describe Project do
context 'hashed storage' do
let(:project) { create(:project, :repository, skip_disk_validation: true) }
let(:gitlab_shell) { Gitlab::Shell.new }
let(:hash) { '6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b' }
let(:hash) { Digest::SHA2.hexdigest(project.id.to_s) }
before do
stub_application_setting(hashed_storage_enabled: true)
allow(Digest::SHA2).to receive(:hexdigest) { hash }
allow(project).to receive(:gitlab_shell).and_return(gitlab_shell)
end
describe '#legacy_storage?' do
......@@ -2706,13 +2704,13 @@ describe Project do
describe '#base_dir' do
it 'returns base_dir based on hash of project id' do
expect(project.base_dir).to eq('@hashed/6b/86')
expect(project.base_dir).to eq("@hashed/#{hash[0..1]}/#{hash[2..3]}")
end
end
describe '#disk_path' do
it 'returns disk_path based on hash of project id' do
hashed_path = '@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b'
hashed_path = "@hashed/#{hash[0..1]}/#{hash[2..3]}/#{hash}"
expect(project.disk_path).to eq(hashed_path)
end
......@@ -2720,7 +2718,9 @@ describe Project do
describe '#ensure_storage_path_exists' do
it 'delegates to gitlab_shell to ensure namespace is created' do
expect(gitlab_shell).to receive(:add_namespace).with(project.repository_storage_path, '@hashed/6b/86')
allow(project).to receive(:gitlab_shell).and_return(gitlab_shell)
expect(gitlab_shell).to receive(:add_namespace).with(project.repository_storage_path, "@hashed/#{hash[0..1]}/#{hash[2..3]}")
project.ensure_storage_path_exists
end
......@@ -2780,7 +2780,7 @@ describe Project do
end
context 'when not rolled out' do
let(:project) { create(:project, :repository, storage_version: 1) }
let(:project) { create(:project, :repository, storage_version: 1, skip_disk_validation: true) }
it 'moves pages folder to new location' do
expect_any_instance_of(Gitlab::UploadsTransfer).to receive(:rename_project)
......@@ -2791,9 +2791,9 @@ describe Project do
end
it 'updates project full path in .git/config' do
expect(project).to receive(:write_repository_config).with(:fullpath, project.full_path)
project.rename_repo
expect(project.repo.config['gitlab.fullpath']).to eq(project.full_path)
end
end
......
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