Commit f6609c98 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Implement search of code via git grep

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 77025ad8
...@@ -431,6 +431,40 @@ class Repository ...@@ -431,6 +431,40 @@ class Repository
end end
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 private
def cache def cache
......
- blob = @project.repository.search_to_blob(blob)
.blob-result .blob-result
.file-holder .file-holder
.file-title .file-title
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment