Skip to content
Snippets Groups Projects

Return the last coverage in trace stream

All threads resolved!
1 file
+ 21
1
Compare changes
  • Side-by-side
  • Inline
@@ -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?
@@ -86,34 +86,39 @@ module Gitlab
@@ -86,34 +86,39 @@ module Gitlab
nil
nil
rescue
rescue
# if bad regex or something goes wrong we dont want to interrupt transition
# if bad regex or something goes wrong we dont want to interrupt transition
# so we just silentrly ignore error for now
# so we just silently ignore error for now
end
end
private
private
def read_last_lines(last_lines)
def read_last_lines(limit)
chunks = []
to_enum(:reverse_line).first(limit).reverse.join
pos = lines = 0
end
max = stream.size
+10
def reverse_line
# We want an extra line to make sure fist line has full contents
stream.seek(0, IO::SEEK_END)
while lines <= last_lines && pos < max
debris = ''
pos += BUFFER_SIZE
until (buf = read_backward(BUFFER_SIZE)).empty?
buf =
buf += debris
if pos <= max
debris, *lines = buf.each_line.to_a
stream.seek(-pos, IO::SEEK_END)
lines.reverse_each do |line|
stream.read(BUFFER_SIZE)
yield(line.force_encoding('UTF-8'))
else # Reached the head, read only left
end
stream.seek(0)
stream.read(BUFFER_SIZE - (pos - max))
end
lines += buf.count("\n")
chunks.unshift(buf)
end
end
chunks.join.lines.last(last_lines).join
yield(debris.force_encoding('UTF-8')) unless debris.empty?
 
end
 
 
def read_backward(length)
 
cur_offset = stream.tell
 
start = cur_offset - length
 
start = 0 if start < 0
 
 
stream.seek(start, IO::SEEK_SET)
 
stream.read(cur_offset - start).tap do
 
stream.seek(start, IO::SEEK_SET)
 
end
end
end
end
end
end
end
Loading