Commit 4475212a authored by Robert Speicher's avatar Robert Speicher

Merge branch 'feature/migrate-revert-to-gitaly' into 'master'

Migrate Gitlab::Git::Repository#revert to Gitaly

Closes gitaly#780

See merge request gitlab-org/gitlab-ce!15717
parents 4215309d 887a3739
...@@ -400,7 +400,7 @@ group :ed25519 do ...@@ -400,7 +400,7 @@ group :ed25519 do
end end
# Gitaly GRPC client # Gitaly GRPC client
gem 'gitaly-proto', '~> 0.58.0', require: 'gitaly' gem 'gitaly-proto', '~> 0.59.0', require: 'gitaly'
gem 'toml-rb', '~> 0.3.15', require: false gem 'toml-rb', '~> 0.3.15', require: false
......
...@@ -276,7 +276,7 @@ GEM ...@@ -276,7 +276,7 @@ GEM
po_to_json (>= 1.0.0) po_to_json (>= 1.0.0)
rails (>= 3.2.0) rails (>= 3.2.0)
gherkin-ruby (0.3.2) gherkin-ruby (0.3.2)
gitaly-proto (0.58.0) gitaly-proto (0.59.0)
google-protobuf (~> 3.1) google-protobuf (~> 3.1)
grpc (~> 1.0) grpc (~> 1.0)
github-linguist (4.7.6) github-linguist (4.7.6)
...@@ -1037,7 +1037,7 @@ DEPENDENCIES ...@@ -1037,7 +1037,7 @@ DEPENDENCIES
gettext (~> 3.2.2) gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.2.0) gettext_i18n_rails_js (~> 1.2.0)
gitaly-proto (~> 0.58.0) gitaly-proto (~> 0.59.0)
github-linguist (~> 4.7.0) github-linguist (~> 4.7.0)
gitlab-flowdock-git-hook (~> 1.0.1) gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-markup (~> 1.6.2) gitlab-markup (~> 1.6.2)
......
...@@ -776,24 +776,21 @@ module Gitlab ...@@ -776,24 +776,21 @@ module Gitlab
end end
def revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:) def revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:)
OperationService.new(user, self).with_branch( gitaly_migrate(:revert) do |is_enabled|
branch_name, args = {
user: user,
commit: commit,
branch_name: branch_name,
message: message,
start_branch_name: start_branch_name, start_branch_name: start_branch_name,
start_repository: start_repository start_repository: start_repository
) do |start_commit| }
Gitlab::Git.check_namespace!(commit, start_repository)
revert_tree_id = check_revert_content(commit, start_commit.sha)
raise CreateTreeError unless revert_tree_id
committer = user_to_committer(user)
create_commit(message: message, if is_enabled
author: committer, gitaly_operations_client.user_revert(args)
committer: committer, else
tree: revert_tree_id, rugged_revert(args)
parents: [start_commit.sha]) end
end end
end end
...@@ -1769,6 +1766,28 @@ module Gitlab ...@@ -1769,6 +1766,28 @@ module Gitlab
end end
end end
def rugged_revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:)
OperationService.new(user, self).with_branch(
branch_name,
start_branch_name: start_branch_name,
start_repository: start_repository
) do |start_commit|
Gitlab::Git.check_namespace!(commit, start_repository)
revert_tree_id = check_revert_content(commit, start_commit.sha)
raise CreateTreeError unless revert_tree_id
committer = user_to_committer(user)
create_commit(message: message,
author: committer,
committer: committer,
tree: revert_tree_id,
parents: [start_commit.sha])
end
end
def gitaly_add_branch(branch_name, user, target) def gitaly_add_branch(branch_name, user, target)
gitaly_operation_client.user_create_branch(branch_name, user, target) gitaly_operation_client.user_create_branch(branch_name, user, target)
rescue GRPC::FailedPrecondition => ex rescue GRPC::FailedPrecondition => ex
......
...@@ -124,7 +124,31 @@ module Gitlab ...@@ -124,7 +124,31 @@ module Gitlab
end end
def user_cherry_pick(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:) def user_cherry_pick(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:)
request = Gitaly::UserCherryPickRequest.new( call_cherry_pick_or_revert(:cherry_pick,
user: user,
commit: commit,
branch_name: branch_name,
message: message,
start_branch_name: start_branch_name,
start_repository: start_repository)
end
def user_revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:)
call_cherry_pick_or_revert(:revert,
user: user,
commit: commit,
branch_name: branch_name,
message: message,
start_branch_name: start_branch_name,
start_repository: start_repository)
end
private
def call_cherry_pick_or_revert(rpc, user:, commit:, branch_name:, message:, start_branch_name:, start_repository:)
request_class = "Gitaly::User#{rpc.to_s.camelcase}Request".constantize
request = request_class.new(
repository: @gitaly_repo, repository: @gitaly_repo,
user: Gitlab::Git::User.from_gitlab(user).to_gitaly, user: Gitlab::Git::User.from_gitlab(user).to_gitaly,
commit: commit.to_gitaly_commit, commit: commit.to_gitaly_commit,
...@@ -137,11 +161,15 @@ module Gitlab ...@@ -137,11 +161,15 @@ module Gitlab
response = GitalyClient.call( response = GitalyClient.call(
@repository.storage, @repository.storage,
:operation_service, :operation_service,
:user_cherry_pick, :"user_#{rpc}",
request, request,
remote_storage: start_repository.storage remote_storage: start_repository.storage
) )
handle_cherry_pick_or_revert_response(response)
end
def handle_cherry_pick_or_revert_response(response)
if response.pre_receive_error.presence if response.pre_receive_error.presence
raise Gitlab::Git::HooksService::PreReceiveError, response.pre_receive_error raise Gitlab::Git::HooksService::PreReceiveError, response.pre_receive_error
elsif response.commit_error.presence elsif response.commit_error.presence
......
...@@ -1372,6 +1372,7 @@ describe Repository do ...@@ -1372,6 +1372,7 @@ describe Repository do
end end
describe '#revert' do describe '#revert' do
shared_examples 'reverting a commit' do
let(:new_image_commit) { repository.commit('33f3729a45c02fc67d00adb1b8bca394b0e761d9') } let(:new_image_commit) { repository.commit('33f3729a45c02fc67d00adb1b8bca394b0e761d9') }
let(:update_image_commit) { repository.commit('2f63565e7aac07bcdadb654e253078b727143ec4') } let(:update_image_commit) { repository.commit('2f63565e7aac07bcdadb654e253078b727143ec4') }
let(:message) { 'revert message' } let(:message) { 'revert message' }
...@@ -1407,6 +1408,15 @@ describe Repository do ...@@ -1407,6 +1408,15 @@ describe Repository do
end end
end end
context 'when Gitaly revert feature is enabled' do
it_behaves_like 'reverting a commit'
end
context 'when Gitaly revert feature is disabled', :disable_gitaly do
it_behaves_like 'reverting a commit'
end
end
describe '#cherry_pick' do describe '#cherry_pick' do
shared_examples 'cherry-picking a commit' do shared_examples 'cherry-picking a commit' do
let(:conflict_commit) { repository.commit('c642fe9b8b9f28f9225d7ea953fe14e74748d53b') } let(:conflict_commit) { repository.commit('c642fe9b8b9f28f9225d7ea953fe14e74748d53b') }
......
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