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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
7a1e93d3
Commit
7a1e93d3
authored
Nov 23, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename fetch_refs to refmap
parent
0e6beaf5
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
29 additions
and
28 deletions
+29
-28
app/models/repository.rb
app/models/repository.rb
+2
-2
app/services/projects/import_service.rb
app/services/projects/import_service.rb
+3
-3
lib/gitlab/git/repository_mirroring.rb
lib/gitlab/git/repository_mirroring.rb
+18
-17
lib/gitlab/github_import.rb
lib/gitlab/github_import.rb
+1
-1
lib/gitlab/github_import/importer/repository_importer.rb
lib/gitlab/github_import/importer/repository_importer.rb
+2
-2
lib/gitlab/legacy_github_import/importer.rb
lib/gitlab/legacy_github_import/importer.rb
+2
-2
spec/lib/gitlab/github_import/importer/repository_importer_spec.rb
...gitlab/github_import/importer/repository_importer_spec.rb
+1
-1
No files found.
app/models/repository.rb
View file @
7a1e93d3
...
...
@@ -972,14 +972,14 @@ class Repository
run_git
(
args
).
first
.
lines
.
map
(
&
:strip
)
end
def
fetch_as_mirror
(
url
,
forced:
false
,
fetch_refs: :all
,
remote_name:
nil
)
def
fetch_as_mirror
(
url
,
forced:
false
,
refmap: :all_refs
,
remote_name:
nil
)
unless
remote_name
remote_name
=
"tmp-
#{
SecureRandom
.
hex
}
"
tmp_remote_name
=
true
end
add_remote
(
remote_name
,
url
)
set_remote_as_mirror
(
remote_name
,
fetch_refs:
fetch_refs
)
set_remote_as_mirror
(
remote_name
,
refmap:
refmap
)
fetch_remote
(
remote_name
,
forced:
forced
)
ensure
remove_remote
(
remote_name
)
if
tmp_remote_name
...
...
app/services/projects/import_service.rb
View file @
7a1e93d3
...
...
@@ -51,11 +51,11 @@ module Projects
def
import_repository
begin
fetch_refs
=
importer_class
.
try
(
:fetch_refs
)
if
has_importer?
refmap
=
importer_class
.
try
(
:refmap
)
if
has_importer?
if
fetch_refs
if
refmap
project
.
ensure_repository
project
.
repository
.
fetch_as_mirror
(
project
.
import_url
,
fetch_refs:
fetch_refs
)
project
.
repository
.
fetch_as_mirror
(
project
.
import_url
,
refmap:
refmap
)
else
gitlab_shell
.
import_repository
(
project
.
repository_storage_path
,
project
.
disk_path
,
project
.
import_url
)
end
...
...
lib/gitlab/git/repository_mirroring.rb
View file @
7a1e93d3
module
Gitlab
module
Git
module
RepositoryMirroring
FETCH_REF
S
=
{
#
`:all` is used to define repository as equivalent as "git clone --mirror"
all:
'+refs/*:refs/*'
,
REFMAP
S
=
{
#
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
,
fetch_refs: :all
)
Array
(
fetch_refs
).
each_with_index
do
|
fetch_ref
,
i
|
fetch_ref
=
FETCH_REFS
[
fetch_ref
]
||
fetch_ref
# Add first fetch with Rugged so it does not create its own.
if
i
==
0
rugged
.
config
[
"remote.
#{
remote_name
}
.fetch"
]
=
fetch_ref
else
add_remote_fetch_config
(
remote_name
,
fetch_ref
)
end
end
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
add_remote_fetch_config
(
remote_name
,
refspec
)
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
# Like all public `Gitlab::Git::Repository` methods, this method is part
# Like all
_refs
public `Gitlab::Git::Repository` methods, this method is part
# of `Repository`'s interface through `method_missing`.
# `Repository` has its own `fetch_as_mirror` which uses `gitlab-shell` and
# takes some extra attributes, so we qualify this method name to prevent confusion.
...
...
lib/gitlab/github_import.rb
View file @
7a1e93d3
module
Gitlab
module
GithubImport
def
self
.
fetch_refs
def
self
.
refmap
[
:heads
,
:tags
,
'+refs/pull/*/head:refs/merge-requests/*/head'
]
end
...
...
lib/gitlab/github_import/importer/repository_importer.rb
View file @
7a1e93d3
...
...
@@ -45,8 +45,8 @@ module Gitlab
def
import_repository
project
.
ensure_repository
fetch_refs
=
Gitlab
::
GithubImport
.
fetch_refs
project
.
repository
.
fetch_as_mirror
(
project
.
import_url
,
fetch_refs:
fetch_refs
,
forced:
true
,
remote_name:
'github'
)
refmap
=
Gitlab
::
GithubImport
.
refmap
project
.
repository
.
fetch_as_mirror
(
project
.
import_url
,
refmap:
refmap
,
forced:
true
,
remote_name:
'github'
)
true
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
,
Gitlab
::
Shell
::
Error
=>
e
...
...
lib/gitlab/legacy_github_import/importer.rb
View file @
7a1e93d3
...
...
@@ -3,8 +3,8 @@ module Gitlab
class
Importer
include
Gitlab
::
ShellAdapter
def
self
.
fetch_refs
Gitlab
::
GithubImport
.
fetch_refs
def
self
.
refmap
Gitlab
::
GithubImport
.
refmap
end
attr_reader
:errors
,
:project
,
:repo
,
:repo_url
...
...
spec/lib/gitlab/github_import/importer/repository_importer_spec.rb
View file @
7a1e93d3
...
...
@@ -166,7 +166,7 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do
expect
(
repository
)
.
to
receive
(
:fetch_as_mirror
)
.
with
(
project
.
import_url
,
fetch_refs:
Gitlab
::
GithubImport
.
fetch_refs
,
forced:
true
,
remote_name:
'github'
)
.
with
(
project
.
import_url
,
refmap:
Gitlab
::
GithubImport
.
refmap
,
forced:
true
,
remote_name:
'github'
)
expect
(
importer
.
import_repository
).
to
eq
(
true
)
end
...
...
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