From 11f0979dfb11cad1e0b3aefc910235f79faffa3b Mon Sep 17 00:00:00 2001 From: Xu Cheng Date: Wed, 2 Sep 2015 16:42:54 +0800 Subject: [PATCH] FormulaVersions: load from contents to reduce io --- Library/Homebrew/formula_versions.rb | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/formula_versions.rb b/Library/Homebrew/formula_versions.rb index 5d9ad43171..3d92d676c6 100644 --- a/Library/Homebrew/formula_versions.rb +++ b/Library/Homebrew/formula_versions.rb @@ -7,12 +7,13 @@ class FormulaVersions ErrorDuringExecution, LoadError ] - attr_reader :name, :repository, :entry_name + attr_reader :name, :path, :repository, :entry_name def initialize(formula) @name = formula.name + @path = formula.path @repository = formula.tap? ? HOMEBREW_LIBRARY.join("Taps", formula.tap) : HOMEBREW_REPOSITORY - @entry_name = formula.path.relative_path_from(repository).to_s + @entry_name = @path.relative_path_from(repository).to_s end def rev_list(branch) @@ -28,19 +29,16 @@ class FormulaVersions end def formula_at_revision(rev) - FileUtils.mktemp(name) do - path = Pathname.pwd.join("#{name}.rb") - path.write file_contents_at_revision(rev) + contents = file_contents_at_revision(rev) - begin - nostdout { yield Formulary.factory(path.to_s) } - rescue *IGNORED_EXCEPTIONS => e - # We rescue these so that we can skip bad versions and - # continue walking the history - ohai "#{e} in #{name} at revision #{rev}", e.backtrace if ARGV.debug? - rescue FormulaUnavailableError - # Suppress this error - end + begin + nostdout { yield Formulary.from_contents(name, path, contents) } + rescue *IGNORED_EXCEPTIONS => e + # We rescue these so that we can skip bad versions and + # continue walking the history + ohai "#{e} in #{name} at revision #{rev}", e.backtrace if ARGV.debug? + rescue FormulaUnavailableError + # Suppress this error end end