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
Jérome Perrin
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
Hide 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
...
@@ -972,14 +972,14 @@ class Repository
run_git
(
args
).
first
.
lines
.
map
(
&
:strip
)
run_git
(
args
).
first
.
lines
.
map
(
&
:strip
)
end
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
unless
remote_name
remote_name
=
"tmp-
#{
SecureRandom
.
hex
}
"
remote_name
=
"tmp-
#{
SecureRandom
.
hex
}
"
tmp_remote_name
=
true
tmp_remote_name
=
true
end
end
add_remote
(
remote_name
,
url
)
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
)
fetch_remote
(
remote_name
,
forced:
forced
)
ensure
ensure
remove_remote
(
remote_name
)
if
tmp_remote_name
remove_remote
(
remote_name
)
if
tmp_remote_name
...
...
app/services/projects/import_service.rb
View file @
7a1e93d3
...
@@ -51,11 +51,11 @@ module Projects
...
@@ -51,11 +51,11 @@ module Projects
def
import_repository
def
import_repository
begin
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
.
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
else
gitlab_shell
.
import_repository
(
project
.
repository_storage_path
,
project
.
disk_path
,
project
.
import_url
)
gitlab_shell
.
import_repository
(
project
.
repository_storage_path
,
project
.
disk_path
,
project
.
import_url
)
end
end
...
...
lib/gitlab/git/repository_mirroring.rb
View file @
7a1e93d3
module
Gitlab
module
Gitlab
module
Git
module
Git
module
RepositoryMirroring
module
RepositoryMirroring
FETCH_REF
S
=
{
REFMAP
S
=
{
#
`:all` is used to define repository as equivalent as "git clone --mirror"
#
With `:all_refs`, the repository is equivalent to the result of `git clone --mirror`
all:
'+refs/*:refs/*'
,
all
_refs
:
'+refs/*:refs/*'
,
heads:
'+refs/heads/*:refs/heads/*'
,
heads:
'+refs/heads/*:refs/heads/*'
,
tags:
'+refs/tags/*:refs/tags/*'
tags:
'+refs/tags/*:refs/tags/*'
}.
freeze
}.
freeze
RemoteError
=
Class
.
new
(
StandardError
)
RemoteError
=
Class
.
new
(
StandardError
)
def
set_remote_as_mirror
(
remote_name
,
fetch_refs: :all
)
def
set_remote_as_mirror
(
remote_name
,
refmap: :all_refs
)
Array
(
fetch_refs
).
each_with_index
do
|
fetch_ref
,
i
|
set_remote_refmap
(
remote_name
,
refmap
)
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
rugged
.
config
[
"remote.
#{
remote_name
}
.mirror"
]
=
true
rugged
.
config
[
"remote.
#{
remote_name
}
.mirror"
]
=
true
rugged
.
config
[
"remote.
#{
remote_name
}
.prune"
]
=
true
rugged
.
config
[
"remote.
#{
remote_name
}
.prune"
]
=
true
end
end
def
add_remote_fetch_config
(
remote_name
,
refspec
)
def
set_remote_refmap
(
remote_name
,
refmap
)
run_git
(
%W[config --add remote.
#{
remote_name
}
.fetch
#{
refspec
}
]
)
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
# 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`.
# of `Repository`'s interface through `method_missing`.
# `Repository` has its own `fetch_as_mirror` which uses `gitlab-shell` and
# `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.
# takes some extra attributes, so we qualify this method name to prevent confusion.
...
...
lib/gitlab/github_import.rb
View file @
7a1e93d3
module
Gitlab
module
Gitlab
module
GithubImport
module
GithubImport
def
self
.
fetch_refs
def
self
.
refmap
[
:heads
,
:tags
,
'+refs/pull/*/head:refs/merge-requests/*/head'
]
[
:heads
,
:tags
,
'+refs/pull/*/head:refs/merge-requests/*/head'
]
end
end
...
...
lib/gitlab/github_import/importer/repository_importer.rb
View file @
7a1e93d3
...
@@ -45,8 +45,8 @@ module Gitlab
...
@@ -45,8 +45,8 @@ module Gitlab
def
import_repository
def
import_repository
project
.
ensure_repository
project
.
ensure_repository
fetch_refs
=
Gitlab
::
GithubImport
.
fetch_refs
refmap
=
Gitlab
::
GithubImport
.
refmap
project
.
repository
.
fetch_as_mirror
(
project
.
import_url
,
fetch_refs:
fetch_refs
,
forced:
true
,
remote_name:
'github'
)
project
.
repository
.
fetch_as_mirror
(
project
.
import_url
,
refmap:
refmap
,
forced:
true
,
remote_name:
'github'
)
true
true
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
,
Gitlab
::
Shell
::
Error
=>
e
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
...
@@ -3,8 +3,8 @@ module Gitlab
class
Importer
class
Importer
include
Gitlab
::
ShellAdapter
include
Gitlab
::
ShellAdapter
def
self
.
fetch_refs
def
self
.
refmap
Gitlab
::
GithubImport
.
fetch_refs
Gitlab
::
GithubImport
.
refmap
end
end
attr_reader
:errors
,
:project
,
:repo
,
:repo_url
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
...
@@ -166,7 +166,7 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do
expect
(
repository
)
expect
(
repository
)
.
to
receive
(
:fetch_as_mirror
)
.
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
)
expect
(
importer
.
import_repository
).
to
eq
(
true
)
end
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