debian-mirror-gitlab/lib/gitlab/gitaly_client/conflicts_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
3 KiB
Ruby
Raw Permalink Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Gitlab
module GitalyClient
class ConflictsService
include Gitlab::EncodingHelper
2023-01-13 00:05:48 +05:30
include WithFeatureFlagActors
2018-03-17 18:26:18 +05:30
MAX_MSG_SIZE = 128.kilobytes.freeze
def initialize(repository, our_commit_oid, their_commit_oid)
@gitaly_repo = repository.gitaly_repository
@repository = repository
@our_commit_oid = our_commit_oid
@their_commit_oid = their_commit_oid
2023-01-13 00:05:48 +05:30
self.repository_actor = repository
2018-03-17 18:26:18 +05:30
end
2021-10-27 15:23:28 +05:30
def list_conflict_files(allow_tree_conflicts: false)
2018-03-17 18:26:18 +05:30
request = Gitaly::ListConflictFilesRequest.new(
repository: @gitaly_repo,
our_commit_oid: @our_commit_oid,
2021-10-27 15:23:28 +05:30
their_commit_oid: @their_commit_oid,
allow_tree_conflicts: allow_tree_conflicts
2018-03-17 18:26:18 +05:30
)
2023-01-13 00:05:48 +05:30
response = gitaly_client_call(@repository.storage, :conflicts_service, :list_conflict_files, request, timeout: GitalyClient.long_timeout)
2019-12-21 20:55:43 +05:30
GitalyClient::ConflictFilesStitcher.new(response, @gitaly_repo)
2018-03-17 18:26:18 +05:30
end
def conflicts?
list_conflict_files.any?
2018-11-08 19:23:39 +05:30
rescue GRPC::FailedPrecondition, GRPC::Unknown
# The server raises FailedPrecondition when it encounters
# ConflictSideMissing, which means a conflict exists but its `theirs` or
# `ours` data is nil due to a non-existent file in one of the trees.
#
# GRPC::Unknown comes from Rugged::ReferenceError and Rugged::OdbError.
2018-03-17 18:26:18 +05:30
true
end
def resolve_conflicts(target_repository, resolution, source_branch, target_branch)
2019-07-07 11:18:12 +05:30
reader = binary_io(resolution.files.to_json)
2018-03-17 18:26:18 +05:30
req_enum = Enumerator.new do |y|
header = resolve_conflicts_request_header(target_repository, resolution, source_branch, target_branch)
y.yield Gitaly::ResolveConflictsRequest.new(header: header)
until reader.eof?
chunk = reader.read(MAX_MSG_SIZE)
y.yield Gitaly::ResolveConflictsRequest.new(files_json: chunk)
end
end
2023-01-13 00:05:48 +05:30
response = gitaly_client_call(@repository.storage, :conflicts_service, :resolve_conflicts, req_enum, remote_storage: target_repository.storage, timeout: GitalyClient.long_timeout)
2018-03-17 18:26:18 +05:30
if response.resolution_error.present?
raise Gitlab::Git::Conflict::Resolver::ResolutionError, response.resolution_error
end
end
private
def resolve_conflicts_request_header(target_repository, resolution, source_branch, target_branch)
Gitaly::ResolveConflictsRequestHeader.new(
repository: @gitaly_repo,
our_commit_oid: @our_commit_oid,
target_repository: target_repository.gitaly_repository,
their_commit_oid: @their_commit_oid,
2019-09-04 21:01:54 +05:30
source_branch: encode_binary(source_branch),
target_branch: encode_binary(target_branch),
commit_message: encode_binary(resolution.commit_message),
2021-03-11 19:13:27 +05:30
user: Gitlab::Git::User.from_gitlab(resolution.user).to_gitaly,
timestamp: Google::Protobuf::Timestamp.new(seconds: Time.now.utc.to_i)
2018-03-17 18:26:18 +05:30
)
end
end
end
end