From c78aa433866e7b2f089a8f7f2287eb091cc22042 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 13 Nov 2016 13:35:25 +0000 Subject: [PATCH] audit: fix "version should not decrease" check. Fix the "version should not decrease" check so it correctly handles `version_scheme`s. Fixes #1489. --- Library/Homebrew/dev-cmd/audit.rb | 39 ++++++++++++++++++---------- Library/Homebrew/formula_versions.rb | 15 ++++++++--- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 568051b436..9024cf50c0 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -662,26 +662,39 @@ class FormulaAuditor return if @new_formula fv = FormulaVersions.new(formula, max_depth: 10) - no_decrease_attributes = [:revision, :version_scheme] - attributes = no_decrease_attributes + [:version] + attributes = [:revision, :version_scheme] + attributes_map = fv.version_attributes_map(attributes, "origin/master") - no_decrease_attributes.each do |attribute| - attributes_for_version = attributes_map[attribute][formula.version] - next if attributes_for_version.empty? - if formula.send(attribute) < attributes_for_version.max - problem "#{attribute} should not decrease" - end - end + [:stable, :devel].each do |spec| + attributes.each do |attribute| + spec_attribute_map = attributes_map[attribute][spec] + next if spec_attribute_map.nil? || spec_attribute_map.empty? - versions = attributes_map[:version].values.flatten - if !versions.empty? && formula.version < versions.max - problem "version should not decrease" + attributes_for_version = spec_attribute_map[formula.version] + next if attributes_for_version.nil? || attributes_for_version.empty? + + if formula.send(attribute) < attributes_for_version.max + problem "#{spec} #{attribute} should not decrease" + end + end + + spec_version_scheme_map = attributes_map[:version_scheme][spec] + next if spec_version_scheme_map.nil? || spec_version_scheme_map.empty? + + max_version_scheme = spec_version_scheme_map.values.flatten.max + max_version = spec_version_scheme_map.select do |_, version_scheme| + version_scheme.first == max_version_scheme + end.keys.max + + if max_version && formula.version < max_version + problem "#{spec} version should not decrease" + end end return if formula.revision.zero? if formula.stable - revision_map = attributes_map[:revision] + revision_map = attributes_map[:revision][:stable] if revision_map[formula.stable.version].empty? # check stable spec problem "'revision #{formula.revision}' should be removed" end diff --git a/Library/Homebrew/formula_versions.rb b/Library/Homebrew/formula_versions.rb index d9a082399f..f17ceefd53 100644 --- a/Library/Homebrew/formula_versions.rb +++ b/Library/Homebrew/formula_versions.rb @@ -61,19 +61,28 @@ class FormulaVersions 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] = [] } + attributes_map[attribute] ||= {} end rev_list(branch) do |rev| formula_at_revision(rev) do |f| 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 + if f.stable + map[:stable] ||= {} + map[:stable][f.stable.version] ||= [] + map[:stable][f.stable.version] << f.send(attribute) + end + next unless f.devel + map[:devel] ||= {} + map[:stable][f.devel.version] ||= [] + map[:devel][f.devel.version] << f.send(attribute) end end end + attributes_map end end