2019-02-21 16:07:26 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# NOTE: This code is legacy. Do not add/modify code here unless you have
|
|
|
|
# discussed with the Gitaly team. See
|
|
|
|
# https://docs.gitlab.com/ee/development/gitaly.html#legacy-rugged-code
|
|
|
|
# for more details.
|
|
|
|
|
|
|
|
# rubocop:disable Gitlab/ModuleWithInstanceVariables
|
|
|
|
module Gitlab
|
|
|
|
module Git
|
|
|
|
module RuggedImpl
|
|
|
|
module Repository
|
2019-03-01 17:21:16 -05:00
|
|
|
extend ::Gitlab::Utils::Override
|
2019-06-14 21:22:26 -04:00
|
|
|
include Gitlab::Git::RuggedImpl::UseRugged
|
2019-03-01 17:21:16 -05:00
|
|
|
|
2019-04-16 17:40:52 -04:00
|
|
|
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
|
2019-02-21 16:07:26 -05:00
|
|
|
|
|
|
|
def alternate_object_directories
|
|
|
|
relative_object_directories.map { |d| File.join(path, d) }
|
|
|
|
end
|
|
|
|
|
|
|
|
ALLOWED_OBJECT_RELATIVE_DIRECTORIES_VARIABLES = %w[
|
|
|
|
GIT_OBJECT_DIRECTORY_RELATIVE
|
|
|
|
GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE
|
|
|
|
].freeze
|
|
|
|
|
|
|
|
def relative_object_directories
|
|
|
|
Gitlab::Git::HookEnv.all(gl_repository).values_at(*ALLOWED_OBJECT_RELATIVE_DIRECTORIES_VARIABLES).flatten.compact
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def cleanup
|
|
|
|
@rugged&.close
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return the object that +revspec+ points to. If +revspec+ is an
|
|
|
|
# annotated tag, then return the tag's target instead.
|
|
|
|
def rev_parse_target(revspec)
|
|
|
|
obj = rugged.rev_parse(revspec)
|
|
|
|
Ref.dereference_object(obj)
|
|
|
|
end
|
2019-03-01 17:21:16 -05:00
|
|
|
|
|
|
|
override :ancestor?
|
|
|
|
def ancestor?(from, to)
|
2019-06-14 21:22:26 -04:00
|
|
|
if use_rugged?(self, :rugged_commit_is_ancestor)
|
2019-07-10 17:36:49 -04:00
|
|
|
wrap_rugged_call { rugged_is_ancestor?(from, to) }
|
2019-03-01 17:21:16 -05:00
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def rugged_merge_base(from, to)
|
|
|
|
rugged.merge_base(from, to)
|
|
|
|
rescue Rugged::ReferenceError
|
|
|
|
nil
|
|
|
|
end
|
2019-03-07 07:29:51 -05:00
|
|
|
|
|
|
|
# Lookup for rugged object by oid or ref name
|
|
|
|
def lookup(oid_or_ref_name)
|
|
|
|
rugged.rev_parse(oid_or_ref_name)
|
|
|
|
end
|
2019-02-21 16:07:26 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# rubocop:enable Gitlab/ModuleWithInstanceVariables
|