Commit 5722f7b7 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'ee-gitaly-mirroring-prep' into 'master'

[EE] gitaly mirroring prep

See merge request gitlab-org/gitlab-ee!3703
parents 229014dc 3c715011
...@@ -1020,8 +1020,7 @@ class Repository ...@@ -1020,8 +1020,7 @@ class Repository
tmp_remote_name = true tmp_remote_name = true
end end
add_remote(remote_name, url) add_remote(remote_name, url, mirror_refmap: refmap)
set_remote_as_mirror(remote_name, refmap: refmap)
fetch_remote(remote_name, forced: forced) fetch_remote(remote_name, forced: forced)
ensure ensure
remove_remote(remote_name) if tmp_remote_name remove_remote(remote_name) if tmp_remote_name
......
...@@ -21,6 +21,7 @@ module Gitlab ...@@ -21,6 +21,7 @@ module Gitlab
GITALY_INTERNAL_URL = 'ssh://gitaly/internal.git'.freeze GITALY_INTERNAL_URL = 'ssh://gitaly/internal.git'.freeze
REBASE_WORKTREE_PREFIX = 'rebase'.freeze REBASE_WORKTREE_PREFIX = 'rebase'.freeze
SQUASH_WORKTREE_PREFIX = 'squash'.freeze SQUASH_WORKTREE_PREFIX = 'squash'.freeze
GITALY_INTERNAL_URL = 'ssh://gitaly/internal.git'.freeze
NoRepository = Class.new(StandardError) NoRepository = Class.new(StandardError)
InvalidBlobName = Class.new(StandardError) InvalidBlobName = Class.new(StandardError)
...@@ -888,8 +889,11 @@ module Gitlab ...@@ -888,8 +889,11 @@ module Gitlab
end end
end end
def add_remote(remote_name, url) # If `mirror_refmap` is present the remote is set as mirror with that mapping
def add_remote(remote_name, url, mirror_refmap: nil)
rugged.remotes.create(remote_name, url) rugged.remotes.create(remote_name, url)
set_remote_as_mirror(remote_name, refmap: mirror_refmap) if mirror_refmap
rescue Rugged::ConfigError rescue Rugged::ConfigError
remote_update(remote_name, url: url) remote_update(remote_name, url: url)
end end
...@@ -1143,8 +1147,7 @@ module Gitlab ...@@ -1143,8 +1147,7 @@ module Gitlab
end end
end end
add_remote(remote_name, url) add_remote(remote_name, url, mirror_refmap: :all_refs)
set_remote_as_mirror(remote_name)
fetch_remote(remote_name, env: env) fetch_remote(remote_name, env: env)
ensure ensure
remove_remote(remote_name) remove_remote(remote_name)
......
...@@ -17,20 +17,6 @@ module Gitlab ...@@ -17,20 +17,6 @@ module Gitlab
rugged.config["remote.#{remote_name}.prune"] = true rugged.config["remote.#{remote_name}.prune"] = true
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
def remote_tags(remote) def remote_tags(remote)
# Each line has this format: "dc872e9fa6963f8f03da6c8f6f264d0845d6b092\trefs/tags/v1.10.0\n" # Each line has this format: "dc872e9fa6963f8f03da6c8f6f264d0845d6b092\trefs/tags/v1.10.0\n"
# We want to convert it to: [{ 'v1.10.0' => 'dc872e9fa6963f8f03da6c8f6f264d0845d6b092' }, ...] # We want to convert it to: [{ 'v1.10.0' => 'dc872e9fa6963f8f03da6c8f6f264d0845d6b092' }, ...]
...@@ -72,6 +58,20 @@ module Gitlab ...@@ -72,6 +58,20 @@ module Gitlab
private private
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
def list_remote_tags(remote) def list_remote_tags(remote)
tag_list, exit_code, error = nil tag_list, exit_code, error = nil
cmd = %W(#{Gitlab.config.git.bin_path} --git-dir=#{path} ls-remote --tags #{remote}) cmd = %W(#{Gitlab.config.git.bin_path} --git-dir=#{path} ls-remote --tags #{remote})
......
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