Module: Gitlab::Git::RuggedImpl::Repository

Extended by:
Utils::Override
Includes:
UseRugged
Defined in:
lib/gitlab/git/rugged_impl/repository.rb

Constant Summary collapse

FEATURE_FLAGS =
%i(rugged_find_commit rugged_tree_entries rugged_tree_entry rugged_commit_is_ancestor rugged_commit_tree_entry rugged_list_commits_by_oid).freeze
ALLOWED_OBJECT_RELATIVE_DIRECTORIES_VARIABLES =
%w[
  GIT_OBJECT_DIRECTORY_RELATIVE
  GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE
].freeze

Instance Method Summary collapse

Methods included from Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods included from UseRugged

#execute_rugged_call, #rugged_enabled_through_feature_flag?, #rugged_feature_keys, #running_puma_with_multiple_threads?, #use_rugged?

Instance Method Details

#alternate_object_directoriesObject


18
19
20
# File 'lib/gitlab/git/rugged_impl/repository.rb', line 18

def alternate_object_directories
  relative_object_directories.map { |d| File.join(path, d) }
end

#ancestor?(from, to) ⇒ Boolean

Returns:

  • (Boolean)

49
50
51
52
53
54
55
# File 'lib/gitlab/git/rugged_impl/repository.rb', line 49

def ancestor?(from, to)
  if use_rugged?(self, :rugged_commit_is_ancestor)
    execute_rugged_call(:rugged_is_ancestor?, from, to)
  else
    super
  end
end

#cleanupObject


37
38
39
# File 'lib/gitlab/git/rugged_impl/repository.rb', line 37

def cleanup
  @rugged&.close
end

#lookup(oid_or_ref_name) ⇒ Object

Lookup for rugged object by oid or ref name


72
73
74
# File 'lib/gitlab/git/rugged_impl/repository.rb', line 72

def lookup(oid_or_ref_name)
  rev_parse_target(oid_or_ref_name)
end

#relative_object_directoriesObject


27
28
29
# File 'lib/gitlab/git/rugged_impl/repository.rb', line 27

def relative_object_directories
  Gitlab::Git::HookEnv.all(gl_repository).values_at(*ALLOWED_OBJECT_RELATIVE_DIRECTORIES_VARIABLES).flatten.compact
end

#rev_parse_target(revspec) ⇒ Object

Return the object that revspec points to. If revspec is an annotated tag, then return the tag's target instead.


43
44
45
46
# File 'lib/gitlab/git/rugged_impl/repository.rb', line 43

def rev_parse_target(revspec)
  obj = rugged.rev_parse(revspec)
  Ref.dereference_object(obj)
end

#ruggedObject


31
32
33
34
35
# File 'lib/gitlab/git/rugged_impl/repository.rb', line 31

def rugged
  @rugged ||= ::Rugged::Repository.new(path, alternates: alternate_object_directories)
rescue ::Rugged::RepositoryError, ::Rugged::OSError
  raise ::Gitlab::Git::Repository::NoRepository.new('no repository for such path')
end

#rugged_is_ancestor?(ancestor_id, descendant_id) ⇒ Boolean

Returns:

  • (Boolean)

57
58
59
60
61
62
63
# File 'lib/gitlab/git/rugged_impl/repository.rb', line 57

def rugged_is_ancestor?(ancestor_id, descendant_id)
  return false if ancestor_id.nil? || descendant_id.nil?

  rugged_merge_base(ancestor_id, descendant_id) == ancestor_id
rescue Rugged::OdbError
  false
end

#rugged_merge_base(from, to) ⇒ Object


65
66
67
68
69
# File 'lib/gitlab/git/rugged_impl/repository.rb', line 65

def rugged_merge_base(from, to)
  rugged.merge_base(from, to)
rescue Rugged::ReferenceError
  nil
end