Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
Simplify versions code
Browse files Browse the repository at this point in the history
  • Loading branch information
jacknagel committed Apr 2, 2015
1 parent 6cff0ac commit aaac3bd
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions Library/Homebrew/formula_versions.rb
Expand Up @@ -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")
Expand All @@ -38,21 +28,22 @@ def file_contents_at_revision(rev)
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
Expand Down

0 comments on commit aaac3bd

Please sign in to comment.