Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
fa1ea656
Commit
fa1ea656
authored
Jul 19, 2018
by
Alejandro Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate add_remote, remove_remote, fetch_internal_remote to gitaly
parent
b60364c0
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
7 additions
and
107 deletions
+7
-107
app/services/projects/import_service.rb
app/services/projects/import_service.rb
+1
-1
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+6
-57
lib/gitlab/git/repository_mirroring.rb
lib/gitlab/git/repository_mirroring.rb
+0
-30
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+0
-19
No files found.
app/services/projects/import_service.rb
View file @
fa1ea656
...
...
@@ -67,7 +67,7 @@ module Projects
else
gitlab_shell
.
import_repository
(
project
.
repository_storage
,
project
.
disk_path
,
project
.
import_url
)
end
rescue
Gitlab
::
Shell
::
Error
,
Gitlab
::
Git
::
RepositoryMirroring
::
RemoteError
=>
e
rescue
Gitlab
::
Shell
::
Error
=>
e
# Expire cache to prevent scenarios such as:
# 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
...
...
lib/gitlab/git/repository.rb
View file @
fa1ea656
...
...
@@ -673,34 +673,16 @@ module Gitlab
# If `mirror_refmap` is present the remote is set as mirror with that mapping
def
add_remote
(
remote_name
,
url
,
mirror_refmap:
nil
)
gitaly_migrate
(
:remote_add_remote
)
do
|
is_enabled
|
if
is_enabled
wrapped_gitaly_errors
do
gitaly_remote_client
.
add_remote
(
remote_name
,
url
,
mirror_refmap
)
else
rugged_add_remote
(
remote_name
,
url
,
mirror_refmap
)
end
end
end
def
remove_remote
(
remote_name
)
gitaly_migrate
(
:remote_remove_remote
)
do
|
is_enabled
|
if
is_enabled
wrapped_gitaly_errors
do
gitaly_remote_client
.
remove_remote
(
remote_name
)
else
rugged_remove_remote
(
remote_name
)
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
=
{
"true"
=>
true
,
...
...
@@ -875,12 +857,8 @@ module Gitlab
end
def
fetch_repository_as_mirror
(
repository
)
gitaly_migrate
(
:remote_fetch_internal_remote
)
do
|
is_enabled
|
if
is_enabled
wrapped_gitaly_errors
do
gitaly_remote_client
.
fetch_internal_remote
(
repository
)
else
rugged_fetch_repository_as_mirror
(
repository
)
end
end
end
...
...
@@ -1288,35 +1266,6 @@ module Gitlab
gitaly_ref_client
.
delete_refs
(
refs:
ref_names
)
if
ref_names
.
any?
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
raise
CommandError
,
@gitlab_projects
.
output
end
...
...
lib/gitlab/git/repository_mirroring.rb
View file @
fa1ea656
module
Gitlab
module
Git
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
)
gitaly_migrate
(
:ref_find_all_remote_branches
)
do
|
is_enabled
|
if
is_enabled
...
...
@@ -45,20 +29,6 @@ module Gitlab
branches
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
spec/lib/gitlab/git/repository_spec.rb
View file @
fa1ea656
...
...
@@ -527,25 +527,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
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
let
(
:new_repository
)
do
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
'my_project.git'
,
''
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment