Class: Homebrew::Vulns::History Private
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Walks a formula's tap history newest first via FormulaVersions, caching the rev-list and the per-revision loads per formula so every advisory for the same formula reuses them.
History that cannot be trusted fails closed: a shallow clone, a formula
file with no git history and a revision that cannot be loaded all end the
walk with :history_unavailable so callers skip the candidate rather
than inventing a boundary.
Instance Method Summary collapse
- #initialize ⇒ void constructor private
-
#walk(formula, &_block) ⇒ String, ...
private
Yield each loadable historical revision of
formula, newest first, until the block returns a result.
Constructor Details
#initialize ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
18 19 20 21 |
# File 'vulns/history.rb', line 18 def initialize @formula_versions = T.let({}, T::Hash[String, FormulaVersions]) @rev_lists = T.let({}, T::Hash[String, T::Array[[String, String]]]) end |
Instance Method Details
#walk(formula, &_block) ⇒ String, ...
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Yield each loadable historical revision of formula, newest first,
until the block returns a result. Returns that result,
:history_unavailable when the history cannot be trusted or nil once
every revision has been visited.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'vulns/history.rb', line 32 def walk(formula, &_block) return :history_unavailable if formula.tap!.shallow? fv = @formula_versions[formula.name] ||= FormulaVersions.new(formula) revs = @rev_lists[formula.name] ||= [].tap { |a| fv.rev_list("HEAD") { |rev, entry| a << [rev, entry] } } return :history_unavailable if revs.empty? revs.each do |rev, entry| # Wrap the verdict so keeping the walk going (`nil`) stays # distinguishable from a revision that failed to load. verdict = fv.formula_at_revision(rev, entry) { |old| [yield(old)] } return :history_unavailable if verdict.nil? result = verdict.fetch(0) return result unless result.nil? end nil end |