Simplify versions code

This commit is contained in:
Jack Nagel 2015-04-01 21:06:03 -04:00
parent f51439329b
commit 7de2d56f52

View File

@ -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