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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
8b31ecd3
Commit
8b31ecd3
authored
Jul 17, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'remove-git-search-files' into 'master'
Remove Repository#search_files See merge request !12879
parents
bf7189ff
682b3287
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
125 deletions
+0
-125
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+0
-89
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+0
-36
No files found.
lib/gitlab/git/repository.rb
View file @
8b31ecd3
...
...
@@ -290,28 +290,6 @@ module Gitlab
(
size
.
to_f
/
1024
).
round
(
2
)
end
# Returns an array of BlobSnippets for files at the specified +ref+ that
# contain the +query+ string.
def
search_files
(
query
,
ref
=
nil
)
greps
=
[]
ref
||=
root_ref
populated_index
(
ref
).
each
do
|
entry
|
# Discard submodules
next
if
submodule?
(
entry
)
blob
=
Gitlab
::
Git
::
Blob
.
raw
(
self
,
entry
[
:oid
])
# Skip binary files
next
if
blob
.
data
.
encoding
==
Encoding
::
ASCII_8BIT
blob
.
load_all_data!
(
self
)
greps
+=
build_greps
(
blob
.
data
,
query
,
ref
,
entry
[
:path
])
end
greps
end
# Use the Rugged Walker API to build an array of commits.
#
# Usage.
...
...
@@ -1099,73 +1077,6 @@ module Gitlab
index
end
# Return an array of BlobSnippets for lines in +file_contents+ that match
# +query+
def
build_greps
(
file_contents
,
query
,
ref
,
filename
)
# The file_contents string is potentially huge so we make sure to loop
# through it one line at a time. This gives Ruby the chance to GC lines
# we are not interested in.
#
# We need to do a little extra work because we are not looking for just
# the lines that matches the query, but also for the context
# (surrounding lines). We will use Enumerable#each_cons to efficiently
# loop through the lines while keeping surrounding lines on hand.
#
# First, we turn "foo\nbar\nbaz" into
# [
# [nil, -3], [nil, -2], [nil, -1],
# ['foo', 0], ['bar', 1], ['baz', 3],
# [nil, 4], [nil, 5], [nil, 6]
# ]
lines_with_index
=
Enumerator
.
new
do
|
yielder
|
# Yield fake 'before' lines for the first line of file_contents
(
-
SEARCH_CONTEXT_LINES
..-
1
).
each
do
|
i
|
yielder
.
yield
[
nil
,
i
]
end
# Yield the actual file contents
count
=
0
file_contents
.
each_line
do
|
line
|
line
.
chomp!
yielder
.
yield
[
line
,
count
]
count
+=
1
end
# Yield fake 'after' lines for the last line of file_contents
(
count
+
1
..
count
+
SEARCH_CONTEXT_LINES
).
each
do
|
i
|
yielder
.
yield
[
nil
,
i
]
end
end
greps
=
[]
# Loop through consecutive blocks of lines with indexes
lines_with_index
.
each_cons
(
2
*
SEARCH_CONTEXT_LINES
+
1
)
do
|
line_block
|
# Get the 'middle' line and index from the block
line
,
_
=
line_block
[
SEARCH_CONTEXT_LINES
]
next
unless
line
&&
line
.
match
(
/
#{
Regexp
.
escape
(
query
)
}
/i
)
# Yay, 'line' contains a match!
# Get an array with just the context lines (no indexes)
match_with_context
=
line_block
.
map
(
&
:first
)
# Remove 'nil' lines in case we are close to the first or last line
match_with_context
.
compact!
# Get the line number (1-indexed) of the first context line
first_context_line_number
=
line_block
[
0
][
1
]
+
1
greps
<<
Gitlab
::
Git
::
BlobSnippet
.
new
(
ref
,
match_with_context
,
first_context_line_number
,
filename
)
end
greps
end
# Return the Rugged patches for the diff between +from+ and +to+.
def
diff_patches
(
from
,
to
,
options
=
{},
*
paths
)
options
||=
{}
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
8b31ecd3
...
...
@@ -251,42 +251,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
describe
'#search_files'
do
let
(
:results
)
{
repository
.
search_files
(
'rails'
,
'master'
)
}
subject
{
results
}
it
{
is_expected
.
to
be_kind_of
Array
}
describe
'#first'
do
subject
{
super
().
first
}
it
{
is_expected
.
to
be_kind_of
Gitlab
::
Git
::
BlobSnippet
}
end
context
'blob result'
do
subject
{
results
.
first
}
describe
'#ref'
do
subject
{
super
().
ref
}
it
{
is_expected
.
to
eq
(
'master'
)
}
end
describe
'#filename'
do
subject
{
super
().
filename
}
it
{
is_expected
.
to
eq
(
'CHANGELOG'
)
}
end
describe
'#startline'
do
subject
{
super
().
startline
}
it
{
is_expected
.
to
eq
(
35
)
}
end
describe
'#data'
do
subject
{
super
().
data
}
it
{
is_expected
.
to
include
"Ability to filter by multiple labels"
}
end
end
end
describe
'#submodule_url_for'
do
let
(
:repository
)
{
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
TEST_REPO_PATH
)
}
let
(
:ref
)
{
'master'
}
...
...
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