Class: Gitlab::GitalyClient::RefService
- Inherits:
-
Object
- Object
- Gitlab::GitalyClient::RefService
show all
- Includes:
- EncodingHelper
- Defined in:
- lib/gitlab/gitaly_client/ref_service.rb
Constant Summary
EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD
Instance Method Summary
collapse
#binary_io, #detect_binary?, #detect_libgit2_binary?, #encode!, #encode_binary, #encode_utf8
Constructor Details
#initialize(repository) ⇒ RefService
'repository' is a Gitlab::Git::Repository
9
10
11
12
13
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 9
def initialize(repository)
@repository = repository
@gitaly_repo = repository.gitaly_repository
@storage = repository.storage
end
|
Instance Method Details
#branch_names ⇒ Object
43
44
45
46
47
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 43
def branch_names
request = Gitaly::FindAllBranchNamesRequest.new(repository: @gitaly_repo)
response = GitalyClient.call(@storage, :ref_service, :find_all_branch_names, request, timeout: GitalyClient.fast_timeout)
consume_refs_response(response) { |name| Gitlab::Git.branch_name(name) }
end
|
#branch_names_contains_sha(sha, limit: 0) ⇒ Object
Limit: 0 implies no limit, thus all tag names will be returned
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 173
def branch_names_contains_sha(sha, limit: 0)
request = Gitaly::ListBranchNamesContainingCommitRequest.new(
repository: @gitaly_repo,
commit_id: sha,
limit: limit
)
response = GitalyClient.call(@storage, :ref_service, :list_branch_names_containing_commit, request, timeout: GitalyClient.medium_timeout)
consume_ref_contains_sha_response(response, :branch_names)
end
|
#branches ⇒ Object
15
16
17
18
19
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 15
def branches
request = Gitaly::FindAllBranchesRequest.new(repository: @gitaly_repo)
response = GitalyClient.call(@storage, :ref_service, :find_all_branches, request, timeout: GitalyClient.fast_timeout)
consume_find_all_branches_response(response)
end
|
#count_branch_names ⇒ Object
109
110
111
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 109
def count_branch_names
branch_names.count
end
|
#count_tag_names ⇒ Object
105
106
107
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 105
def count_tag_names
tag_names.count
end
|
#default_branch_name ⇒ Object
37
38
39
40
41
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 37
def default_branch_name
request = Gitaly::FindDefaultBranchNameRequest.new(repository: @gitaly_repo)
response = GitalyClient.call(@storage, :ref_service, :find_default_branch_name, request, timeout: GitalyClient.fast_timeout)
Gitlab::Git.branch_name(response.name)
end
|
#delete_refs(refs: [], except_with_prefixes: []) ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 148
def delete_refs(refs: [], except_with_prefixes: [])
request = Gitaly::DeleteRefsRequest.new(
repository: @gitaly_repo,
refs: refs.map { |r| encode_binary(r) },
except_with_prefix: except_with_prefixes.map { |r| encode_binary(r) }
)
response = GitalyClient.call(@repository.storage, :ref_service, :delete_refs, request, timeout: GitalyClient.medium_timeout)
raise Gitlab::Git::Repository::GitError, response.git_error if response.git_error.present?
end
|
#find_branch(branch_name) ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 134
def find_branch(branch_name)
request = Gitaly::FindBranchRequest.new(
repository: @gitaly_repo,
name: encode_binary(branch_name)
)
response = GitalyClient.call(@repository.storage, :ref_service, :find_branch, request, timeout: GitalyClient.medium_timeout)
branch = response.branch
return unless branch
target_commit = Gitlab::Git::Commit.decorate(@repository, branch.target_commit)
Gitlab::Git::Branch.new(@repository, encode!(branch.name.dup), branch.target_commit.id, target_commit)
end
|
#find_ref_name(commit_id, ref_prefix) ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 55
def find_ref_name(commit_id, ref_prefix)
request = Gitaly::FindRefNameRequest.new(
repository: @gitaly_repo,
commit_id: commit_id,
prefix: ref_prefix
)
response = GitalyClient.call(@storage, :ref_service, :find_ref_name, request, timeout: GitalyClient.medium_timeout)
encode!(response.name.dup)
end
|
#get_tag_messages(tag_ids) ⇒ Object
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 184
def get_tag_messages(tag_ids)
request = Gitaly::GetTagMessagesRequest.new(repository: @gitaly_repo, tag_ids: tag_ids)
messages = Hash.new { |h, k| h[k] = +''.b }
current_tag_id = nil
response = GitalyClient.call(@storage, :ref_service, :get_tag_messages, request, timeout: GitalyClient.fast_timeout)
response.each do |rpc_message|
current_tag_id = rpc_message.tag_id if rpc_message.tag_id.present?
messages[current_tag_id] << rpc_message.message
end
messages
end
|
#list_new_blobs(newrev, limit = 0, dynamic_timeout: nil) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 83
def list_new_blobs(newrev, limit = 0, dynamic_timeout: nil)
request = Gitaly::ListNewBlobsRequest.new(
repository: @gitaly_repo,
commit_id: newrev,
limit: limit
)
timeout =
if dynamic_timeout
[dynamic_timeout, GitalyClient.medium_timeout].min
else
GitalyClient.medium_timeout
end
response = GitalyClient.call(@storage, :ref_service, :list_new_blobs, request, timeout: timeout)
response.flat_map do |msg|
msg.new_blob_objects
end
end
|
#list_new_commits(newrev) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 65
def list_new_commits(newrev)
request = Gitaly::ListNewCommitsRequest.new(
repository: @gitaly_repo,
commit_id: newrev
)
commits = []
response = GitalyClient.call(@storage, :ref_service, :list_new_commits, request, timeout: GitalyClient.medium_timeout)
response.each do |msg|
msg.commits.each do |c|
commits << Gitlab::Git::Commit.new(@repository, c)
end
end
commits
end
|
#local_branches(sort_by: nil, pagination_params: nil) ⇒ Object
113
114
115
116
117
118
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 113
def local_branches(sort_by: nil, pagination_params: nil)
request = Gitaly::FindLocalBranchesRequest.new(repository: @gitaly_repo, pagination_params: )
request.sort_by = sort_by_param(sort_by) if sort_by
response = GitalyClient.call(@storage, :ref_service, :find_local_branches, request, timeout: GitalyClient.fast_timeout)
consume_find_local_branches_response(response)
end
|
#merged_branches(branch_names = []) ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 27
def merged_branches(branch_names = [])
request = Gitaly::FindAllBranchesRequest.new(
repository: @gitaly_repo,
merged_only: true,
merged_branches: branch_names.map { |s| encode_binary(s) }
)
response = GitalyClient.call(@storage, :ref_service, :find_all_branches, request, timeout: GitalyClient.fast_timeout)
consume_find_all_branches_response(response)
end
|
#pack_refs ⇒ Object
199
200
201
202
203
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 199
def pack_refs
request = Gitaly::PackRefsRequest.new(repository: @gitaly_repo)
GitalyClient.call(@storage, :ref_service, :pack_refs, request, timeout: GitalyClient.long_timeout)
end
|
#ref_exists?(ref_name) ⇒ Boolean
126
127
128
129
130
131
132
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 126
def ref_exists?(ref_name)
request = Gitaly::RefExistsRequest.new(repository: @gitaly_repo, ref: encode_binary(ref_name))
response = GitalyClient.call(@storage, :ref_service, :ref_exists, request, timeout: GitalyClient.fast_timeout)
response.value
rescue GRPC::InvalidArgument => e
raise ArgumentError, e.message
end
|
#remote_branches(remote_name) ⇒ Object
21
22
23
24
25
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 21
def remote_branches(remote_name)
request = Gitaly::FindAllRemoteBranchesRequest.new(repository: @gitaly_repo, remote_name: remote_name)
response = GitalyClient.call(@storage, :ref_service, :find_all_remote_branches, request, timeout: GitalyClient.medium_timeout)
consume_find_all_remote_branches_response(remote_name, response)
end
|
#tag_names ⇒ Object
49
50
51
52
53
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 49
def tag_names
request = Gitaly::FindAllTagNamesRequest.new(repository: @gitaly_repo)
response = GitalyClient.call(@storage, :ref_service, :find_all_tag_names, request, timeout: GitalyClient.fast_timeout)
consume_refs_response(response) { |name| Gitlab::Git.tag_name(name) }
end
|
#tag_names_contains_sha(sha, limit: 0) ⇒ Object
Limit: 0 implies no limit, thus all tag names will be returned
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 161
def tag_names_contains_sha(sha, limit: 0)
request = Gitaly::ListTagNamesContainingCommitRequest.new(
repository: @gitaly_repo,
commit_id: sha,
limit: limit
)
response = GitalyClient.call(@storage, :ref_service, :list_tag_names_containing_commit, request, timeout: GitalyClient.medium_timeout)
consume_ref_contains_sha_response(response, :tag_names)
end
|
120
121
122
123
124
|
# File 'lib/gitlab/gitaly_client/ref_service.rb', line 120
def tags
request = Gitaly::FindAllTagsRequest.new(repository: @gitaly_repo)
response = GitalyClient.call(@storage, :ref_service, :find_all_tags, request, timeout: GitalyClient.medium_timeout)
consume_tags_response(response)
end
|