Bring back Rugged implementation of CommitIsAncestor
This brings back some of the changes in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20095. For users using Gitaly on top of NFS, accessing the Git data directly via Rugged is more performant than Gitaly. This merge request introduces the feature flag `rugged_commit_is_ancestor` to activate the Rugged path. Part of four Rugged changes identified in https://gitlab.com/gitlab-org/gitlab-ce/issues/57317.
This commit is contained in:
parent
db70f74dfd
commit
9d294467bd
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Bring back Rugged implementation of CommitIsAncestor
|
||||||
|
merge_request: 25702
|
||||||
|
author:
|
||||||
|
type: other
|
|
@ -11,7 +11,7 @@ module Gitlab
|
||||||
include Gitlab::Git::WrapsGitalyErrors
|
include Gitlab::Git::WrapsGitalyErrors
|
||||||
include Gitlab::EncodingHelper
|
include Gitlab::EncodingHelper
|
||||||
include Gitlab::Utils::StrongMemoize
|
include Gitlab::Utils::StrongMemoize
|
||||||
include Gitlab::Git::RuggedImpl::Repository
|
prepend Gitlab::Git::RuggedImpl::Repository
|
||||||
|
|
||||||
SEARCH_CONTEXT_LINES = 3
|
SEARCH_CONTEXT_LINES = 3
|
||||||
REV_LIST_COMMIT_LIMIT = 2_000
|
REV_LIST_COMMIT_LIMIT = 2_000
|
||||||
|
|
|
@ -10,7 +10,9 @@ module Gitlab
|
||||||
module Git
|
module Git
|
||||||
module RuggedImpl
|
module RuggedImpl
|
||||||
module Repository
|
module Repository
|
||||||
FEATURE_FLAGS = %i(rugged_find_commit).freeze
|
extend ::Gitlab::Utils::Override
|
||||||
|
|
||||||
|
FEATURE_FLAGS = %i(rugged_find_commit rugged_tree_entries rugged_tree_entry rugged_commit_is_ancestor).freeze
|
||||||
|
|
||||||
def alternate_object_directories
|
def alternate_object_directories
|
||||||
relative_object_directories.map { |d| File.join(path, d) }
|
relative_object_directories.map { |d| File.join(path, d) }
|
||||||
|
@ -41,6 +43,29 @@ module Gitlab
|
||||||
obj = rugged.rev_parse(revspec)
|
obj = rugged.rev_parse(revspec)
|
||||||
Ref.dereference_object(obj)
|
Ref.dereference_object(obj)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
override :ancestor?
|
||||||
|
def ancestor?(from, to)
|
||||||
|
if Feature.enabled?(:rugged_commit_is_ancestor)
|
||||||
|
rugged_is_ancestor?(from, to)
|
||||||
|
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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2237,7 +2237,7 @@ describe Repository do
|
||||||
rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", target.id)
|
rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", target.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#ancestor?' do
|
shared_examples '#ancestor?' do
|
||||||
let(:commit) { repository.commit }
|
let(:commit) { repository.commit }
|
||||||
let(:ancestor) { commit.parents.first }
|
let(:ancestor) { commit.parents.first }
|
||||||
|
|
||||||
|
@ -2261,6 +2261,20 @@ describe Repository do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#ancestor? with Gitaly enabled' do
|
||||||
|
it_behaves_like "#ancestor?"
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#ancestor? with Rugged enabled', :enable_rugged do
|
||||||
|
it 'calls out to the Rugged implementation' do
|
||||||
|
allow_any_instance_of(Rugged).to receive(:merge_base).with(repository.commit.id, Gitlab::Git::BLANK_SHA).and_call_original
|
||||||
|
|
||||||
|
repository.ancestor?(repository.commit.id, Gitlab::Git::BLANK_SHA)
|
||||||
|
end
|
||||||
|
|
||||||
|
it_behaves_like '#ancestor?'
|
||||||
|
end
|
||||||
|
|
||||||
describe '#archive_metadata' do
|
describe '#archive_metadata' do
|
||||||
let(:ref) { 'master' }
|
let(:ref) { 'master' }
|
||||||
let(:storage_path) { '/tmp' }
|
let(:storage_path) { '/tmp' }
|
||||||
|
|
Loading…
Reference in New Issue