Skip to content

Commit

Permalink
don't read entire log.
Browse files Browse the repository at this point in the history
  • Loading branch information
akr committed Aug 11, 2010
1 parent a9f84b0 commit e2360b9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 15 deletions.
18 changes: 11 additions & 7 deletions chkbuild/build.rb
Expand Up @@ -37,6 +37,7 @@
require 'gdb'
require "lchg"
require "util"
require "erbio"

module ChkBuild
end
Expand Down Expand Up @@ -489,7 +490,7 @@ def update_recent
content = ERB.new(RECENT_HTMLTemplate).result(binding)

recent_path = @public+"recent.html"
atomic_make_file(recent_path, content)
atomic_make_file(recent_path) {|f| f << content }
end

def list_tags(log)
Expand Down Expand Up @@ -598,8 +599,9 @@ def markup_diff(str)
End

def make_html_log(title, has_diff, dst)
content = ERB.new(LAST_HTMLTemplate, nil, '%').result(binding)
atomic_make_file(dst, content)
atomic_make_file(dst) {|_erbout|
ERBIO.new(LAST_HTMLTemplate, nil, '%').result(binding)
}
end

DIFF_HTMLTemplate = <<'End'
Expand Down Expand Up @@ -642,8 +644,9 @@ def make_html_log(title, has_diff, dst)
End

def make_diffhtml(title, has_diff)
content = ERB.new(DIFF_HTMLTemplate, nil, '%').result(binding)
atomic_make_compressed_file(@public+@compressed_diffhtml_relpath, content)
atomic_make_compressed_file(@public+@compressed_diffhtml_relpath) {|_erbout|
ERBIO.new(DIFF_HTMLTemplate, nil, '%').result(binding)
}
end

LOG_HTMLTemplate = <<'End'
Expand Down Expand Up @@ -687,8 +690,9 @@ def make_diffhtml(title, has_diff)
End

def make_loghtml(title, has_diff)
content = ERB.new(LOG_HTMLTemplate, nil, '%').result(binding)
atomic_make_compressed_file(@public+@compressed_loghtml_relpath, content)
atomic_make_compressed_file(@public+@compressed_loghtml_relpath) {|_erbout|
ERBIO.new(LOG_HTMLTemplate, nil, '%').result(binding)
}
end

def compress_file(src, dst)
Expand Down
44 changes: 44 additions & 0 deletions erbio.rb
@@ -0,0 +1,44 @@
# erbio.rb - erb output IO directly
#
# Copyright (C) 2010 Tanaka Akira <akr@fsij.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
# OF SUCH DAMAGE.

require 'erb'

class ERBIO < ERB
def set_eoutvar(compiler, eoutvar = '_erbout')
compiler.put_cmd = "#{eoutvar}.write"
compiler.insert_cmd = "#{eoutvar}.write"

cmd = []
cmd.push ""

compiler.pre_cmd = cmd

cmd = []
cmd.push(eoutvar)

compiler.post_cmd = cmd
end
end
16 changes: 8 additions & 8 deletions util.rb
Expand Up @@ -238,7 +238,7 @@ def force_link(old, new)
end
end

def atomic_make_file(filename, content)
def atomic_make_file(filename)
tmp = nil
i = 0
begin
Expand All @@ -248,18 +248,18 @@ def atomic_make_file(filename, content)
i += 1
retry
end
f << content
yield f
f.close
File.rename tmp, filename
end

def atomic_make_compressed_file(filename, content)
str = ""
strio = StringIO.new(str)
Zlib::GzipWriter.wrap(strio) {|z|
z << content
def atomic_make_compressed_file(filename)
atomic_make_file(filename) {|f|
Zlib::GzipWriter.wrap(f) {|z|
yield z
z.finish
}
}
atomic_make_file(filename, str)
end

def with_tempfile(content) # :yield: tempfile
Expand Down

0 comments on commit e2360b9

Please sign in to comment.