Commit 6018afa8 authored by Shinya Maeda's avatar Shinya Maeda

Add reverse_line

parent a1cddf05
...@@ -73,7 +73,7 @@ module Gitlab ...@@ -73,7 +73,7 @@ module Gitlab
match = "" match = ""
stream.each_line do |line| reverse_line do |line|
matches = line.scan(regex) matches = line.scan(regex)
next unless matches.is_a?(Array) next unless matches.is_a?(Array)
next if matches.empty? next if matches.empty?
...@@ -115,6 +115,26 @@ module Gitlab ...@@ -115,6 +115,26 @@ module Gitlab
chunks.join.lines.last(last_lines).join chunks.join.lines.last(last_lines).join
end end
def reverse_line
pos = 0
max = stream.size
while true
pos += BUFFER_SIZE
buf =
if pos <= max
stream.seek(-pos, IO::SEEK_END)
stream.read(BUFFER_SIZE)
else # Reached the head, read only left
stream.seek(0)
stream.read(BUFFER_SIZE - (pos - max))
end
yield(buf)
end
end
end end
end end
end end
......
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