From 7de2d56f5282de4a46452ea15da4f6063c1bbbb5 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Wed, 1 Apr 2015 21:06:03 -0400 Subject: [PATCH] Simplify versions code --- Library/Homebrew/formula_versions.rb | 31 ++++++++++------------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/Library/Homebrew/formula_versions.rb b/Library/Homebrew/formula_versions.rb index eb4334a62a..563961b7f8 100644 --- a/Library/Homebrew/formula_versions.rb +++ b/Library/Homebrew/formula_versions.rb @@ -7,22 +7,12 @@ class FormulaVersions ErrorDuringExecution, LoadError, ] - attr_reader :f + attr_reader :name, :repository, :entry_name - def initialize(f) - @f = f - end - - def repository - @repository ||= if f.tap? - HOMEBREW_LIBRARY.join("Taps", f.tap) - else - HOMEBREW_REPOSITORY - end - end - - def entry_name - @entry_name ||= f.path.relative_path_from(repository).to_s + def initialize(formula) + @name = formula.name + @repository = formula.tap? ? HOMEBREW_LIBRARY.join("Taps", formula.tap) : HOMEBREW_REPOSITORY + @entry_name = formula.path.relative_path_from(repository).to_s end def rev_list(branch="HEAD") @@ -38,21 +28,22 @@ class FormulaVersions end def formula_at_revision(rev) - FileUtils.mktemp(f.name) do - path = Pathname.pwd.join("#{f.name}.rb") + FileUtils.mktemp(name) do + path = Pathname.pwd.join("#{name}.rb") path.write file_contents_at_revision(rev) + old_const = Formulary.unload_formula(name) + begin - old_const = Formulary.unload_formula(f.name) 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 #{f.name} at revision #{rev}", e.backtrace if ARGV.debug? + ohai "#{e} in #{name} at revision #{rev}", e.backtrace if ARGV.debug? rescue FormulaUnavailableError # Suppress this error ensure - Formulary.restore_formula(f.name, old_const) + Formulary.restore_formula(name, old_const) end end end