From e2360b9d4fd02f3f97a197a7ffaa210be120b42b Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 11 Aug 2010 14:55:09 +0000 Subject: [PATCH] don't read entire log. --- chkbuild/build.rb | 18 +++++++++++------- erbio.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ util.rb | 16 ++++++++-------- 3 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 erbio.rb diff --git a/chkbuild/build.rb b/chkbuild/build.rb index a60a376..f88cfc9 100644 --- a/chkbuild/build.rb +++ b/chkbuild/build.rb @@ -37,6 +37,7 @@ require 'gdb' require "lchg" require "util" +require "erbio" module ChkBuild end @@ -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) @@ -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' @@ -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' @@ -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) diff --git a/erbio.rb b/erbio.rb new file mode 100644 index 0000000..002cc41 --- /dev/null +++ b/erbio.rb @@ -0,0 +1,44 @@ +# erbio.rb - erb output IO directly +# +# Copyright (C) 2010 Tanaka Akira +# +# 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 diff --git a/util.rb b/util.rb index 5538e09..bd14ea0 100644 --- a/util.rb +++ b/util.rb @@ -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 @@ -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