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

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

54 lines
1.3 KiB
Ruby
Raw 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 ConflictFilesStitcher
include Enumerable
2019-12-21 20:55:43 +05:30
attr_reader :gitaly_repo
def initialize(rpc_response, gitaly_repo)
2018-03-17 18:26:18 +05:30
@rpc_response = rpc_response
2019-12-21 20:55:43 +05:30
@gitaly_repo = gitaly_repo
2018-03-17 18:26:18 +05:30
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
2019-02-15 15:39:39 +05:30
current_file.raw_content = "#{current_file.raw_content}#{gitaly_file.content}"
2018-03-17 18:26:18 +05:30
end
end
end
yield current_file if current_file
end
private
def file_from_gitaly_header(header)
Gitlab::Git::Conflict::File.new(
2019-12-21 20:55:43 +05:30
Gitlab::GitalyClient::Util.git_repository(gitaly_repo),
2018-03-17 18:26:18 +05:30
header.commit_oid,
conflict_from_gitaly_file_header(header),
''
)
end
def conflict_from_gitaly_file_header(header)
{
2021-10-27 15:23:28 +05:30
ancestor: { path: header.ancestor_path },
2018-03-17 18:26:18 +05:30
ours: { path: header.our_path, mode: header.our_mode },
theirs: { path: header.their_path }
}
end
end
end
end