Migrate RepositoryService#SearchFilesBy{Content,Name}

This commit is contained in:
Kim "BKC" Carlbäcker 2018-05-04 15:53:01 +02:00
parent 1b9ff9db81
commit 61a5994db6
4 changed files with 44 additions and 8 deletions

View file

@ -1 +1 @@
0.100.0
0.102.0

View file

@ -1473,10 +1473,19 @@ module Gitlab
def search_files_by_content(query, ref)
return [] if empty? || query.blank?
offset = 2
args = %W(grep -i -I -n -z --before-context #{offset} --after-context #{offset} -E -e #{Regexp.escape(query)} #{ref || root_ref})
safe_query = Regexp.escape(query)
ref ||= root_ref
run_git(args).first.scrub.split(/^--\n/)
gitaly_migrate(:search_files_by_content) do |is_enabled|
if is_enabled
gitaly_repository_client.search_files_by_content(ref, safe_query)
else
offset = 2
args = %W(grep -i -I -n -z --before-context #{offset} --after-context #{offset} -E -e #{safe_query} #{ref})
run_git(args).first.scrub.split(/^--\n/)
end
end
end
def can_be_merged?(source_sha, target_branch)
@ -1491,12 +1500,19 @@ module Gitlab
def search_files_by_name(query, ref)
safe_query = Regexp.escape(query.sub(%r{^/*}, ""))
ref ||= root_ref
return [] if empty? || safe_query.blank?
args = %W(ls-tree -r --name-status --full-tree #{ref || root_ref} -- #{safe_query})
gitaly_migrate(:search_files_by_name) do |is_enabled|
if is_enabled
gitaly_repository_client.search_files_by_name(ref, safe_query)
else
args = %W(ls-tree -r --name-status --full-tree #{ref} -- #{safe_query})
run_git(args).first.lines.map(&:strip)
run_git(args).first.lines.map(&:strip)
end
end
end
def find_commits_by_message(query, ref, path, limit, offset)

View file

@ -301,6 +301,16 @@ module Gitlab
GitalyClient.call(@storage, :repository_service, :get_raw_changes, request)
end
def search_files_by_name(ref, query)
request = Gitaly::SearchFilesByNameRequest.new(repository: @gitaly_repo, ref: ref, query: query)
GitalyClient.call(@storage, :repository_service, :search_files_by_name, request).flat_map(&:files)
end
def search_files_by_content(ref, query)
request = Gitaly::SearchFilesByContentRequest.new(repository: @gitaly_repo, ref: ref, query: query)
GitalyClient.call(@storage, :repository_service, :search_files_by_content, request).flat_map(&:matches)
end
end
end
end

View file

@ -671,7 +671,7 @@ describe Repository do
end
end
describe "search_files_by_content" do
shared_examples "search_files_by_content" do
let(:results) { repository.search_files_by_content('feature', 'master') }
subject { results }
@ -718,7 +718,7 @@ describe Repository do
end
end
describe "search_files_by_name" do
shared_examples "search_files_by_name" do
let(:results) { repository.search_files_by_name('files', 'master') }
it 'returns result' do
@ -758,6 +758,16 @@ describe Repository do
end
end
describe 'with gitaly enabled' do
it_behaves_like 'search_files_by_content'
it_behaves_like 'search_files_by_name'
end
describe 'with gitaly disabled', :disable_gitaly do
it_behaves_like 'search_files_by_content'
it_behaves_like 'search_files_by_name'
end
describe '#async_remove_remote' do
before do
masterrev = repository.find_branch('master').dereferenced_target