Class: Gitlab::Git::KeepAround

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/git/keep_around.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository) ⇒ KeepAround

Returns a new instance of KeepAround.


17
18
19
# File 'lib/gitlab/git/keep_around.rb', line 17

def initialize(repository)
  @repository = repository
end

Class Method Details

.execute(repository, shas) ⇒ Object


13
14
15
# File 'lib/gitlab/git/keep_around.rb', line 13

def self.execute(repository, shas)
  new(repository).execute(shas)
end

Instance Method Details

#execute(shas) ⇒ Object


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

def execute(shas)
  shas.each do |sha|
    next unless sha.present? && commit_by(oid: sha)

    next if kept_around?(sha)

    # This will still fail if the file is corrupted (e.g. 0 bytes)
    raw_repository.write_ref(keep_around_ref_name(sha), sha)
  rescue Gitlab::Git::CommandError => ex
    Gitlab::AppLogger.error "Unable to create keep-around reference for repository #{disk_path}: #{ex}"
  end
end

#kept_around?(sha) ⇒ Boolean

Returns:

  • (Boolean)

34
35
36
# File 'lib/gitlab/git/keep_around.rb', line 34

def kept_around?(sha)
  ref_exists?(keep_around_ref_name(sha))
end