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
Léo-Paul Géneau
gitlab-ce
Commits
f6609c98
Commit
f6609c98
authored
Jul 10, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement search of code via git grep
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
77025ad8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
app/models/repository.rb
app/models/repository.rb
+34
-0
app/views/search/results/_blob.html.haml
app/views/search/results/_blob.html.haml
+1
-0
No files found.
app/models/repository.rb
View file @
f6609c98
...
...
@@ -431,6 +431,40 @@ class Repository
end
end
def
search_files
(
query
,
ref
)
offset
=
2
args
=
%W(git grep -i -n --before-context
#{
offset
}
--after-context
#{
offset
}
#{
query
}
#{
ref
||
root_ref
}
)
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
).
first
.
scrub
.
split
(
/^--$/
)
end
def
search_to_blob
(
result
)
ref
=
nil
filename
=
nil
startline
=
0
lines
=
result
.
lstrip
.
lines
lines
.
each_with_index
do
|
line
,
index
|
if
line
=~
/^.*:.*:\d+:/
ref
,
filename
,
startline
=
line
.
split
(
':'
)
startline
=
startline
.
to_i
-
index
break
end
end
data
=
lines
.
map
do
|
line
|
line
.
sub
(
ref
,
''
).
sub
(
filename
,
''
).
sub
(
/^:-\d+-/
,
''
).
sub
(
/^::\d+:/
,
''
)
end
data
=
data
.
join
(
""
)
OpenStruct
.
new
(
filename:
filename
,
ref:
ref
,
startline:
startline
,
data:
data
)
end
private
def
cache
...
...
app/views/search/results/_blob.html.haml
View file @
f6609c98
-
blob
=
@project
.
repository
.
search_to_blob
(
blob
)
.blob-result
.file-holder
.file-title
...
...
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