Commit 1ea0ce82 authored by Kim "BKC" Carlbäcker's avatar Kim "BKC" Carlbäcker

Make GitLab use Gitaly for commit_is_ancestor

- Migration in Repository#is_ancestor?
parent 3e1fb2a5
......@@ -981,7 +981,13 @@ class Repository
end
def is_ancestor?(ancestor_id, descendant_id)
merge_base(ancestor_id, descendant_id) == ancestor_id
Gitlab::GitalyClient.migrate(:is_ancestor) do |is_enabled|
if is_enabled
raw_repository.is_ancestor?(ancestor_id, descendant_id)
else
merge_base_commit(ancestor_id, descendant_id) == ancestor_id
end
end
end
def empty_repo?
......
---
title: Use Gitaly for Repository#is_ancestor
merge_request: 9864
author:
......@@ -406,6 +406,11 @@ module Gitlab
rugged.merge_base(from, to)
end
# Returns true is +from+ is direct ancestor to +to+, otherwise false
def is_ancestor?(from, to)
Gitlab::GitalyClient::Commit.is_ancestor(self, from, to)
end
# Return an array of Diff objects that represent the diff
# between +from+ and +to+. See Diff::filter_diff_options for the allowed
# diff options. The +options+ hash can also include :break_rewrites to
......
......@@ -21,6 +21,20 @@ module Gitlab
Gitlab::Git::DiffCollection.new(stub.commit_diff(request), options)
end
def is_ancestor(repository, ancestor_id, child_id)
project = Project.find_by_path(repository.path)
channel = GitalyClient.get_channel(project.repository_storage)
stub = Gitaly::Commit::Stub.new(nil, nil, channel_override: channel)
repo = Gitaly::Repository.new(path: repository.path_to_repo)
request = Gitaly::CommitIsAncestorRequest.new(
repository: repo,
ancestor_id: ancestor_id,
child_id: child_id
)
stub.commit_is_ancestor(request).value
end
end
end
end
......
......@@ -1851,4 +1851,17 @@ describe Repository, models: true do
end
end
end
describe '#is_ancestor?' do
context 'Gitaly is_ancestor feature enabled' do
it 'asks Gitaly server if it\'s an ancestor' do
commit = repository.commit
allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(:is_ancestor).and_return(true)
expect(Gitlab::GitalyClient::Commit).to receive(:is_ancestor).
with(repository.raw_repository, commit.id, commit.id).and_return(true)
expect(repository.is_ancestor?(commit.id, commit.id)).to be true
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment