Commit a14f1720 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'gitaly-remote-mandatory' into 'master'

Migrate add_remote, remove_remote, fetch_internal_remote to gitaly

See merge request gitlab-org/gitlab-ce!20724
parents 71a67cfb fa1ea656
...@@ -67,7 +67,7 @@ module Projects ...@@ -67,7 +67,7 @@ module Projects
else else
gitlab_shell.import_repository(project.repository_storage, project.disk_path, project.import_url) gitlab_shell.import_repository(project.repository_storage, project.disk_path, project.import_url)
end end
rescue Gitlab::Shell::Error, Gitlab::Git::RepositoryMirroring::RemoteError => e rescue Gitlab::Shell::Error => e
# Expire cache to prevent scenarios such as: # Expire cache to prevent scenarios such as:
# 1. First import failed, but the repo was imported successfully, so +exists?+ returns true # 1. First import failed, but the repo was imported successfully, so +exists?+ returns true
# 2. Retried import, repo is broken or not imported but +exists?+ still returns true # 2. Retried import, repo is broken or not imported but +exists?+ still returns true
......
...@@ -673,35 +673,17 @@ module Gitlab ...@@ -673,35 +673,17 @@ module Gitlab
# If `mirror_refmap` is present the remote is set as mirror with that mapping # If `mirror_refmap` is present the remote is set as mirror with that mapping
def add_remote(remote_name, url, mirror_refmap: nil) def add_remote(remote_name, url, mirror_refmap: nil)
gitaly_migrate(:remote_add_remote) do |is_enabled| wrapped_gitaly_errors do
if is_enabled gitaly_remote_client.add_remote(remote_name, url, mirror_refmap)
gitaly_remote_client.add_remote(remote_name, url, mirror_refmap)
else
rugged_add_remote(remote_name, url, mirror_refmap)
end
end end
end end
def remove_remote(remote_name) def remove_remote(remote_name)
gitaly_migrate(:remote_remove_remote) do |is_enabled| wrapped_gitaly_errors do
if is_enabled gitaly_remote_client.remove_remote(remote_name)
gitaly_remote_client.remove_remote(remote_name)
else
rugged_remove_remote(remote_name)
end
end end
end end
# Update the specified remote using the values in the +options+ hash
#
# Example
# repo.update_remote("origin", url: "path/to/repo")
def remote_update(remote_name, url:)
# TODO: Implement other remote options
rugged.remotes.set_url(remote_name, url)
nil
end
AUTOCRLF_VALUES = { AUTOCRLF_VALUES = {
"true" => true, "true" => true,
"false" => false, "false" => false,
...@@ -875,12 +857,8 @@ module Gitlab ...@@ -875,12 +857,8 @@ module Gitlab
end end
def fetch_repository_as_mirror(repository) def fetch_repository_as_mirror(repository)
gitaly_migrate(:remote_fetch_internal_remote) do |is_enabled| wrapped_gitaly_errors do
if is_enabled gitaly_remote_client.fetch_internal_remote(repository)
gitaly_remote_client.fetch_internal_remote(repository)
else
rugged_fetch_repository_as_mirror(repository)
end
end end
end end
...@@ -1288,35 +1266,6 @@ module Gitlab ...@@ -1288,35 +1266,6 @@ module Gitlab
gitaly_ref_client.delete_refs(refs: ref_names) if ref_names.any? gitaly_ref_client.delete_refs(refs: ref_names) if ref_names.any?
end end
def rugged_remove_remote(remote_name)
# When a remote is deleted all its remote refs are deleted too, but in
# the case of mirrors we map its refs (that would usualy go under
# [remote_name]/) to the top level namespace. We clean the mapping so
# those don't get deleted.
if rugged.config["remote.#{remote_name}.mirror"]
rugged.config.delete("remote.#{remote_name}.fetch")
end
rugged.remotes.delete(remote_name)
true
rescue Rugged::ConfigError
false
end
def rugged_fetch_repository_as_mirror(repository)
remote_name = "tmp-#{SecureRandom.hex}"
repository = RemoteRepository.new(repository) unless repository.is_a?(RemoteRepository)
add_remote(remote_name, GITALY_INTERNAL_URL, mirror_refmap: :all_refs)
fetch_remote(remote_name, env: repository.fetch_env)
ensure
remove_remote(remote_name)
end
def fetch_remote(remote_name = 'origin', env: nil)
run_git(['fetch', remote_name], env: env).last.zero?
end
def gitlab_projects_error def gitlab_projects_error
raise CommandError, @gitlab_projects.output raise CommandError, @gitlab_projects.output
end end
......
module Gitlab module Gitlab
module Git module Git
module RepositoryMirroring module RepositoryMirroring
REFMAPS = {
# With `:all_refs`, the repository is equivalent to the result of `git clone --mirror`
all_refs: '+refs/*:refs/*',
heads: '+refs/heads/*:refs/heads/*',
tags: '+refs/tags/*:refs/tags/*'
}.freeze
RemoteError = Class.new(StandardError)
def set_remote_as_mirror(remote_name, refmap: :all_refs)
set_remote_refmap(remote_name, refmap)
rugged.config["remote.#{remote_name}.mirror"] = true
rugged.config["remote.#{remote_name}.prune"] = true
end
def remote_branches(remote_name) def remote_branches(remote_name)
gitaly_migrate(:ref_find_all_remote_branches) do |is_enabled| gitaly_migrate(:ref_find_all_remote_branches) do |is_enabled|
if is_enabled if is_enabled
...@@ -45,20 +29,6 @@ module Gitlab ...@@ -45,20 +29,6 @@ module Gitlab
branches branches
end end
def set_remote_refmap(remote_name, refmap)
Array(refmap).each_with_index do |refspec, i|
refspec = REFMAPS[refspec] || refspec
# We need multiple `fetch` entries, but Rugged only allows replacing a config, not adding to it.
# To make sure we start from scratch, we set the first using rugged, and use `git` for any others
if i == 0
rugged.config["remote.#{remote_name}.fetch"] = refspec
else
run_git(%W[config --add remote.#{remote_name}.fetch #{refspec}])
end
end
end
end end
end end
end end
...@@ -527,25 +527,6 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -527,25 +527,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
end end
describe "#remote_update" do
before(:all) do
@repo = Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '')
@repo.remote_update("expendable", url: TEST_NORMAL_REPO_PATH)
end
it "should add the remote" do
rugged = Gitlab::GitalyClient::StorageSettings.allow_disk_access { @repo.rugged }
expect(rugged.remotes["expendable"].url).to(
eq(TEST_NORMAL_REPO_PATH)
)
end
after(:all) do
ensure_seeds
end
end
describe '#fetch_repository_as_mirror' do describe '#fetch_repository_as_mirror' do
let(:new_repository) do let(:new_repository) do
Gitlab::Git::Repository.new('default', 'my_project.git', '') Gitlab::Git::Repository.new('default', 'my_project.git', '')
......
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