Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
61a5994d
Commit
61a5994d
authored
May 04, 2018
by
Kim "BKC" Carlbäcker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate RepositoryService#SearchFilesBy{Content,Name}
parent
1b9ff9db
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
8 deletions
+44
-8
GITALY_SERVER_VERSION
GITALY_SERVER_VERSION
+1
-1
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+21
-5
lib/gitlab/gitaly_client/repository_service.rb
lib/gitlab/gitaly_client/repository_service.rb
+10
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+12
-2
No files found.
GITALY_SERVER_VERSION
View file @
61a5994d
0.10
0
.0
0.10
2
.0
lib/gitlab/git/repository.rb
View file @
61a5994d
...
@@ -1473,11 +1473,20 @@ module Gitlab
...
@@ -1473,11 +1473,20 @@ module Gitlab
def
search_files_by_content
(
query
,
ref
)
def
search_files_by_content
(
query
,
ref
)
return
[]
if
empty?
||
query
.
blank?
return
[]
if
empty?
||
query
.
blank?
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
offset
=
2
args
=
%W(grep -i -I -n -z --before-context
#{
offset
}
--after-context
#{
offset
}
-E -e
#{
Regexp
.
escape
(
query
)
}
#{
ref
||
root_
ref
}
)
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
end
def
can_be_merged?
(
source_sha
,
target_branch
)
def
can_be_merged?
(
source_sha
,
target_branch
)
gitaly_migrate
(
:can_be_merged
)
do
|
is_enabled
|
gitaly_migrate
(
:can_be_merged
)
do
|
is_enabled
|
...
@@ -1491,13 +1500,20 @@ module Gitlab
...
@@ -1491,13 +1500,20 @@ module Gitlab
def
search_files_by_name
(
query
,
ref
)
def
search_files_by_name
(
query
,
ref
)
safe_query
=
Regexp
.
escape
(
query
.
sub
(
%r{^/*}
,
""
))
safe_query
=
Regexp
.
escape
(
query
.
sub
(
%r{^/*}
,
""
))
ref
||=
root_ref
return
[]
if
empty?
||
safe_query
.
blank?
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
end
def
find_commits_by_message
(
query
,
ref
,
path
,
limit
,
offset
)
def
find_commits_by_message
(
query
,
ref
,
path
,
limit
,
offset
)
gitaly_migrate
(
:commits_by_message
)
do
|
is_enabled
|
gitaly_migrate
(
:commits_by_message
)
do
|
is_enabled
|
...
...
lib/gitlab/gitaly_client/repository_service.rb
View file @
61a5994d
...
@@ -301,6 +301,16 @@ module Gitlab
...
@@ -301,6 +301,16 @@ module Gitlab
GitalyClient
.
call
(
@storage
,
:repository_service
,
:get_raw_changes
,
request
)
GitalyClient
.
call
(
@storage
,
:repository_service
,
:get_raw_changes
,
request
)
end
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
end
end
end
spec/models/repository_spec.rb
View file @
61a5994d
...
@@ -671,7 +671,7 @@ describe Repository do
...
@@ -671,7 +671,7 @@ describe Repository do
end
end
end
end
describe
"search_files_by_content"
do
shared_examples
"search_files_by_content"
do
let
(
:results
)
{
repository
.
search_files_by_content
(
'feature'
,
'master'
)
}
let
(
:results
)
{
repository
.
search_files_by_content
(
'feature'
,
'master'
)
}
subject
{
results
}
subject
{
results
}
...
@@ -718,7 +718,7 @@ describe Repository do
...
@@ -718,7 +718,7 @@ describe Repository do
end
end
end
end
describe
"search_files_by_name"
do
shared_examples
"search_files_by_name"
do
let
(
:results
)
{
repository
.
search_files_by_name
(
'files'
,
'master'
)
}
let
(
:results
)
{
repository
.
search_files_by_name
(
'files'
,
'master'
)
}
it
'returns result'
do
it
'returns result'
do
...
@@ -758,6 +758,16 @@ describe Repository do
...
@@ -758,6 +758,16 @@ describe Repository do
end
end
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
describe
'#async_remove_remote'
do
before
do
before
do
masterrev
=
repository
.
find_branch
(
'master'
).
dereferenced_target
masterrev
=
repository
.
find_branch
(
'master'
).
dereferenced_target
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment