diff options
author | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-09-11 10:17:49 +0200 |
---|---|---|
committer | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-09-22 11:20:40 +0200 |
commit | 215c0cc07b5380adbbfd036e16da3365b5e3f30f (patch) | |
tree | 17caa30c3fe7b7abdc5faca20e60be9e5679e03c | |
parent | d103e95513704314a38ab8ae441851524031c4a1 (diff) | |
download | gitlab-ce-gitaly-508-find-commits.tar.gz |
Migrate Gitlab::Git::Repository#log to Gitalygitaly-508-find-commits
-rw-r--r-- | GITALY_SERVER_VERSION | 2 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/commit_service.rb | 20 | ||||
-rw-r--r-- | spec/lib/gitlab/git/commit_spec.rb | 10 |
5 files changed, 45 insertions, 3 deletions
diff --git a/GITALY_SERVER_VERSION b/GITALY_SERVER_VERSION index ca75280b09b..4ef2eb086f5 100644 --- a/GITALY_SERVER_VERSION +++ b/GITALY_SERVER_VERSION @@ -1 +1 @@ -0.38.0 +0.39.0 diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 0be35034d24..809b06e6d8b 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -386,7 +386,13 @@ module Gitlab options[:limit] ||= 0 options[:offset] ||= 0 - raw_log(options).map { |c| Commit.decorate(self, c) } + 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) } + end + end end # Used in gitaly-ruby diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index cbd9ff406de..955d2307f88 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -228,10 +228,18 @@ module Gitlab path.read.chomp end + def self.timestamp(t) + Google::Protobuf::Timestamp.new(seconds: t.to_i) + end + def self.encode(s) s.dup.force_encoding(Encoding::ASCII_8BIT) 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 def self.count_stack return unless RequestStore.active? diff --git a/lib/gitlab/gitaly_client/commit_service.rb b/lib/gitlab/gitaly_client/commit_service.rb index b536eb1868c..29c740d1d59 100644 --- a/lib/gitlab/gitaly_client/commit_service.rb +++ b/lib/gitlab/gitaly_client/commit_service.rb @@ -212,6 +212,26 @@ module Gitlab GitalyClient.call(@repository.storage, :commit_service, :commit_stats, request) 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 def commit_diff_request_params(commit, options = {}) diff --git a/spec/lib/gitlab/git/commit_spec.rb b/spec/lib/gitlab/git/commit_spec.rb index 46e968cc398..a3dff6d0d4b 100644 --- a/spec/lib/gitlab/git/commit_spec.rb +++ b/spec/lib/gitlab/git/commit_spec.rb @@ -181,7 +181,7 @@ describe Gitlab::Git::Commit, seed_helper: true do end end - describe '.where' do + shared_examples '.where' do context 'path is empty string' do subject do commits = described_class.where( @@ -279,6 +279,14 @@ describe Gitlab::Git::Commit, seed_helper: true do 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 subject do commits = described_class.between(repository, SeedRepo::Commit::PARENT_ID, SeedRepo::Commit::ID) |