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
618dd9e4
Commit
618dd9e4
authored
Oct 02, 2017
by
Ahmad Sherif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate Workhorse Send{Diff,Patch} to Gitaly
parent
1c0407e8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
22 deletions
+92
-22
GITALY_SERVER_VERSION
GITALY_SERVER_VERSION
+1
-1
lib/gitlab/workhorse.rb
lib/gitlab/workhorse.rb
+36
-10
spec/lib/gitlab/workhorse_spec.rb
spec/lib/gitlab/workhorse_spec.rb
+55
-11
No files found.
GITALY_SERVER_VERSION
View file @
618dd9e4
0.4
3
.0
0.4
4
.0
lib/gitlab/workhorse.rb
View file @
618dd9e4
...
...
@@ -103,11 +103,16 @@ module Gitlab
end
def
send_git_diff
(
repository
,
diff_refs
)
params
=
{
'RepoPath'
=>
repository
.
path_to_repo
,
'ShaFrom'
=>
diff_refs
.
base_sha
,
'ShaTo'
=>
diff_refs
.
head_sha
}
params
=
if
Gitlab
::
GitalyClient
.
feature_enabled?
(
:workhorse_send_git_diff
)
{
'GitalyServer'
=>
gitaly_server_hash
(
repository
),
'RawDiffRequest'
=>
Gitaly
::
RawDiffRequest
.
new
(
gitaly_diff_or_patch_hash
(
repository
,
diff_refs
)
).
to_json
}
else
workhorse_diff_or_patch_hash
(
repository
,
diff_refs
)
end
[
SEND_DATA_HEADER
,
...
...
@@ -116,11 +121,16 @@ module Gitlab
end
def
send_git_patch
(
repository
,
diff_refs
)
params
=
{
'RepoPath'
=>
repository
.
path_to_repo
,
'ShaFrom'
=>
diff_refs
.
base_sha
,
'ShaTo'
=>
diff_refs
.
head_sha
}
params
=
if
Gitlab
::
GitalyClient
.
feature_enabled?
(
:workhorse_send_git_patch
)
{
'GitalyServer'
=>
gitaly_server_hash
(
repository
),
'RawPatchRequest'
=>
Gitaly
::
RawPatchRequest
.
new
(
gitaly_diff_or_patch_hash
(
repository
,
diff_refs
)
).
to_json
}
else
workhorse_diff_or_patch_hash
(
repository
,
diff_refs
)
end
[
SEND_DATA_HEADER
,
...
...
@@ -216,6 +226,22 @@ module Gitlab
token:
Gitlab
::
GitalyClient
.
token
(
repository
.
project
.
repository_storage
)
}
end
def
workhorse_diff_or_patch_hash
(
repository
,
diff_refs
)
{
'RepoPath'
=>
repository
.
path_to_repo
,
'ShaFrom'
=>
diff_refs
.
base_sha
,
'ShaTo'
=>
diff_refs
.
head_sha
}
end
def
gitaly_diff_or_patch_hash
(
repository
,
diff_refs
)
{
repository:
repository
.
gitaly_repository
,
left_commit_id:
diff_refs
.
base_sha
,
right_commit_id:
diff_refs
.
head_sha
}
end
end
end
end
spec/lib/gitlab/workhorse_spec.rb
View file @
618dd9e4
...
...
@@ -66,12 +66,34 @@ describe Gitlab::Workhorse do
let
(
:diff_refs
)
{
double
(
base_sha:
"base"
,
head_sha:
"head"
)
}
subject
{
described_class
.
send_git_patch
(
repository
,
diff_refs
)
}
it
'sets the header correctly'
do
key
,
command
,
params
=
decode_workhorse_header
(
subject
)
context
'when Gitaly workhorse_send_git_patch feature is enabled'
do
it
'sets the header correctly'
do
key
,
command
,
params
=
decode_workhorse_header
(
subject
)
expect
(
key
).
to
eq
(
"Gitlab-Workhorse-Send-Data"
)
expect
(
command
).
to
eq
(
"git-format-patch"
)
expect
(
params
).
to
eq
({
'GitalyServer'
=>
{
address:
Gitlab
::
GitalyClient
.
address
(
project
.
repository_storage
),
token:
Gitlab
::
GitalyClient
.
token
(
project
.
repository_storage
)
},
'RawPatchRequest'
=>
Gitaly
::
RawPatchRequest
.
new
(
repository:
repository
.
gitaly_repository
,
left_commit_id:
'base'
,
right_commit_id:
'head'
).
to_json
}.
deep_stringify_keys
)
end
end
context
'when Gitaly workhorse_send_git_patch feature is disabled'
,
skip_gitaly_mock:
true
do
it
'sets the header correctly'
do
key
,
command
,
params
=
decode_workhorse_header
(
subject
)
expect
(
key
).
to
eq
(
"Gitlab-Workhorse-Send-Data"
)
expect
(
command
).
to
eq
(
"git-format-patch"
)
expect
(
params
).
to
eq
(
"RepoPath"
=>
repository
.
path_to_repo
,
"ShaFrom"
=>
"base"
,
"ShaTo"
=>
"head"
)
expect
(
key
).
to
eq
(
"Gitlab-Workhorse-Send-Data"
)
expect
(
command
).
to
eq
(
"git-format-patch"
)
expect
(
params
).
to
eq
(
"RepoPath"
=>
repository
.
path_to_repo
,
"ShaFrom"
=>
"base"
,
"ShaTo"
=>
"head"
)
end
end
end
...
...
@@ -115,14 +137,36 @@ describe Gitlab::Workhorse do
describe
'.send_git_diff'
do
let
(
:diff_refs
)
{
double
(
base_sha:
"base"
,
head_sha:
"head"
)
}
subject
{
described_class
.
send_git_
patch
(
repository
,
diff_refs
)
}
subject
{
described_class
.
send_git_
diff
(
repository
,
diff_refs
)
}
it
'sets the header correctly'
do
key
,
command
,
params
=
decode_workhorse_header
(
subject
)
context
'when Gitaly workhorse_send_git_diff feature is enabled'
do
it
'sets the header correctly'
do
key
,
command
,
params
=
decode_workhorse_header
(
subject
)
expect
(
key
).
to
eq
(
"Gitlab-Workhorse-Send-Data"
)
expect
(
command
).
to
eq
(
"git-format-patch"
)
expect
(
params
).
to
eq
(
"RepoPath"
=>
repository
.
path_to_repo
,
"ShaFrom"
=>
"base"
,
"ShaTo"
=>
"head"
)
expect
(
key
).
to
eq
(
"Gitlab-Workhorse-Send-Data"
)
expect
(
command
).
to
eq
(
"git-diff"
)
expect
(
params
).
to
eq
({
'GitalyServer'
=>
{
address:
Gitlab
::
GitalyClient
.
address
(
project
.
repository_storage
),
token:
Gitlab
::
GitalyClient
.
token
(
project
.
repository_storage
)
},
'RawDiffRequest'
=>
Gitaly
::
RawDiffRequest
.
new
(
repository:
repository
.
gitaly_repository
,
left_commit_id:
'base'
,
right_commit_id:
'head'
).
to_json
}.
deep_stringify_keys
)
end
end
context
'when Gitaly workhorse_send_git_diff feature is disabled'
,
skip_gitaly_mock:
true
do
it
'sets the header correctly'
do
key
,
command
,
params
=
decode_workhorse_header
(
subject
)
expect
(
key
).
to
eq
(
"Gitlab-Workhorse-Send-Data"
)
expect
(
command
).
to
eq
(
"git-diff"
)
expect
(
params
).
to
eq
(
"RepoPath"
=>
repository
.
path_to_repo
,
"ShaFrom"
=>
"base"
,
"ShaTo"
=>
"head"
)
end
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