Class: Gitlab::GitalyClient::CleanupService

Inherits:
Object
  • Object
show all
Includes:
EncodingHelper, WithFeatureFlagActors
Defined in:
lib/gitlab/gitaly_client/cleanup_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 collapse

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

‘repository’ is a Gitlab::Git::Repository



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

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

  self.repository_actor = repository
end

Instance Attribute Details

#gitaly_repoObject (readonly)

Returns the value of attribute gitaly_repo.



9
10
11
# File 'lib/gitlab/gitaly_client/cleanup_service.rb', line 9

def gitaly_repo
  @gitaly_repo
end

#repositoryObject (readonly)

Returns the value of attribute repository.



9
10
11
# File 'lib/gitlab/gitaly_client/cleanup_service.rb', line 9

def repository
  @repository
end

#storageObject (readonly)

Returns the value of attribute storage.



9
10
11
# File 'lib/gitlab/gitaly_client/cleanup_service.rb', line 9

def storage
  @storage
end

Instance Method Details

#apply_bfg_object_map_stream(io, &blk) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/gitaly_client/cleanup_service.rb', line 20

def apply_bfg_object_map_stream(io, &blk)
  response = gitaly_client_call(
    storage,
    :cleanup_service,
    :apply_bfg_object_map_stream,
    build_object_map_enum(io),
    timeout: GitalyClient.long_timeout
  )
  response.each(&blk)
end

#rewrite_history(blobs: [], redactions: []) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gitlab/gitaly_client/cleanup_service.rb', line 31

def rewrite_history(blobs: [], redactions: [])
  req_enum = Enumerator.new do |y|
    first_request = Gitaly::RewriteHistoryRequest.new(repository: @gitaly_repo)
    y.yield(first_request)

    blobs.each_slice(100) do |b|
      y.yield Gitaly::RewriteHistoryRequest.new(blobs: b)
    end

    redactions.map { |r| encode_binary(r) }.each_slice(100) do |r|
      y.yield Gitaly::RewriteHistoryRequest.new(redactions: r)
    end
  end

  gitaly_client_call(@repository.storage, :cleanup_service, :rewrite_history, req_enum,
    timeout: GitalyClient.long_timeout)
rescue GRPC::InvalidArgument => e
  raise ArgumentError, e.message
end