Commit 9c16958c authored by Kim "BKC" Carlbäcker's avatar Kim "BKC" Carlbäcker

Migrate Gitlab::Git::Repository#log to Gitaly

parent 4d88f649
...@@ -386,8 +386,14 @@ module Gitlab ...@@ -386,8 +386,14 @@ module Gitlab
options[:limit] ||= 0 options[:limit] ||= 0
options[:offset] ||= 0 options[:offset] ||= 0
gitaly_migrate(:find_commits) do |is_enabled|
if is_enabled
gitaly_commit_client.find_commits(options)
else
raw_log(options).map { |c| Commit.decorate(self, c) } raw_log(options).map { |c| Commit.decorate(self, c) }
end end
end
end
# Used in gitaly-ruby # Used in gitaly-ruby
def raw_log(options) def raw_log(options)
......
...@@ -228,10 +228,18 @@ module Gitlab ...@@ -228,10 +228,18 @@ module Gitlab
path.read.chomp path.read.chomp
end end
def self.timestamp(t)
Google::Protobuf::Timestamp.new(seconds: t.to_i)
end
def self.encode(s) def self.encode(s)
s.dup.force_encoding(Encoding::ASCII_8BIT) s.dup.force_encoding(Encoding::ASCII_8BIT)
end end
def self.encode_repeated(a)
Google::Protobuf::RepeatedField.new(:bytes, a.map { |s| self.encode(s) } )
end
# Count a stack. Used for n+1 detection # Count a stack. Used for n+1 detection
def self.count_stack def self.count_stack
return unless RequestStore.active? return unless RequestStore.active?
......
...@@ -230,6 +230,26 @@ module Gitlab ...@@ -230,6 +230,26 @@ module Gitlab
GitalyClient.call(@repository.storage, :commit_service, :commit_stats, request) GitalyClient.call(@repository.storage, :commit_service, :commit_stats, request)
end end
def find_commits(options)
request = Gitaly::FindCommitsRequest.new(
repository: @gitaly_repo,
limit: options[:limit],
offset: options[:offset],
follow: options[:follow],
skip_merges: options[:skip_merges],
disable_walk: options[:disable_walk]
)
request.after = GitalyClient.timestamp(options[:after]) if options[:after]
request.before = GitalyClient.timestamp(options[:before]) if options[:before]
request.revision = GitalyClient.encode(options[:ref]) if options[:ref]
request.paths = GitalyClient.encode_repeated(Array(options[:path])) if options[:path].present?
response = GitalyClient.call(@repository.storage, :commit_service, :find_commits, request)
consume_commits_response(response)
end
private private
def call_commit_diff(request_params, options = {}) def call_commit_diff(request_params, options = {})
......
...@@ -181,7 +181,7 @@ describe Gitlab::Git::Commit, seed_helper: true do ...@@ -181,7 +181,7 @@ describe Gitlab::Git::Commit, seed_helper: true do
end end
end end
describe '.where' do shared_examples '.where' do
context 'path is empty string' do context 'path is empty string' do
subject do subject do
commits = described_class.where( commits = described_class.where(
...@@ -279,6 +279,14 @@ describe Gitlab::Git::Commit, seed_helper: true do ...@@ -279,6 +279,14 @@ describe Gitlab::Git::Commit, seed_helper: true do
end end
end end
describe '.where with gitaly' do
it_should_behave_like '.where'
end
describe '.where without gitaly', skip_gitaly_mock: true do
it_should_behave_like '.where'
end
describe '.between' do describe '.between' do
subject do subject do
commits = described_class.between(repository, SeedRepo::Commit::PARENT_ID, SeedRepo::Commit::ID) commits = described_class.between(repository, SeedRepo::Commit::PARENT_ID, SeedRepo::Commit::ID)
......
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