diff options
author | Robert Speicher <robert@gitlab.com> | 2018-05-18 21:28:32 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2018-05-18 21:28:32 +0300 |
commit | ee59fdf566369e05c253551c445444a6c8fd1f77 (patch) | |
tree | 5f0c2f63bbc9ba1a3030ae6ae29ac2a5ea95587e /lib/gitlab | |
parent | fa04ec116620ce03a991248ed3590ef862d2c404 (diff) | |
parent | 61a5994db6f8b1e98f7ee1460f8aadb2ddb6c713 (diff) |
Merge branch 'gitaly-1182-search-by-content-name' into 'master'
Migrate Repo#search_by_{content,name} to Gitaly
See merge request gitlab-org/gitlab-ce!18750
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/git/repository.rb | 26 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/repository_service.rb | 10 |
2 files changed, 31 insertions, 5 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index b521d69930a..396ade871e8 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -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 + + 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/) + 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) diff --git a/lib/gitlab/gitaly_client/repository_service.rb b/lib/gitlab/gitaly_client/repository_service.rb index 132a5947f17..ee01f5a5bd9 100644 --- a/lib/gitlab/gitaly_client/repository_service.rb +++ b/lib/gitlab/gitaly_client/repository_service.rb @@ -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 |