Class: Gitlab::GitalyClient::AnalysisService

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

Constant Summary

Constants included from EncodingHelper

EncodingHelper::BOM_UTF8, EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD, EncodingHelper::ESCAPED_CHARS, EncodingHelper::UNICODE_REPLACEMENT_CHARACTER

Instance Attribute Summary

Attributes included from WithFeatureFlagActors

#repository_actor

Instance Method Summary collapse

Methods included from WithFeatureFlagActors

#gitaly_client_call, #gitaly_feature_flag_actors, #group_actor, #project_actor, #user_actor

Methods included from EncodingHelper

#binary_io, #detect_binary?, #detect_encoding, #detect_libgit2_binary?, #encode!, #encode_binary, #encode_utf8, #encode_utf8_no_detect, #encode_utf8_with_escaping!, #encode_utf8_with_replacement_character, #force_encode_utf8, #strip_bom, #unquote_path

Constructor Details

#initialize(repository) ⇒ AnalysisService

Returns a new instance of AnalysisService.



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

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

  self.repository_actor = repository
end

Instance Method Details

#check_blobs_generated(base, head, changed_paths) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gitlab/gitaly_client/analysis_service.rb', line 17

def check_blobs_generated(base, head, changed_paths)
  request_enum = Enumerator.new do |y|
    changed_paths.each_slice(100).with_index do |paths_subset, i|
      blobs = paths_subset.filter_map do |changed_path|
        # Submodule changes should be ignored as the blob won't exist
        next if changed_path.submodule_change?

        # The Blob won't exist in the base if the file is newly added.
        # We can use the head to get the blob to handle both added or deleted files.
        prefix = changed_path.new_file? ? head : base
        revision = "#{prefix}:#{changed_path.path}"

        Gitaly::CheckBlobsGeneratedRequest::Blob.new(
          revision: encode_binary(revision),
          path: encode_binary(changed_path.path)
        )
      end

      next if blobs.blank?

      params = { blobs: blobs }
      # Repository is only needed for the first request
      params[:repository] = @gitaly_repo if i == 0

      y.yield Gitaly::CheckBlobsGeneratedRequest.new(**params)
    end
  end

  return [] if request_enum.count == 0

  response = gitaly_client_call(
    @repository.storage,
    :analysis_service,
    :check_blobs_generated,
    request_enum,
    timeout: GitalyClient.medium_timeout
  )

  result = []
  response.each do |msg|
    msg.blobs.each do |blob|
      path = blob.revision.split(":", 2).last
      result << { path: path, generated: blob.generated }
    end
  end

  result
end