Class: Gitlab::GitalyClient::BlobService

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

Constant Summary

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) ⇒ BlobService

Returns a new instance of BlobService.


8
9
10
# File 'lib/gitlab/gitaly_client/blob_service.rb', line 8

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

Instance Method Details

#batch_lfs_pointers(blob_ids) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gitlab/gitaly_client/blob_service.rb', line 22

def batch_lfs_pointers(blob_ids)
  return [] if blob_ids.empty?

  request = Gitaly::GetLFSPointersRequest.new(
    repository: @gitaly_repo,
    blob_ids: blob_ids
  )

  response = GitalyClient.call(@gitaly_repo.storage_name, :blob_service, :get_lfs_pointers, request, timeout: GitalyClient.medium_timeout)
  map_lfs_pointers(response)
end

#get_all_lfs_pointersObject


110
111
112
113
114
115
116
117
# File 'lib/gitlab/gitaly_client/blob_service.rb', line 110

def get_all_lfs_pointers
  request = Gitaly::GetAllLFSPointersRequest.new(
    repository: @gitaly_repo
  )

  response = GitalyClient.call(@gitaly_repo.storage_name, :blob_service, :get_all_lfs_pointers, request, timeout: GitalyClient.medium_timeout)
  map_lfs_pointers(response)
end

#get_blob(oid:, limit:) ⇒ Object


12
13
14
15
16
17
18
19
20
# File 'lib/gitlab/gitaly_client/blob_service.rb', line 12

def get_blob(oid:, limit:)
  request = Gitaly::GetBlobRequest.new(
    repository: @gitaly_repo,
    oid: oid,
    limit: limit
  )
  response = GitalyClient.call(@gitaly_repo.storage_name, :blob_service, :get_blob, request, timeout: GitalyClient.fast_timeout)
  consume_blob_response(response)
end

#get_blob_types(revision_paths, limit = -1)) ⇒ Object


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/gitlab/gitaly_client/blob_service.rb', line 57

def get_blob_types(revision_paths, limit = -1)
  return {} if revision_paths.empty?

  request_revision_paths = revision_paths.map do |rev, path|
    Gitaly::GetBlobsRequest::RevisionPath.new(revision: rev, path: encode_binary(path))
  end

  request = Gitaly::GetBlobsRequest.new(
    repository: @gitaly_repo,
    revision_paths: request_revision_paths,
    limit: limit
  )

  response = GitalyClient.call(
    @gitaly_repo.storage_name,
    :blob_service,
    :get_blobs,
    request,
    timeout: GitalyClient.fast_timeout
  )
  map_blob_types(response)
end

#get_blobs(revision_paths, limit = -1)) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gitlab/gitaly_client/blob_service.rb', line 34

def get_blobs(revision_paths, limit = -1)
  return [] if revision_paths.empty?

  request_revision_paths = revision_paths.map do |rev, path|
    Gitaly::GetBlobsRequest::RevisionPath.new(revision: rev, path: encode_binary(path))
  end

  request = Gitaly::GetBlobsRequest.new(
    repository: @gitaly_repo,
    revision_paths: request_revision_paths,
    limit: limit
  )

  response = GitalyClient.call(
    @gitaly_repo.storage_name,
    :blob_service,
    :get_blobs,
    request,
    timeout: GitalyClient.fast_timeout)

  GitalyClient::BlobsStitcher.new(response)
end

#get_new_lfs_pointers(revision, limit, not_in, dynamic_timeout = nil) ⇒ Object


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/gitlab/gitaly_client/blob_service.rb', line 80

def get_new_lfs_pointers(revision, limit, not_in, dynamic_timeout = nil)
  request = Gitaly::GetNewLFSPointersRequest.new(
    repository: @gitaly_repo,
    revision: encode_binary(revision),
    limit: limit || 0
  )

  if not_in.nil? || not_in == :all
    request.not_in_all = true
  else
    request.not_in_refs += not_in
  end

  timeout =
    if dynamic_timeout
      [dynamic_timeout, GitalyClient.medium_timeout].min
    else
      GitalyClient.medium_timeout
    end

  response = GitalyClient.call(
    @gitaly_repo.storage_name,
    :blob_service,
    :get_new_lfs_pointers,
    request,
    timeout: timeout
  )
  map_lfs_pointers(response)
end