Commit 618dd9e4 authored by Ahmad Sherif's avatar Ahmad Sherif

Migrate Workhorse Send{Diff,Patch} to Gitaly

parent 1c0407e8
...@@ -103,11 +103,16 @@ module Gitlab ...@@ -103,11 +103,16 @@ module Gitlab
end end
def send_git_diff(repository, diff_refs) def send_git_diff(repository, diff_refs)
params = { params = if Gitlab::GitalyClient.feature_enabled?(:workhorse_send_git_diff)
'RepoPath' => repository.path_to_repo, {
'ShaFrom' => diff_refs.base_sha, 'GitalyServer' => gitaly_server_hash(repository),
'ShaTo' => diff_refs.head_sha '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, SEND_DATA_HEADER,
...@@ -116,11 +121,16 @@ module Gitlab ...@@ -116,11 +121,16 @@ module Gitlab
end end
def send_git_patch(repository, diff_refs) def send_git_patch(repository, diff_refs)
params = { params = if Gitlab::GitalyClient.feature_enabled?(:workhorse_send_git_patch)
'RepoPath' => repository.path_to_repo, {
'ShaFrom' => diff_refs.base_sha, 'GitalyServer' => gitaly_server_hash(repository),
'ShaTo' => diff_refs.head_sha '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, SEND_DATA_HEADER,
...@@ -216,6 +226,22 @@ module Gitlab ...@@ -216,6 +226,22 @@ module Gitlab
token: Gitlab::GitalyClient.token(repository.project.repository_storage) token: Gitlab::GitalyClient.token(repository.project.repository_storage)
} }
end 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 end
end end
...@@ -66,12 +66,34 @@ describe Gitlab::Workhorse do ...@@ -66,12 +66,34 @@ describe Gitlab::Workhorse do
let(:diff_refs) { double(base_sha: "base", head_sha: "head") } let(:diff_refs) { double(base_sha: "base", head_sha: "head") }
subject { described_class.send_git_patch(repository, diff_refs) } subject { described_class.send_git_patch(repository, diff_refs) }
it 'sets the header correctly' do context 'when Gitaly workhorse_send_git_patch feature is enabled' do
key, command, params = decode_workhorse_header(subject) 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(key).to eq("Gitlab-Workhorse-Send-Data")
expect(command).to eq("git-format-patch") expect(command).to eq("git-format-patch")
expect(params).to eq("RepoPath" => repository.path_to_repo, "ShaFrom" => "base", "ShaTo" => "head") expect(params).to eq("RepoPath" => repository.path_to_repo, "ShaFrom" => "base", "ShaTo" => "head")
end
end end
end end
...@@ -115,14 +137,36 @@ describe Gitlab::Workhorse do ...@@ -115,14 +137,36 @@ describe Gitlab::Workhorse do
describe '.send_git_diff' do describe '.send_git_diff' do
let(:diff_refs) { double(base_sha: "base", head_sha: "head") } 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 context 'when Gitaly workhorse_send_git_diff feature is enabled' do
key, command, params = decode_workhorse_header(subject) it 'sets the header correctly' do
key, command, params = decode_workhorse_header(subject)
expect(key).to eq("Gitlab-Workhorse-Send-Data") expect(key).to eq("Gitlab-Workhorse-Send-Data")
expect(command).to eq("git-format-patch") expect(command).to eq("git-diff")
expect(params).to eq("RepoPath" => repository.path_to_repo, "ShaFrom" => "base", "ShaTo" => "head") 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
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment