From 55ba22e2965a364d17a82796158357b2c6ee6ff2 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Thu, 18 Aug 2016 12:52:25 +0100 Subject: [PATCH] formula_versions: add version_attributes_map. This allows querying multiple attributes in the same way as `revision_map` did but without duplicating code or repeatedly traversing history. --- Library/Homebrew/cmd/audit.rb | 2 +- Library/Homebrew/formula_versions.rb | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cmd/audit.rb b/Library/Homebrew/cmd/audit.rb index b46f47ab58..3342b13547 100644 --- a/Library/Homebrew/cmd/audit.rb +++ b/Library/Homebrew/cmd/audit.rb @@ -627,7 +627,7 @@ class FormulaAuditor return unless formula.tap.git? # git log is required fv = FormulaVersions.new(formula, :max_depth => 10) - revision_map = fv.revision_map("origin/master") + revision_map = fv.version_attributes_map([:revision], "origin/master") revisions = revision_map[formula.version] if !revisions.empty? problem "revision should not decrease" if formula.revision < revisions.max diff --git a/Library/Homebrew/formula_versions.rb b/Library/Homebrew/formula_versions.rb index 13cb8ac8c4..2c5aae8f55 100644 --- a/Library/Homebrew/formula_versions.rb +++ b/Library/Homebrew/formula_versions.rb @@ -60,14 +60,22 @@ class FormulaVersions map end - def revision_map(branch) - map = Hash.new { |h, k| h[k] = [] } + def version_attributes_map(attributes, branch) + attributes_map = {} + return attributes_map if attributes.empty? + attributes.each do |attribute| + attributes_map[attribute] = Hash.new { |h, k| h[k] = [] } + end + rev_list(branch) do |rev| formula_at_revision(rev) do |f| - map[f.stable.version] << f.revision if f.stable - map[f.devel.version] << f.revision if f.devel + attributes.each do |attribute| + map = attributes_map[attribute] + map[f.stable.version] << f.send(attribute) if f.stable + map[f.devel.version] << f.send(attribute) if f.devel + end end end - map + attributes_map end end