Skip to content
Snippets Groups Projects
Commit e7e93072 authored by Robert Speicher's avatar Robert Speicher
Browse files

Merge branch 'use-gitaly-commit-is-ancestor' into 'master'

Use gitaly commit is ancestor

See merge request !9864
parents fee49c99 1ea0ce82
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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?
Loading
Loading
---
title: Use Gitaly for Repository#is_ancestor
merge_request: 9864
author:
Loading
Loading
@@ -411,6 +411,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
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment