2018-11-09 18:39:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-24 15:53:44 +00:00
|
|
|
module Gitlab
|
|
|
|
module GitalyClient
|
2017-07-18 07:59:36 +00:00
|
|
|
class CommitService
|
2017-12-26 18:53:31 +00:00
|
|
|
include Gitlab::EncodingHelper
|
|
|
|
|
2017-04-11 19:23:00 +00:00
|
|
|
def initialize(repository)
|
|
|
|
@gitaly_repo = repository.gitaly_repository
|
2017-05-05 14:55:12 +00:00
|
|
|
@repository = repository
|
2017-04-11 19:23:00 +00:00
|
|
|
end
|
|
|
|
|
2017-08-04 04:16:02 +00:00
|
|
|
def ls_files(revision)
|
|
|
|
request = Gitaly::ListFilesRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
2017-12-26 18:53:31 +00:00
|
|
|
revision: encode_binary(revision)
|
2017-08-04 04:16:02 +00:00
|
|
|
)
|
|
|
|
|
2017-11-29 09:12:12 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :list_files, request, timeout: GitalyClient.medium_timeout)
|
2017-08-04 04:16:02 +00:00
|
|
|
response.flat_map do |msg|
|
2017-11-02 08:29:03 +00:00
|
|
|
msg.paths.map { |d| EncodingHelper.encode!(d.dup) }
|
2017-08-04 04:16:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-24 17:52:43 +00:00
|
|
|
def ancestor?(ancestor_id, child_id)
|
2017-04-11 19:23:00 +00:00
|
|
|
request = Gitaly::CommitIsAncestorRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
ancestor_id: ancestor_id,
|
|
|
|
child_id: child_id
|
|
|
|
)
|
|
|
|
|
2017-11-29 09:12:12 +00:00
|
|
|
GitalyClient.call(@repository.storage, :commit_service, :commit_is_ancestor, request, timeout: GitalyClient.fast_timeout).value
|
2017-05-05 14:55:12 +00:00
|
|
|
end
|
|
|
|
|
2017-09-11 12:52:27 +00:00
|
|
|
def diff(from, to, options = {})
|
|
|
|
from_id = case from
|
|
|
|
when NilClass
|
2018-04-12 03:05:07 +00:00
|
|
|
Gitlab::Git::EMPTY_TREE_ID
|
2017-09-11 12:52:27 +00:00
|
|
|
else
|
2018-01-23 17:42:10 +00:00
|
|
|
if from.respond_to?(:oid)
|
|
|
|
# This is meant to match a Rugged::Commit. This should be impossible in
|
|
|
|
# the future.
|
|
|
|
from.oid
|
|
|
|
else
|
|
|
|
from
|
|
|
|
end
|
2017-09-11 12:52:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
to_id = case to
|
|
|
|
when NilClass
|
2018-04-12 03:05:07 +00:00
|
|
|
Gitlab::Git::EMPTY_TREE_ID
|
2017-09-11 12:52:27 +00:00
|
|
|
else
|
2018-01-23 17:42:10 +00:00
|
|
|
if to.respond_to?(:oid)
|
|
|
|
# This is meant to match a Rugged::Commit. This should be impossible in
|
|
|
|
# the future.
|
|
|
|
to.oid
|
|
|
|
else
|
|
|
|
to
|
|
|
|
end
|
2017-09-11 12:52:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
request_params = diff_between_commits_request_params(from_id, to_id, options)
|
|
|
|
|
|
|
|
call_commit_diff(request_params, options)
|
|
|
|
end
|
|
|
|
|
2017-05-05 14:55:12 +00:00
|
|
|
def diff_from_parent(commit, options = {})
|
2017-09-11 12:52:27 +00:00
|
|
|
request_params = diff_from_parent_request_params(commit, options)
|
2017-07-13 22:22:09 +00:00
|
|
|
|
2017-09-11 12:52:27 +00:00
|
|
|
call_commit_diff(request_params, options)
|
2017-04-11 19:23:00 +00:00
|
|
|
end
|
|
|
|
|
2017-05-05 14:55:12 +00:00
|
|
|
def commit_deltas(commit)
|
2017-09-11 12:52:27 +00:00
|
|
|
request = Gitaly::CommitDeltaRequest.new(diff_from_parent_request_params(commit))
|
2020-07-01 00:09:02 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :diff_service, :commit_delta, request, timeout: GitalyClient.fast_timeout)
|
|
|
|
response.flat_map { |msg| msg.deltas }
|
2017-02-24 15:53:44 +00:00
|
|
|
end
|
2017-05-05 14:55:12 +00:00
|
|
|
|
2017-06-12 18:55:28 +00:00
|
|
|
def tree_entry(ref, path, limit = nil)
|
2018-06-26 12:12:08 +00:00
|
|
|
if Pathname.new(path).cleanpath.to_s.start_with?('../')
|
2019-05-20 14:11:44 +00:00
|
|
|
# The TreeEntry RPC should return an empty response in this case but in
|
2018-06-26 12:12:08 +00:00
|
|
|
# Gitaly 0.107.0 and earlier we get an exception instead. This early return
|
|
|
|
# saves us a Gitaly roundtrip while also avoiding the exception.
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-06-12 18:55:28 +00:00
|
|
|
request = Gitaly::TreeEntryRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
2018-05-30 10:48:25 +00:00
|
|
|
revision: encode_binary(ref),
|
2017-12-26 18:53:31 +00:00
|
|
|
path: encode_binary(path),
|
2017-06-12 18:55:28 +00:00
|
|
|
limit: limit.to_i
|
|
|
|
)
|
|
|
|
|
2017-11-29 09:12:12 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :tree_entry, request, timeout: GitalyClient.medium_timeout)
|
2017-06-12 18:55:28 +00:00
|
|
|
|
2017-08-16 12:29:27 +00:00
|
|
|
entry = nil
|
2018-11-09 18:39:43 +00:00
|
|
|
data = []
|
2017-08-16 12:29:27 +00:00
|
|
|
response.each do |msg|
|
|
|
|
if entry.nil?
|
|
|
|
entry = msg
|
|
|
|
|
|
|
|
break unless entry.type == :BLOB
|
|
|
|
end
|
|
|
|
|
|
|
|
data << msg.data
|
2017-06-12 18:55:28 +00:00
|
|
|
end
|
2018-11-09 18:39:43 +00:00
|
|
|
entry.data = data.join
|
2017-06-12 18:55:28 +00:00
|
|
|
|
2017-08-16 12:29:27 +00:00
|
|
|
entry unless entry.oid.blank?
|
2021-03-25 21:09:13 +00:00
|
|
|
rescue GRPC::NotFound
|
|
|
|
nil
|
2017-06-12 18:55:28 +00:00
|
|
|
end
|
|
|
|
|
2018-02-16 20:39:43 +00:00
|
|
|
def tree_entries(repository, revision, path, recursive)
|
2017-07-18 05:02:56 +00:00
|
|
|
request = Gitaly::GetTreeEntriesRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
2017-12-26 18:53:31 +00:00
|
|
|
revision: encode_binary(revision),
|
2018-02-16 20:39:43 +00:00
|
|
|
path: path.present? ? encode_binary(path) : '.',
|
|
|
|
recursive: recursive
|
2017-07-18 05:02:56 +00:00
|
|
|
)
|
|
|
|
|
2017-11-29 09:12:12 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :get_tree_entries, request, timeout: GitalyClient.medium_timeout)
|
2017-07-18 05:02:56 +00:00
|
|
|
|
|
|
|
response.flat_map do |message|
|
|
|
|
message.entries.map do |gitaly_tree_entry|
|
|
|
|
Gitlab::Git::Tree.new(
|
|
|
|
id: gitaly_tree_entry.oid,
|
|
|
|
root_id: gitaly_tree_entry.root_oid,
|
|
|
|
type: gitaly_tree_entry.type.downcase,
|
|
|
|
mode: gitaly_tree_entry.mode.to_s(8),
|
2017-09-06 20:47:25 +00:00
|
|
|
name: File.basename(gitaly_tree_entry.path),
|
2017-12-26 18:53:31 +00:00
|
|
|
path: encode_binary(gitaly_tree_entry.path),
|
|
|
|
flat_path: encode_binary(gitaly_tree_entry.flat_path),
|
2017-07-18 05:02:56 +00:00
|
|
|
commit_id: gitaly_tree_entry.commit_oid
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-06-12 18:55:28 +00:00
|
|
|
|
2017-07-27 06:45:04 +00:00
|
|
|
def commit_count(ref, options = {})
|
2017-07-06 18:34:25 +00:00
|
|
|
request = Gitaly::CountCommitsRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
2018-03-01 16:50:07 +00:00
|
|
|
revision: encode_binary(ref),
|
2019-09-19 21:06:29 +00:00
|
|
|
all: !!options[:all],
|
|
|
|
first_parent: !!options[:first_parent]
|
2017-07-06 18:34:25 +00:00
|
|
|
)
|
2017-07-27 06:45:04 +00:00
|
|
|
request.after = Google::Protobuf::Timestamp.new(seconds: options[:after].to_i) if options[:after].present?
|
|
|
|
request.before = Google::Protobuf::Timestamp.new(seconds: options[:before].to_i) if options[:before].present?
|
2018-01-23 08:26:28 +00:00
|
|
|
request.path = encode_binary(options[:path]) if options[:path].present?
|
2017-12-27 13:16:24 +00:00
|
|
|
request.max_count = options[:max_count] if options[:max_count].present?
|
2017-07-06 18:34:25 +00:00
|
|
|
|
2017-11-29 09:12:12 +00:00
|
|
|
GitalyClient.call(@repository.storage, :commit_service, :count_commits, request, timeout: GitalyClient.medium_timeout).count
|
2017-07-06 18:34:25 +00:00
|
|
|
end
|
|
|
|
|
2019-01-10 02:45:47 +00:00
|
|
|
def diverging_commit_count(from, to, max_count:)
|
|
|
|
request = Gitaly::CountDivergingCommitsRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
from: encode_binary(from),
|
|
|
|
to: encode_binary(to),
|
|
|
|
max_count: max_count
|
|
|
|
)
|
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :count_diverging_commits, request, timeout: GitalyClient.medium_timeout)
|
|
|
|
[response.left_count, response.right_count]
|
|
|
|
end
|
|
|
|
|
2020-06-26 21:08:51 +00:00
|
|
|
def list_last_commits_for_tree(revision, path, offset: 0, limit: 25, literal_pathspec: false)
|
2018-10-01 12:29:47 +00:00
|
|
|
request = Gitaly::ListLastCommitsForTreeRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
revision: encode_binary(revision),
|
|
|
|
path: encode_binary(path.to_s),
|
|
|
|
offset: offset,
|
2020-06-26 21:08:51 +00:00
|
|
|
limit: limit,
|
|
|
|
global_options: parse_global_options!(literal_pathspec: literal_pathspec)
|
2018-10-01 12:29:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :list_last_commits_for_tree, request, timeout: GitalyClient.medium_timeout)
|
|
|
|
|
|
|
|
response.each_with_object({}) do |gitaly_response, hsh|
|
|
|
|
gitaly_response.commits.each do |commit_for_tree|
|
2019-04-02 18:15:59 +00:00
|
|
|
hsh[commit_for_tree.path_bytes] = Gitlab::Git::Commit.new(@repository, commit_for_tree.commit)
|
2018-10-01 12:29:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-22 03:08:17 +00:00
|
|
|
def last_commit_for_path(revision, path, literal_pathspec: false)
|
2017-07-31 17:38:36 +00:00
|
|
|
request = Gitaly::LastCommitForPathRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
2017-12-26 18:53:31 +00:00
|
|
|
revision: encode_binary(revision),
|
2020-06-22 03:08:17 +00:00
|
|
|
path: encode_binary(path.to_s),
|
2020-06-26 21:08:51 +00:00
|
|
|
global_options: parse_global_options!(literal_pathspec: literal_pathspec)
|
2017-07-31 17:38:36 +00:00
|
|
|
)
|
|
|
|
|
2017-11-29 09:12:12 +00:00
|
|
|
gitaly_commit = GitalyClient.call(@repository.storage, :commit_service, :last_commit_for_path, request, timeout: GitalyClient.fast_timeout).commit
|
2017-07-31 17:38:36 +00:00
|
|
|
return unless gitaly_commit
|
|
|
|
|
2017-07-25 20:48:17 +00:00
|
|
|
Gitlab::Git::Commit.new(@repository, gitaly_commit)
|
2017-07-31 17:38:36 +00:00
|
|
|
end
|
|
|
|
|
2017-06-23 21:52:51 +00:00
|
|
|
def between(from, to)
|
|
|
|
request = Gitaly::CommitsBetweenRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
from: from,
|
|
|
|
to: to
|
|
|
|
)
|
|
|
|
|
2020-07-01 00:09:02 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :commits_between, request, timeout: GitalyClient.medium_timeout)
|
|
|
|
consume_commits_response(response)
|
2017-06-23 21:52:51 +00:00
|
|
|
end
|
|
|
|
|
2018-09-14 01:11:35 +00:00
|
|
|
def diff_stats(left_commit_sha, right_commit_sha)
|
|
|
|
request = Gitaly::DiffStatsRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
left_commit_id: left_commit_sha,
|
|
|
|
right_commit_id: right_commit_sha
|
|
|
|
)
|
|
|
|
|
2020-07-01 00:09:02 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :diff_service, :diff_stats, request, timeout: GitalyClient.medium_timeout)
|
|
|
|
response.flat_map(&:stats)
|
2018-09-14 01:11:35 +00:00
|
|
|
end
|
|
|
|
|
2020-12-04 06:09:34 +00:00
|
|
|
def find_changed_paths(commits)
|
|
|
|
request = Gitaly::FindChangedPathsRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
commits: commits
|
|
|
|
)
|
|
|
|
|
|
|
|
response = GitalyClient.call(@repository.storage, :diff_service, :find_changed_paths, request, timeout: GitalyClient.medium_timeout)
|
|
|
|
response.flat_map do |msg|
|
|
|
|
msg.paths.map do |path|
|
2021-01-05 15:10:02 +00:00
|
|
|
Gitlab::Git::ChangedPath.new(
|
2020-12-04 06:09:34 +00:00
|
|
|
status: path.status,
|
|
|
|
path: EncodingHelper.encode!(path.path)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-18 08:06:49 +00:00
|
|
|
def find_all_commits(opts = {})
|
|
|
|
request = Gitaly::FindAllCommitsRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
revision: opts[:ref].to_s,
|
|
|
|
max_count: opts[:max_count].to_i,
|
|
|
|
skip: opts[:skip].to_i
|
|
|
|
)
|
|
|
|
request.order = opts[:order].upcase if opts[:order].present?
|
|
|
|
|
2020-07-01 00:09:02 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :find_all_commits, request, timeout: GitalyClient.medium_timeout)
|
|
|
|
consume_commits_response(response)
|
2017-07-18 08:06:49 +00:00
|
|
|
end
|
|
|
|
|
2017-12-05 13:15:30 +00:00
|
|
|
def list_commits_by_oid(oids)
|
2018-06-13 13:23:34 +00:00
|
|
|
return [] if oids.empty?
|
|
|
|
|
2017-12-05 13:15:30 +00:00
|
|
|
request = Gitaly::ListCommitsByOidRequest.new(repository: @gitaly_repo, oid: oids)
|
|
|
|
|
2020-07-01 00:09:02 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :list_commits_by_oid, request, timeout: GitalyClient.medium_timeout)
|
|
|
|
consume_commits_response(response)
|
2018-01-15 13:17:25 +00:00
|
|
|
rescue GRPC::NotFound # If no repository is found, happens mainly during testing
|
2017-12-05 13:15:30 +00:00
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
2020-06-26 21:08:51 +00:00
|
|
|
def commits_by_message(query, revision: '', path: '', limit: 1000, offset: 0, literal_pathspec: true)
|
2017-08-03 08:22:01 +00:00
|
|
|
request = Gitaly::CommitsByMessageRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
query: query,
|
2020-06-11 15:08:36 +00:00
|
|
|
revision: encode_binary(revision),
|
|
|
|
path: encode_binary(path),
|
2017-08-03 08:22:01 +00:00
|
|
|
limit: limit.to_i,
|
2020-06-26 21:08:51 +00:00
|
|
|
offset: offset.to_i,
|
|
|
|
global_options: parse_global_options!(literal_pathspec: literal_pathspec)
|
2017-08-03 08:22:01 +00:00
|
|
|
)
|
|
|
|
|
2020-07-01 00:09:02 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :commits_by_message, request, timeout: GitalyClient.medium_timeout)
|
|
|
|
consume_commits_response(response)
|
2017-08-03 08:22:01 +00:00
|
|
|
end
|
|
|
|
|
2017-07-31 13:23:05 +00:00
|
|
|
def languages(ref = nil)
|
|
|
|
request = Gitaly::CommitLanguagesRequest.new(repository: @gitaly_repo, revision: ref || '')
|
2019-09-19 18:06:18 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :commit_languages, request, timeout: GitalyClient.long_timeout)
|
2017-07-31 13:23:05 +00:00
|
|
|
|
|
|
|
response.languages.map { |l| { value: l.share.round(2), label: l.name, color: l.color, highlight: l.color } }
|
|
|
|
end
|
|
|
|
|
2017-07-28 12:16:26 +00:00
|
|
|
def raw_blame(revision, path)
|
|
|
|
request = Gitaly::RawBlameRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
2017-12-26 18:53:31 +00:00
|
|
|
revision: encode_binary(revision),
|
|
|
|
path: encode_binary(path)
|
2017-07-28 12:16:26 +00:00
|
|
|
)
|
|
|
|
|
2017-11-29 09:12:12 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :raw_blame, request, timeout: GitalyClient.medium_timeout)
|
2018-11-09 18:39:43 +00:00
|
|
|
response.reduce([]) { |memo, msg| memo << msg.data }.join
|
2017-07-28 12:16:26 +00:00
|
|
|
end
|
|
|
|
|
2017-07-25 21:33:06 +00:00
|
|
|
def find_commit(revision)
|
2019-06-23 05:51:52 +00:00
|
|
|
return call_find_commit(revision) unless Gitlab::SafeRequestStore.active?
|
|
|
|
|
|
|
|
# We don't use Gitlab::SafeRequestStore.fetch(key) { ... } directly
|
|
|
|
# because `revision` can be a branch name, so we can't use it as a key
|
|
|
|
# as it could point to another commit later on (happens a lot in
|
|
|
|
# tests).
|
|
|
|
key = {
|
|
|
|
storage: @gitaly_repo.storage_name,
|
|
|
|
relative_path: @gitaly_repo.relative_path,
|
|
|
|
commit_id: revision
|
|
|
|
}
|
|
|
|
return Gitlab::SafeRequestStore[key] if Gitlab::SafeRequestStore.exist?(key)
|
|
|
|
|
|
|
|
commit = call_find_commit(revision)
|
|
|
|
|
|
|
|
if GitalyClient.ref_name_caching_allowed?
|
2018-09-20 22:40:15 +00:00
|
|
|
Gitlab::SafeRequestStore[key] = commit
|
2019-06-23 05:51:52 +00:00
|
|
|
return commit
|
2018-02-06 15:32:34 +00:00
|
|
|
end
|
2019-06-23 05:51:52 +00:00
|
|
|
|
|
|
|
return unless commit
|
|
|
|
|
|
|
|
key[:commit_id] = commit.id
|
|
|
|
Gitlab::SafeRequestStore[key] = commit
|
2017-07-25 21:33:06 +00:00
|
|
|
end
|
|
|
|
|
2017-09-06 10:55:16 +00:00
|
|
|
def commit_stats(revision)
|
|
|
|
request = Gitaly::CommitStatsRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
2017-12-26 18:53:31 +00:00
|
|
|
revision: encode_binary(revision)
|
2017-09-06 10:55:16 +00:00
|
|
|
)
|
2017-11-29 09:12:12 +00:00
|
|
|
GitalyClient.call(@repository.storage, :commit_service, :commit_stats, request, timeout: GitalyClient.medium_timeout)
|
2017-09-06 10:55:16 +00:00
|
|
|
end
|
|
|
|
|
2017-09-11 08:17:49 +00:00
|
|
|
def find_commits(options)
|
|
|
|
request = Gitaly::FindCommitsRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
limit: options[:limit],
|
|
|
|
offset: options[:offset],
|
|
|
|
follow: options[:follow],
|
|
|
|
skip_merges: options[:skip_merges],
|
2018-03-01 16:50:07 +00:00
|
|
|
all: !!options[:all],
|
2019-09-19 21:06:29 +00:00
|
|
|
first_parent: !!options[:first_parent],
|
2020-06-26 21:08:51 +00:00
|
|
|
global_options: parse_global_options!(options),
|
2021-01-20 15:10:29 +00:00
|
|
|
disable_walk: true, # This option is deprecated. The 'walk' implementation is being removed.
|
|
|
|
trailers: options[:trailers]
|
2017-09-11 08:17:49 +00:00
|
|
|
)
|
|
|
|
request.after = GitalyClient.timestamp(options[:after]) if options[:after]
|
|
|
|
request.before = GitalyClient.timestamp(options[:before]) if options[:before]
|
2017-12-26 18:53:31 +00:00
|
|
|
request.revision = encode_binary(options[:ref]) if options[:ref]
|
2020-02-26 18:09:24 +00:00
|
|
|
request.author = encode_binary(options[:author]) if options[:author]
|
|
|
|
request.order = options[:order].upcase.sub('DEFAULT', 'NONE') if options[:order].present?
|
2017-09-11 08:17:49 +00:00
|
|
|
|
2017-12-26 18:53:31 +00:00
|
|
|
request.paths = encode_repeated(Array(options[:path])) if options[:path].present?
|
2017-09-11 08:17:49 +00:00
|
|
|
|
2020-07-01 00:09:02 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :find_commits, request, timeout: GitalyClient.medium_timeout)
|
|
|
|
consume_commits_response(response)
|
2017-09-11 08:17:49 +00:00
|
|
|
end
|
|
|
|
|
2017-11-28 09:23:38 +00:00
|
|
|
def filter_shas_with_signatures(shas)
|
|
|
|
request = Gitaly::FilterShasWithSignaturesRequest.new(repository: @gitaly_repo)
|
|
|
|
|
|
|
|
enum = Enumerator.new do |y|
|
|
|
|
shas.each_slice(20) do |revs|
|
2017-12-26 18:53:31 +00:00
|
|
|
request.shas = encode_repeated(revs)
|
2017-11-28 09:23:38 +00:00
|
|
|
|
|
|
|
y.yield request
|
|
|
|
|
|
|
|
request = Gitaly::FilterShasWithSignaturesRequest.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-01 00:09:02 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :filter_shas_with_signatures, enum, timeout: GitalyClient.fast_timeout)
|
|
|
|
response.flat_map do |msg|
|
|
|
|
msg.shas.map { |sha| EncodingHelper.encode!(sha) }
|
2017-11-28 09:23:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-28 16:56:00 +00:00
|
|
|
def get_commit_signatures(commit_ids)
|
|
|
|
request = Gitaly::GetCommitSignaturesRequest.new(repository: @gitaly_repo, commit_ids: commit_ids)
|
2018-07-05 16:05:24 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :get_commit_signatures, request, timeout: GitalyClient.fast_timeout)
|
2018-02-28 16:56:00 +00:00
|
|
|
|
2018-11-09 18:39:43 +00:00
|
|
|
signatures = Hash.new { |h, k| h[k] = [+''.b, +''.b] }
|
2018-02-28 16:56:00 +00:00
|
|
|
current_commit_id = nil
|
|
|
|
|
|
|
|
response.each do |message|
|
|
|
|
current_commit_id = message.commit_id if message.commit_id.present?
|
|
|
|
|
|
|
|
signatures[current_commit_id].first << message.signature
|
|
|
|
signatures[current_commit_id].last << message.signed_text
|
|
|
|
end
|
|
|
|
|
|
|
|
signatures
|
2018-06-27 12:29:03 +00:00
|
|
|
rescue GRPC::InvalidArgument => ex
|
|
|
|
raise ArgumentError, ex
|
2018-02-28 16:56:00 +00:00
|
|
|
end
|
|
|
|
|
2018-03-20 19:20:12 +00:00
|
|
|
def get_commit_messages(commit_ids)
|
|
|
|
request = Gitaly::GetCommitMessagesRequest.new(repository: @gitaly_repo, commit_ids: commit_ids)
|
2018-07-05 16:05:24 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :get_commit_messages, request, timeout: GitalyClient.fast_timeout)
|
2018-03-20 19:20:12 +00:00
|
|
|
|
2018-11-09 18:39:43 +00:00
|
|
|
messages = Hash.new { |h, k| h[k] = +''.b }
|
2018-03-20 19:20:12 +00:00
|
|
|
current_commit_id = nil
|
|
|
|
|
|
|
|
response.each do |rpc_message|
|
|
|
|
current_commit_id = rpc_message.commit_id if rpc_message.commit_id.present?
|
|
|
|
|
|
|
|
messages[current_commit_id] << rpc_message.message
|
|
|
|
end
|
|
|
|
|
|
|
|
messages
|
|
|
|
end
|
|
|
|
|
2020-06-23 18:09:28 +00:00
|
|
|
def list_commits_by_ref_name(refs)
|
|
|
|
request = Gitaly::ListCommitsByRefNameRequest
|
2020-06-30 12:08:57 +00:00
|
|
|
.new(repository: @gitaly_repo, ref_names: refs.map { |ref| encode_binary(ref) })
|
2020-06-23 18:09:28 +00:00
|
|
|
|
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :list_commits_by_ref_name, request, timeout: GitalyClient.medium_timeout)
|
|
|
|
|
|
|
|
commit_refs = response.flat_map do |message|
|
|
|
|
message.commit_refs.map do |commit_ref|
|
2020-06-30 12:08:57 +00:00
|
|
|
[encode_utf8(commit_ref.ref_name), Gitlab::Git::Commit.new(@repository, commit_ref.commit)]
|
2020-06-23 18:09:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Hash[commit_refs]
|
|
|
|
end
|
|
|
|
|
2017-05-05 14:55:12 +00:00
|
|
|
private
|
|
|
|
|
2020-06-26 21:08:51 +00:00
|
|
|
def parse_global_options!(options)
|
|
|
|
literal_pathspec = options.delete(:literal_pathspec)
|
|
|
|
Gitaly::GlobalOptions.new(literal_pathspecs: literal_pathspec)
|
|
|
|
end
|
|
|
|
|
2017-09-11 12:52:27 +00:00
|
|
|
def call_commit_diff(request_params, options = {})
|
|
|
|
request_params[:ignore_whitespace_change] = options.fetch(:ignore_whitespace_change, false)
|
|
|
|
request_params[:enforce_limits] = options.fetch(:limits, true)
|
2018-06-29 13:25:35 +00:00
|
|
|
request_params[:collapse_diffs] = !options.fetch(:expanded, true)
|
2018-09-06 20:56:06 +00:00
|
|
|
request_params.merge!(Gitlab::Git::DiffCollection.limits(options).to_h)
|
2017-09-11 12:52:27 +00:00
|
|
|
|
|
|
|
request = Gitaly::CommitDiffRequest.new(request_params)
|
2020-07-01 00:09:02 +00:00
|
|
|
response = GitalyClient.call(@repository.storage, :diff_service, :commit_diff, request, timeout: GitalyClient.medium_timeout)
|
|
|
|
GitalyClient::DiffStitcher.new(response)
|
2017-09-11 12:52:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def diff_from_parent_request_params(commit, options = {})
|
2018-04-12 03:05:07 +00:00
|
|
|
parent_id = commit.parent_ids.first || Gitlab::Git::EMPTY_TREE_ID
|
2017-05-05 14:55:12 +00:00
|
|
|
|
2017-09-11 12:52:27 +00:00
|
|
|
diff_between_commits_request_params(parent_id, commit.id, options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def diff_between_commits_request_params(from_id, to_id, options)
|
2017-05-05 14:55:12 +00:00
|
|
|
{
|
|
|
|
repository: @gitaly_repo,
|
2017-09-11 12:52:27 +00:00
|
|
|
left_commit_id: from_id,
|
|
|
|
right_commit_id: to_id,
|
2017-12-26 18:53:31 +00:00
|
|
|
paths: options.fetch(:paths, []).compact.map { |path| encode_binary(path) }
|
2017-05-05 14:55:12 +00:00
|
|
|
}
|
|
|
|
end
|
2017-06-23 21:52:51 +00:00
|
|
|
|
|
|
|
def consume_commits_response(response)
|
2017-07-18 08:06:49 +00:00
|
|
|
response.flat_map do |message|
|
|
|
|
message.commits.map do |gitaly_commit|
|
2017-07-25 20:48:17 +00:00
|
|
|
Gitlab::Git::Commit.new(@repository, gitaly_commit)
|
2017-07-18 08:06:49 +00:00
|
|
|
end
|
|
|
|
end
|
2017-06-23 21:52:51 +00:00
|
|
|
end
|
2017-12-26 18:53:31 +00:00
|
|
|
|
2018-07-04 14:02:01 +00:00
|
|
|
def encode_repeated(array)
|
|
|
|
Google::Protobuf::RepeatedField.new(:bytes, array.map { |s| encode_binary(s) } )
|
2017-12-26 18:53:31 +00:00
|
|
|
end
|
2018-02-06 15:32:34 +00:00
|
|
|
|
|
|
|
def call_find_commit(revision)
|
|
|
|
request = Gitaly::FindCommitRequest.new(
|
|
|
|
repository: @gitaly_repo,
|
|
|
|
revision: encode_binary(revision)
|
|
|
|
)
|
|
|
|
|
|
|
|
response = GitalyClient.call(@repository.storage, :commit_service, :find_commit, request, timeout: GitalyClient.medium_timeout)
|
|
|
|
|
|
|
|
response.commit
|
|
|
|
end
|
2017-02-24 15:53:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|