Class: Gitlab::Git::Branch

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

Constant Summary collapse

STALE_BRANCH_THRESHOLD =
3.months

Constants included from EncodingHelper

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

Instance Attribute Summary

Attributes inherited from Ref

#dereferenced_target, #name, #target

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Ref

extract_branch_name, #initialize

Methods included from RuggedImpl::Ref

dereference_object

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, #strip_bom, #unquote_path

Constructor Details

This class inherits a constructor from Gitlab::Git::Ref

Class Method Details

.find(repo, branch_name) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/gitlab/git/branch.rb', line 8

def self.find(repo, branch_name)
  if branch_name.is_a?(Gitlab::Git::Branch)
    branch_name
  else
    repo.find_branch(branch_name)
  end
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/gitlab/git/branch.rb', line 16

def active?
  self.dereferenced_target.committed_date >= STALE_BRANCH_THRESHOLD.ago
end

#cache_keyObject



28
29
30
# File 'lib/gitlab/git/branch.rb', line 28

def cache_key
  "branch:" + Digest::SHA1.hexdigest([name, target, dereferenced_target&.sha].join(':'))
end

#stale?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/gitlab/git/branch.rb', line 20

def stale?
  !active?
end

#stateObject



24
25
26
# File 'lib/gitlab/git/branch.rb', line 24

def state
  active? ? :active : :stale
end