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
aadd0902
Commit
aadd0902
authored
Jan 17, 2018
by
Alejandro Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Incorporate Gitaly's RemoteService.UpdateRemoteMirror RPC
parent
3853a609
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
10 deletions
+68
-10
GITALY_SERVER_VERSION
GITALY_SERVER_VERSION
+1
-1
lib/gitlab/git/remote_mirror.rb
lib/gitlab/git/remote_mirror.rb
+19
-5
lib/gitlab/gitaly_client/remote_service.rb
lib/gitlab/gitaly_client/remote_service.rb
+27
-0
spec/lib/gitlab/gitaly_client/remote_service_spec.rb
spec/lib/gitlab/gitaly_client/remote_service_spec.rb
+14
-0
spec/services/projects/update_remote_mirror_service_spec.rb
spec/services/projects/update_remote_mirror_service_spec.rb
+7
-4
No files found.
GITALY_SERVER_VERSION
View file @
aadd0902
0.7
0
.0
0.7
2
.0
lib/gitlab/git/remote_mirror.rb
View file @
aadd0902
...
...
@@ -6,7 +6,23 @@ module Gitlab
@ref_name
=
ref_name
end
def
update
(
only_branches_matching:
[],
only_tags_matching:
[])
def
update
(
only_branches_matching:
[])
@repository
.
gitaly_migrate
(
:remote_update_remote_mirror
)
do
|
is_enabled
|
if
is_enabled
gitaly_update
(
only_branches_matching
)
else
rugged_update
(
only_branches_matching
)
end
end
end
private
def
gitaly_update
(
only_branches_matching
)
@repository
.
gitaly_remote_client
.
update_remote_mirror
(
@ref_name
,
only_branches_matching
)
end
def
rugged_update
(
only_branches_matching
)
local_branches
=
refs_obj
(
@repository
.
local_branches
,
only_refs_matching:
only_branches_matching
)
remote_branches
=
refs_obj
(
@repository
.
remote_branches
(
@ref_name
),
only_refs_matching:
only_branches_matching
)
...
...
@@ -15,8 +31,8 @@ module Gitlab
delete_refs
(
local_branches
,
remote_branches
)
local_tags
=
refs_obj
(
@repository
.
tags
,
only_refs_matching:
only_tags_matching
)
remote_tags
=
refs_obj
(
@repository
.
remote_tags
(
@ref_name
)
,
only_refs_matching:
only_tags_matching
)
local_tags
=
refs_obj
(
@repository
.
tags
)
remote_tags
=
refs_obj
(
@repository
.
remote_tags
(
@ref_name
))
updated_tags
=
changed_refs
(
local_tags
,
remote_tags
)
@repository
.
push_remote_branches
(
@ref_name
,
updated_tags
.
keys
)
if
updated_tags
.
present?
...
...
@@ -24,8 +40,6 @@ module Gitlab
delete_refs
(
local_tags
,
remote_tags
)
end
private
def
refs_obj
(
refs
,
only_refs_matching:
[])
refs
.
each_with_object
({})
do
|
ref
,
refs
|
next
if
only_refs_matching
.
present?
&&
!
only_refs_matching
.
include?
(
ref
.
name
)
...
...
lib/gitlab/gitaly_client/remote_service.rb
View file @
aadd0902
module
Gitlab
module
GitalyClient
class
RemoteService
MAX_MSG_SIZE
=
128
.
kilobytes
.
freeze
def
initialize
(
repository
)
@repository
=
repository
@gitaly_repo
=
repository
.
gitaly_repository
...
...
@@ -38,6 +40,31 @@ module Gitlab
response
.
result
end
def
update_remote_mirror
(
ref_name
,
only_branches_matching
)
req_enum
=
Enumerator
.
new
do
|
y
|
y
.
yield
Gitaly
::
UpdateRemoteMirrorRequest
.
new
(
repository:
@gitaly_repo
,
ref_name:
ref_name
)
current_size
=
0
slices
=
only_branches_matching
.
slice_before
do
|
branch_name
|
current_size
+=
branch_name
.
bytesize
next
false
if
current_size
<
MAX_MSG_SIZE
current_size
=
0
end
slices
.
each
do
|
slice
|
y
.
yield
Gitaly
::
UpdateRemoteMirrorRequest
.
new
(
only_branches_matching:
slice
)
end
end
GitalyClient
.
call
(
@storage
,
:remote_service
,
:update_remote_mirror
,
req_enum
)
end
end
end
end
spec/lib/gitlab/gitaly_client/remote_service_spec.rb
View file @
aadd0902
...
...
@@ -44,4 +44,18 @@ describe Gitlab::GitalyClient::RemoteService do
expect
(
client
.
fetch_internal_remote
(
remote_repository
)).
to
be
(
true
)
end
end
describe
'#update_remote_mirror'
do
let
(
:ref_name
)
{
'remote_mirror_1'
}
let
(
:only_branches_matching
)
{
[
'my-branch'
,
'master'
]
}
it
'sends an update_remote_mirror message'
do
expect_any_instance_of
(
Gitaly
::
RemoteService
::
Stub
)
.
to
receive
(
:update_remote_mirror
)
.
with
(
kind_of
(
Enumerator
),
kind_of
(
Hash
))
.
and_return
(
double
(
:update_remote_mirror_response
))
client
.
update_remote_mirror
(
ref_name
,
only_branches_matching
)
end
end
end
spec/services/projects/update_remote_mirror_service_spec.rb
View file @
aadd0902
...
...
@@ -9,7 +9,7 @@ describe Projects::UpdateRemoteMirrorService do
subject
{
described_class
.
new
(
project
,
project
.
creator
)
}
describe
"#execute"
do
describe
"#execute"
,
:skip_gitaly_mock
do
before
do
create_branch
(
repository
,
'existing-branch'
)
allow
(
raw_repository
).
to
receive
(
:remote_tags
)
do
...
...
@@ -82,7 +82,10 @@ describe Projects::UpdateRemoteMirrorService do
end
context
'when push only protected branches option is set'
do
let
(
:protected_branch_name
)
{
project
.
repository
.
branch_names
.
first
}
let
(
:unprotected_branch_name
)
{
'existing-branch'
}
let
(
:protected_branch_name
)
do
project
.
repository
.
branch_names
.
find
{
|
n
|
n
!=
unprotected_branch_name
}
end
let!
(
:protected_branch
)
do
create
(
:protected_branch
,
project:
project
,
name:
protected_branch_name
)
end
...
...
@@ -106,10 +109,10 @@ describe Projects::UpdateRemoteMirrorService do
it
'does not sync unprotected branches'
do
allow
(
repository
).
to
receive
(
:fetch_remote
)
do
sync_remote
(
repository
,
remote_mirror
.
remote_name
,
local_branch_names
)
update_branch
(
repository
,
'existing-branch'
)
update_branch
(
repository
,
unprotected_branch_name
)
end
expect
(
raw_repository
).
not_to
receive
(
:push_remote_branches
).
with
(
remote_mirror
.
remote_name
,
[
'existing-branch'
])
expect
(
raw_repository
).
not_to
receive
(
:push_remote_branches
).
with
(
remote_mirror
.
remote_name
,
[
unprotected_branch_name
])
subject
.
execute
(
remote_mirror
)
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