2018-11-09 13:39:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-01-09 07:53:35 -05:00
|
|
|
module Gitlab
|
|
|
|
module GitalyClient
|
|
|
|
class ConflictFilesStitcher
|
|
|
|
include Enumerable
|
|
|
|
|
2019-10-17 20:07:45 -04:00
|
|
|
attr_reader :gitaly_repo
|
|
|
|
|
|
|
|
def initialize(rpc_response, gitaly_repo)
|
2018-01-09 07:53:35 -05:00
|
|
|
@rpc_response = rpc_response
|
2019-10-17 20:07:45 -04:00
|
|
|
@gitaly_repo = gitaly_repo
|
2018-01-09 07:53:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def each
|
|
|
|
current_file = nil
|
|
|
|
|
|
|
|
@rpc_response.each do |msg|
|
|
|
|
msg.files.each do |gitaly_file|
|
|
|
|
if gitaly_file.header
|
|
|
|
yield current_file if current_file
|
|
|
|
|
|
|
|
current_file = file_from_gitaly_header(gitaly_file.header)
|
|
|
|
else
|
2018-11-09 13:39:43 -05:00
|
|
|
current_file.raw_content = "#{current_file.raw_content}#{gitaly_file.content}"
|
2018-01-09 07:53:35 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
yield current_file if current_file
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def file_from_gitaly_header(header)
|
|
|
|
Gitlab::Git::Conflict::File.new(
|
2019-10-17 20:07:45 -04:00
|
|
|
Gitlab::GitalyClient::Util.git_repository(gitaly_repo),
|
2018-01-09 07:53:35 -05:00
|
|
|
header.commit_oid,
|
|
|
|
conflict_from_gitaly_file_header(header),
|
|
|
|
''
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def conflict_from_gitaly_file_header(header)
|
|
|
|
{
|
2021-07-28 11:09:57 -04:00
|
|
|
ancestor: { path: header.ancestor_path },
|
2018-01-09 07:53:35 -05:00
|
|
|
ours: { path: header.our_path, mode: header.our_mode },
|
|
|
|
theirs: { path: header.their_path }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|