Simplify versions code
This commit is contained in:
parent
f51439329b
commit
7de2d56f52
@ -7,22 +7,12 @@ class FormulaVersions
|
|||||||
ErrorDuringExecution, LoadError,
|
ErrorDuringExecution, LoadError,
|
||||||
]
|
]
|
||||||
|
|
||||||
attr_reader :f
|
attr_reader :name, :repository, :entry_name
|
||||||
|
|
||||||
def initialize(f)
|
def initialize(formula)
|
||||||
@f = f
|
@name = formula.name
|
||||||
end
|
@repository = formula.tap? ? HOMEBREW_LIBRARY.join("Taps", formula.tap) : HOMEBREW_REPOSITORY
|
||||||
|
@entry_name = formula.path.relative_path_from(repository).to_s
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def rev_list(branch="HEAD")
|
def rev_list(branch="HEAD")
|
||||||
@ -38,21 +28,22 @@ class FormulaVersions
|
|||||||
end
|
end
|
||||||
|
|
||||||
def formula_at_revision(rev)
|
def formula_at_revision(rev)
|
||||||
FileUtils.mktemp(f.name) do
|
FileUtils.mktemp(name) do
|
||||||
path = Pathname.pwd.join("#{f.name}.rb")
|
path = Pathname.pwd.join("#{name}.rb")
|
||||||
path.write file_contents_at_revision(rev)
|
path.write file_contents_at_revision(rev)
|
||||||
|
|
||||||
|
old_const = Formulary.unload_formula(name)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
old_const = Formulary.unload_formula(f.name)
|
|
||||||
nostdout { yield Formulary.factory(path.to_s) }
|
nostdout { yield Formulary.factory(path.to_s) }
|
||||||
rescue *IGNORED_EXCEPTIONS => e
|
rescue *IGNORED_EXCEPTIONS => e
|
||||||
# We rescue these so that we can skip bad versions and
|
# We rescue these so that we can skip bad versions and
|
||||||
# continue walking the history
|
# 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
|
rescue FormulaUnavailableError
|
||||||
# Suppress this error
|
# Suppress this error
|
||||||
ensure
|
ensure
|
||||||
Formulary.restore_formula(f.name, old_const)
|
Formulary.restore_formula(name, old_const)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user