Commit e28896ce authored by Douwe Maan's avatar Douwe Maan

Merge branch 'zj-find-all-commits' into 'master'

FindAllCommits mandatory

Closes gitaly#326

See merge request gitlab-org/gitlab-ce!20242
parents 37b19222 ec78d29a
...@@ -143,57 +143,10 @@ module Gitlab ...@@ -143,57 +143,10 @@ module Gitlab
# #
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/326 # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/326
def find_all(repo, options = {}) def find_all(repo, options = {})
Gitlab::GitalyClient.migrate(:find_all_commits) do |is_enabled| repo.wrapped_gitaly_errors do
if is_enabled
find_all_by_gitaly(repo, options)
else
find_all_by_rugged(repo, options)
end
end
end
def find_all_by_rugged(repo, options = {})
actual_options = options.dup
allowed_options = [:ref, :max_count, :skip, :order]
actual_options.keep_if do |key|
allowed_options.include?(key)
end
default_options = { skip: 0 }
actual_options = default_options.merge(actual_options)
rugged = repo.rugged
walker = Rugged::Walker.new(rugged)
if actual_options[:ref]
walker.push(rugged.rev_parse_oid(actual_options[:ref]))
else
rugged.references.each("refs/heads/*") do |ref|
walker.push(ref.target_id)
end
end
walker.sorting(rugged_sort_type(actual_options[:order]))
commits = []
offset = actual_options[:skip]
limit = actual_options[:max_count]
walker.each(offset: offset, limit: limit) do |commit|
commits.push(decorate(repo, commit))
end
walker.reset
commits
rescue Rugged::OdbError
[]
end
def find_all_by_gitaly(repo, options = {})
Gitlab::GitalyClient::CommitService.new(repo).find_all_commits(options) Gitlab::GitalyClient::CommitService.new(repo).find_all_commits(options)
end end
end
def decorate(repository, commit, ref = nil) def decorate(repository, commit, ref = nil)
Gitlab::Git::Commit.new(repository, commit, ref) Gitlab::Git::Commit.new(repository, commit, ref)
......
...@@ -331,7 +331,6 @@ describe Gitlab::Git::Commit, seed_helper: true do ...@@ -331,7 +331,6 @@ describe Gitlab::Git::Commit, seed_helper: true do
end end
describe '.find_all' do describe '.find_all' do
shared_examples 'finding all commits' do
it 'should return a return a collection of commits' do it 'should return a return a collection of commits' do
commits = described_class.find_all(repository) commits = described_class.find_all(repository)
...@@ -384,35 +383,6 @@ describe Gitlab::Git::Commit, seed_helper: true do ...@@ -384,35 +383,6 @@ describe Gitlab::Git::Commit, seed_helper: true do
end end
end end
context 'when Gitaly find_all_commits feature is enabled' do
it_behaves_like 'finding all commits'
end
context 'when Gitaly find_all_commits feature is disabled', :skip_gitaly_mock do
it_behaves_like 'finding all commits'
context 'while applying a sort order based on the `order` option' do
it "allows ordering topologically (no parents shown before their children)" do
expect_any_instance_of(Rugged::Walker).to receive(:sorting).with(Rugged::SORT_TOPO)
described_class.find_all(repository, order: :topo)
end
it "allows ordering by date" do
expect_any_instance_of(Rugged::Walker).to receive(:sorting).with(Rugged::SORT_DATE | Rugged::SORT_TOPO)
described_class.find_all(repository, order: :date)
end
it "applies no sorting by default" do
expect_any_instance_of(Rugged::Walker).to receive(:sorting).with(Rugged::SORT_NONE)
described_class.find_all(repository)
end
end
end
end
describe '#batch_by_oid' do describe '#batch_by_oid' do
context 'when oids is empty' do context 'when oids is empty' do
it 'makes no Gitaly request' do it 'makes no Gitaly request' do
......
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