Class: Gitlab::GitalyClient::RepositoryService

Inherits:
Object
  • Object
show all
Includes:
EncodingHelper
Defined in:
lib/gitlab/gitaly_client/repository_service.rb

Constant Summary collapse

MAX_MSG_SIZE =
128.kilobytes

Constants included from EncodingHelper

EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD

Instance Method Summary collapse

Methods included from EncodingHelper

#binary_io, #detect_binary?, #detect_libgit2_binary?, #encode!, #encode_binary, #encode_utf8

Constructor Details

#initialize(repository) ⇒ RepositoryService

Returns a new instance of RepositoryService.


10
11
12
13
14
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 10

def initialize(repository)
  @repository = repository
  @gitaly_repo = repository.gitaly_repository
  @storage = repository.storage
end

Instance Method Details

#apply_gitattributes(revision) ⇒ Object


57
58
59
60
61
62
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 57

def apply_gitattributes(revision)
  request = Gitaly::ApplyGitattributesRequest.new(repository: @gitaly_repo, revision: encode_binary(revision))
  GitalyClient.call(@storage, :repository_service, :apply_gitattributes, request, timeout: GitalyClient.fast_timeout)
rescue GRPC::InvalidArgument => ex
  raise Gitlab::Git::Repository::InvalidRef, ex
end

#backup_custom_hooks(save_path) ⇒ Object


219
220
221
222
223
224
225
226
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 219

def backup_custom_hooks(save_path)
  gitaly_fetch_stream_to_file(
    save_path,
    :backup_custom_hooks,
    Gitaly::BackupCustomHooksRequest,
    GitalyClient.default_timeout
  )
end

#calculate_checksumObject


316
317
318
319
320
321
322
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 316

def calculate_checksum
  request  = Gitaly::CalculateChecksumRequest.new(repository: @gitaly_repo)
  response = GitalyClient.call(@storage, :repository_service, :calculate_checksum, request, timeout: GitalyClient.fast_timeout)
  response.checksum.presence
rescue GRPC::DataLoss => e
  raise Gitlab::Git::Repository::InvalidRepository.new(e)
end

#cleanupObject


24
25
26
27
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 24

def cleanup
  request = Gitaly::CleanupRequest.new(repository: @gitaly_repo)
  GitalyClient.call(@storage, :repository_service, :cleanup, request, timeout: GitalyClient.fast_timeout)
end

#create_bundle(save_path) ⇒ Object


210
211
212
213
214
215
216
217
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 210

def create_bundle(save_path)
  gitaly_fetch_stream_to_file(
    save_path,
    :create_bundle,
    Gitaly::CreateBundleRequest,
    GitalyClient.long_timeout
  )
end

#create_from_bundle(bundle_path) ⇒ Object


228
229
230
231
232
233
234
235
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 228

def create_from_bundle(bundle_path)
  gitaly_repo_stream_request(
    bundle_path,
    :create_repository_from_bundle,
    Gitaly::CreateRepositoryFromBundleRequest,
    GitalyClient.long_timeout
  )
end

#create_from_snapshot(http_url, http_auth) ⇒ Object


246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 246

def create_from_snapshot(http_url, http_auth)
  request = Gitaly::CreateRepositoryFromSnapshotRequest.new(
    repository: @gitaly_repo,
    http_url: http_url,
    http_auth: http_auth
  )

  GitalyClient.call(
    @storage,
    :repository_service,
    :create_repository_from_snapshot,
    request,
    timeout: GitalyClient.long_timeout
  )
end

#create_repositoryObject


92
93
94
95
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 92

def create_repository
  request = Gitaly::CreateRepositoryRequest.new(repository: @gitaly_repo)
  GitalyClient.call(@storage, :repository_service, :create_repository, request, timeout: GitalyClient.fast_timeout)
end

#delete_config(keys) ⇒ Object


292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 292

def delete_config(keys)
  return if keys.empty?

  request = Gitaly::DeleteConfigRequest.new(repository: @gitaly_repo, keys: keys)

  GitalyClient.call(
    @storage,
    :repository_service,
    :delete_config,
    request,
    timeout: GitalyClient.fast_timeout
  )

  nil
end

#disconnect_alternatesObject


341
342
343
344
345
346
347
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 341

def disconnect_alternates
  request = Gitaly::DisconnectGitAlternatesRequest.new(
    repository: @gitaly_repo
  )

  GitalyClient.call(@storage, :object_pool_service, :disconnect_git_alternates, request, timeout: GitalyClient.long_timeout)
end

#exists?Boolean

Returns:

  • (Boolean)

16
17
18
19
20
21
22
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 16

def exists?
  request = Gitaly::RepositoryExistsRequest.new(repository: @gitaly_repo)

  response = GitalyClient.call(@storage, :repository_service, :repository_exists, request, timeout: GitalyClient.fast_timeout)

  response.exists
end

#fetch_remote(remote, ssh_auth:, forced:, no_tags:, timeout:, prune: true) ⇒ Object


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 73

def fetch_remote(remote, ssh_auth:, forced:, no_tags:, timeout:, prune: true)
  request = Gitaly::FetchRemoteRequest.new(
    repository: @gitaly_repo, remote: remote, force: forced,
    no_tags: no_tags, timeout: timeout, no_prune: !prune
  )

  if ssh_auth&.ssh_mirror_url?
    if ssh_auth.ssh_key_auth? && ssh_auth.ssh_private_key.present?
      request.ssh_key = ssh_auth.ssh_private_key
    end

    if ssh_auth.ssh_known_hosts.present?
      request.known_hosts = ssh_auth.ssh_known_hosts
    end
  end

  GitalyClient.call(@storage, :repository_service, :fetch_remote, request, timeout: GitalyClient.long_timeout)
end

#fetch_source_branch(source_repository, source_branch, local_ref) ⇒ Object


179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 179

def fetch_source_branch(source_repository, source_branch, local_ref)
  request = Gitaly::FetchSourceBranchRequest.new(
    repository: @gitaly_repo,
    source_repository: source_repository.gitaly_repository,
    source_branch: source_branch.b,
    target_ref: local_ref.b
  )

  response = GitalyClient.call(
    @storage,
    :repository_service,
    :fetch_source_branch,
    request,
    timeout: GitalyClient.long_timeout,
    remote_storage: source_repository.storage
  )

  response.result
end

#find_merge_base(*revisions) ⇒ Object


104
105
106
107
108
109
110
111
112
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 104

def find_merge_base(*revisions)
  request = Gitaly::FindMergeBaseRequest.new(
    repository: @gitaly_repo,
    revisions: revisions.map { |r| encode_binary(r) }
  )

  response = GitalyClient.call(@storage, :repository_service, :find_merge_base, request, timeout: GitalyClient.fast_timeout)
  response.base.presence
end

#fork_repository(source_repository) ⇒ Object


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 114

def fork_repository(source_repository)
  request = Gitaly::CreateForkRequest.new(
    repository: @gitaly_repo,
    source_repository: source_repository.gitaly_repository
  )

  GitalyClient.call(
    @storage,
    :repository_service,
    :create_fork,
    request,
    remote_storage: source_repository.storage,
    timeout: GitalyClient.long_timeout
  )
end

#fsckObject


199
200
201
202
203
204
205
206
207
208
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 199

def fsck
  request = Gitaly::FsckRequest.new(repository: @gitaly_repo)
  response = GitalyClient.call(@storage, :repository_service, :fsck, request, timeout: GitalyClient.long_timeout)

  if response.error.empty?
    ["", 0]
  else
    [response.error.b, 1]
  end
end

#garbage_collect(create_bitmap) ⇒ Object


29
30
31
32
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 29

def garbage_collect(create_bitmap)
  request = Gitaly::GarbageCollectRequest.new(repository: @gitaly_repo, create_bitmap: create_bitmap)
  GitalyClient.call(@storage, :repository_service, :garbage_collect, request, timeout: GitalyClient.long_timeout)
end

#get_object_directory_sizeObject


50
51
52
53
54
55
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 50

def get_object_directory_size
  request = Gitaly::GetObjectDirectorySizeRequest.new(repository: @gitaly_repo)
  response = GitalyClient.call(@storage, :repository_service, :get_object_directory_size, request, timeout: GitalyClient.medium_timeout)

  response.size
end

#has_local_branches?Boolean

Returns:

  • (Boolean)

97
98
99
100
101
102
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 97

def has_local_branches?
  request = Gitaly::HasLocalBranchesRequest.new(repository: @gitaly_repo)
  response = GitalyClient.call(@storage, :repository_service, :has_local_branches, request, timeout: GitalyClient.fast_timeout)

  response.value
end

#import_repository(source) ⇒ Object


130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 130

def import_repository(source)
  request = Gitaly::CreateRepositoryFromURLRequest.new(
    repository: @gitaly_repo,
    url: source
  )

  GitalyClient.call(
    @storage,
    :repository_service,
    :create_repository_from_url,
    request,
    timeout: GitalyClient.long_timeout
  )
end

#info_attributesObject


64
65
66
67
68
69
70
71
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 64

def info_attributes
  request = Gitaly::GetInfoAttributesRequest.new(repository: @gitaly_repo)

  response = GitalyClient.call(@storage, :repository_service, :get_info_attributes, request, timeout: GitalyClient.fast_timeout)
  response.each_with_object([]) do |message, attributes|
    attributes << message.attributes
  end.join
end

#license_short_nameObject


308
309
310
311
312
313
314
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 308

def license_short_name
  request = Gitaly::FindLicenseRequest.new(repository: @gitaly_repo)

  response = GitalyClient.call(@storage, :repository_service, :find_license, request, timeout: GitalyClient.fast_timeout)

  response.license_short_name.presence
end

#raw_changes_between(from, to) ⇒ Object


324
325
326
327
328
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 324

def raw_changes_between(from, to)
  request = Gitaly::GetRawChangesRequest.new(repository: @gitaly_repo, from_revision: from, to_revision: to)

  GitalyClient.call(@storage, :repository_service, :get_raw_changes, request, timeout: GitalyClient.fast_timeout)
end

#rebase_in_progress?(rebase_id) ⇒ Boolean

Returns:

  • (Boolean)

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 145

def rebase_in_progress?(rebase_id)
  request = Gitaly::IsRebaseInProgressRequest.new(
    repository: @gitaly_repo,
    rebase_id: rebase_id.to_s
  )

  response = GitalyClient.call(
    @storage,
    :repository_service,
    :is_rebase_in_progress,
    request,
    timeout: GitalyClient.fast_timeout
  )

  response.in_progress
end

#removeObject


355
356
357
358
359
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 355

def remove
  request = Gitaly::RemoveRepositoryRequest.new(repository: @gitaly_repo)

  GitalyClient.call(@storage, :repository_service, :remove_repository, request, timeout: GitalyClient.long_timeout)
end

#rename(relative_path) ⇒ Object


349
350
351
352
353
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 349

def rename(relative_path)
  request = Gitaly::RenameRepositoryRequest.new(repository: @gitaly_repo, relative_path: relative_path)

  GitalyClient.call(@storage, :repository_service, :rename_repository, request, timeout: GitalyClient.fast_timeout)
end

#repack_full(create_bitmap) ⇒ Object


34
35
36
37
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 34

def repack_full(create_bitmap)
  request = Gitaly::RepackFullRequest.new(repository: @gitaly_repo, create_bitmap: create_bitmap)
  GitalyClient.call(@storage, :repository_service, :repack_full, request, timeout: GitalyClient.long_timeout)
end

#repack_incrementalObject


39
40
41
42
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 39

def repack_incremental
  request = Gitaly::RepackIncrementalRequest.new(repository: @gitaly_repo)
  GitalyClient.call(@storage, :repository_service, :repack_incremental, request, timeout: GitalyClient.long_timeout)
end

#replicate(source_repository) ⇒ Object


361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 361

def replicate(source_repository)
  request = Gitaly::ReplicateRepositoryRequest.new(
    repository: @gitaly_repo,
    source: source_repository.gitaly_repository
  )

  GitalyClient.call(
    @storage,
    :repository_service,
    :replicate_repository,
    request,
    remote_storage: source_repository.storage,
    timeout: GitalyClient.long_timeout
  )
end

#repository_sizeObject


44
45
46
47
48
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 44

def repository_size
  request = Gitaly::RepositorySizeRequest.new(repository: @gitaly_repo)
  response = GitalyClient.call(@storage, :repository_service, :repository_size, request, timeout: GitalyClient.medium_timeout)
  response.size
end

#restore_custom_hooks(custom_hooks_path) ⇒ Object


237
238
239
240
241
242
243
244
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 237

def restore_custom_hooks(custom_hooks_path)
  gitaly_repo_stream_request(
    custom_hooks_path,
    :restore_custom_hooks,
    Gitaly::RestoreCustomHooksRequest,
    GitalyClient.default_timeout
  )
end

#search_files_by_content(ref, query, options = {}) ⇒ Object


335
336
337
338
339
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 335

def search_files_by_content(ref, query, options = {})
  request = Gitaly::SearchFilesByContentRequest.new(repository: @gitaly_repo, ref: ref, query: query)
  response = GitalyClient.call(@storage, :repository_service, :search_files_by_content, request, timeout: GitalyClient.default_timeout)
  search_results_from_response(response, options)
end

#search_files_by_name(ref, query) ⇒ Object


330
331
332
333
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 330

def search_files_by_name(ref, query)
  request = Gitaly::SearchFilesByNameRequest.new(repository: @gitaly_repo, ref: ref, query: query)
  GitalyClient.call(@storage, :repository_service, :search_files_by_name, request, timeout: GitalyClient.fast_timeout).flat_map(&:files)
end

#set_config(entries) ⇒ Object


273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 273

def set_config(entries)
  return if entries.empty?

  request = Gitaly::SetConfigRequest.new(repository: @gitaly_repo)
  entries.each do |key, value|
    request.entries << build_set_config_entry(key, value)
  end

  GitalyClient.call(
    @storage,
    :repository_service,
    :set_config,
    request,
    timeout: GitalyClient.fast_timeout
  )

  nil
end

#squash_in_progress?(squash_id) ⇒ Boolean

Returns:

  • (Boolean)

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 162

def squash_in_progress?(squash_id)
  request = Gitaly::IsSquashInProgressRequest.new(
    repository: @gitaly_repo,
    squash_id: squash_id.to_s
  )

  response = GitalyClient.call(
    @storage,
    :repository_service,
    :is_squash_in_progress,
    request,
    timeout: GitalyClient.fast_timeout
  )

  response.in_progress
end

#write_ref(ref_path, ref, old_ref) ⇒ Object


262
263
264
265
266
267
268
269
270
271
# File 'lib/gitlab/gitaly_client/repository_service.rb', line 262

def write_ref(ref_path, ref, old_ref)
  request = Gitaly::WriteRefRequest.new(
    repository: @gitaly_repo,
    ref: ref_path.b,
    revision: ref.b
  )
  request.old_revision = old_ref.b unless old_ref.nil?

  GitalyClient.call(@storage, :repository_service, :write_ref, request, timeout: GitalyClient.fast_timeout)
end