Migrate Repository#find_commits_by_message to Gitaly

Closes gitaly#443
This commit is contained in:
Ahmad Sherif 2017-08-03 10:22:01 +02:00
parent b12107a0b9
commit c0b41064ff
6 changed files with 67 additions and 24 deletions

View File

@ -1 +1 @@
0.27.0 0.29.0

View File

@ -391,7 +391,7 @@ gem 'vmstat', '~> 2.3.0'
gem 'sys-filesystem', '~> 1.1.6' gem 'sys-filesystem', '~> 1.1.6'
# Gitaly GRPC client # Gitaly GRPC client
gem 'gitaly', '~> 0.24.0' gem 'gitaly', '~> 0.26.0'
gem 'toml-rb', '~> 0.3.15', require: false gem 'toml-rb', '~> 0.3.15', require: false

View File

@ -269,7 +269,7 @@ GEM
po_to_json (>= 1.0.0) po_to_json (>= 1.0.0)
rails (>= 3.2.0) rails (>= 3.2.0)
gherkin-ruby (0.3.2) gherkin-ruby (0.3.2)
gitaly (0.24.0) gitaly (0.26.0)
google-protobuf (~> 3.1) google-protobuf (~> 3.1)
grpc (~> 1.0) grpc (~> 1.0)
github-linguist (4.7.6) github-linguist (4.7.6)
@ -975,7 +975,7 @@ DEPENDENCIES
gettext (~> 3.2.2) gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.2.0) gettext_i18n_rails_js (~> 1.2.0)
gitaly (~> 0.24.0) gitaly (~> 0.26.0)
github-linguist (~> 4.7.0) github-linguist (~> 4.7.0)
gitlab-flowdock-git-hook (~> 1.0.1) gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-markup (~> 1.5.1) gitlab-markup (~> 1.5.1)

View File

@ -130,17 +130,13 @@ class Repository
return [] return []
end end
ref ||= root_ref raw_repository.gitaly_migrate(:commits_by_message) do |is_enabled|
if is_enabled
args = %W( find_commits_by_message_by_gitaly(query, ref, path, limit, offset)
log #{ref} --pretty=%H --skip #{offset} else
--max-count #{limit} --grep=#{query} --regexp-ignore-case find_commits_by_message_by_shelling_out(query, ref, path, limit, offset)
) end
args = args.concat(%W(-- #{path})) if path.present? end
git_log_results = run_git(args).first.lines
git_log_results.map { |c| commit(c.chomp) }.compact
end end
def find_branch(name, fresh_repo: true) def find_branch(name, fresh_repo: true)
@ -1184,4 +1180,25 @@ class Repository
def circuit_breaker def circuit_breaker
@circuit_breaker ||= Gitlab::Git::Storage::CircuitBreaker.for_storage(project.repository_storage) @circuit_breaker ||= Gitlab::Git::Storage::CircuitBreaker.for_storage(project.repository_storage)
end end
def find_commits_by_message_by_shelling_out(query, ref, path, limit, offset)
ref ||= root_ref
args = %W(
log #{ref} --pretty=%H --skip #{offset}
--max-count #{limit} --grep=#{query} --regexp-ignore-case
)
args = args.concat(%W(-- #{path})) if path.present?
git_log_results = run_git(args).first.lines
git_log_results.map { |c| commit(c.chomp) }.compact
end
def find_commits_by_message_by_gitaly(query, ref, path, limit, offset)
raw_repository
.gitaly_commit_client
.commits_by_message(query, revision: ref, path: path, limit: limit, offset: offset)
.map { |c| commit(c) }
end
end end

View File

@ -135,6 +135,20 @@ module Gitlab
consume_commits_response(response) consume_commits_response(response)
end end
def commits_by_message(query, revision: '', path: '', limit: 1000, offset: 0)
request = Gitaly::CommitsByMessageRequest.new(
repository: @gitaly_repo,
query: query,
revision: revision.to_s.force_encoding(Encoding::ASCII_8BIT),
path: path.to_s.force_encoding(Encoding::ASCII_8BIT),
limit: limit.to_i,
offset: offset.to_i
)
response = GitalyClient.call(@repository.storage, :commit_service, :commits_by_message, request)
consume_commits_response(response)
end
def languages(ref = nil) def languages(ref = nil)
request = Gitaly::CommitLanguagesRequest.new(repository: @gitaly_repo, revision: ref || '') request = Gitaly::CommitLanguagesRequest.new(repository: @gitaly_repo, revision: ref || '')
response = GitalyClient.call(@repository.storage, :commit_service, :commit_languages, request) response = GitalyClient.call(@repository.storage, :commit_service, :commit_languages, request)

View File

@ -234,19 +234,31 @@ describe Repository, models: true do
end end
describe '#find_commits_by_message' do describe '#find_commits_by_message' do
it 'returns commits with messages containing a given string' do shared_examples 'finding commits by message' do
commit_ids = repository.find_commits_by_message('submodule').map(&:id) it 'returns commits with messages containing a given string' do
commit_ids = repository.find_commits_by_message('submodule').map(&:id)
expect(commit_ids).to include('5937ac0a7beb003549fc5fd26fc247adbce4a52e') expect(commit_ids).to include(
expect(commit_ids).to include('6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') '5937ac0a7beb003549fc5fd26fc247adbce4a52e',
expect(commit_ids).to include('cfe32cf61b73a0d5e9f13e774abde7ff789b1660') '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9',
expect(commit_ids).not_to include('913c66a37b4a45b9769037c55c2d238bd0942d2e') 'cfe32cf61b73a0d5e9f13e774abde7ff789b1660'
)
expect(commit_ids).not_to include('913c66a37b4a45b9769037c55c2d238bd0942d2e')
end
it 'is case insensitive' do
commit_ids = repository.find_commits_by_message('SUBMODULE').map(&:id)
expect(commit_ids).to include('5937ac0a7beb003549fc5fd26fc247adbce4a52e')
end
end end
it 'is case insensitive' do context 'when Gitaly commits_by_message feature is enabled' do
commit_ids = repository.find_commits_by_message('SUBMODULE').map(&:id) it_behaves_like 'finding commits by message'
end
expect(commit_ids).to include('5937ac0a7beb003549fc5fd26fc247adbce4a52e') context 'when Gitaly commits_by_message feature is disabled', skip_gitaly_mock: true do
it_behaves_like 'finding commits by message'
end end
describe 'when storage is broken', broken_storage: true do describe 'when storage is broken', broken_storage: true do