aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMarkus Reiter2017-05-10 20:45:34 +0200
committerMarkus Reiter2017-05-22 02:01:57 +0200
commit330307b01a37ea514ec747ebab7a99dd47b79e7c (patch)
tree3bf20fb2013aa8569eb430290f22919a1e8f04cd /Library
parentade62aa1b1c3c2eb68dc6f065687fe38a8846ab0 (diff)
downloadbrew-330307b01a37ea514ec747ebab7a99dd47b79e7c.tar.bz2
Use `FormulaVersions` for checksum check.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/dev-cmd/audit.rb28
-rw-r--r--Library/Homebrew/formula_versions.rb20
2 files changed, 29 insertions, 19 deletions
diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb
index c11c503e3..4f71189c9 100644
--- a/Library/Homebrew/dev-cmd/audit.rb
+++ b/Library/Homebrew/dev-cmd/audit.rb
@@ -31,9 +31,6 @@
#:
#: If `--except-cops` is passed, the given Rubocop cop(s)' checks would be skipped.
#:
-#: If `--commit-range` is is passed, the audited Formula will be compared to the
-#: last revision before the `<commit_range>`.
-#:
#: `audit` exits with a non-zero status if any errors are found. This is useful,
#: for instance, for implementing pre-commit hooks.
@@ -651,25 +648,9 @@ class FormulaAuditor
problem "Devel-only (no stable download)"
end
- previous_formula_contents = unless formula.tap.nil?
- commit_range = ARGV.value("commit-range")
- Git.last_revision_of_file(formula.tap.path, formula.path, before_commit: commit_range)
- end
- previous_formula = unless (previous_formula_contents || "").empty?
- Formulary.from_contents(formula.name, formula.path, previous_formula_contents)
- end
-
%w[Stable Devel HEAD].each do |name|
next unless spec = formula.send(name.downcase)
- unless previous_formula.nil?
- previous_spec = previous_formula.send(name.downcase)
-
- if previous_spec.version == spec.version && previous_spec.checksum != spec.checksum
- problem "#{name}: only sha256 changed; needs to be confirmed by the developer"
- end
- end
-
ra = ResourceAuditor.new(spec, online: @online, strict: @strict).audit
problems.concat ra.problems.map { |problem| "#{name}: #{problem}" }
@@ -765,6 +746,15 @@ class FormulaAuditor
return if @new_formula
fv = FormulaVersions.new(formula)
+
+ previous_version_and_checksum = fv.previous_version_and_checksum("origin/master")
+ [:stable, :devel].each do |spec_sym|
+ next unless spec = formula.send(spec_sym)
+ next unless previous_version_and_checksum[spec_sym][:version] == spec.version
+ next if previous_version_and_checksum[spec_sym][:checksum] == spec.checksum
+ problem "#{spec_sym}: only sha256 changed; needs to be confirmed by the developer"
+ end
+
attributes = [:revision, :version_scheme]
attributes_map = fv.version_attributes_map(attributes, "origin/master")
diff --git a/Library/Homebrew/formula_versions.rb b/Library/Homebrew/formula_versions.rb
index 70706a2f0..5c4e0ecc9 100644
--- a/Library/Homebrew/formula_versions.rb
+++ b/Library/Homebrew/formula_versions.rb
@@ -63,6 +63,26 @@ class FormulaVersions
map
end
+ def previous_version_and_checksum(branch)
+ map = {}
+
+ rev_list(branch) do |rev|
+ formula_at_revision(rev) do |f|
+ [:stable, :devel].each do |spec_sym|
+ next unless spec = f.send(spec_sym)
+ map[spec_sym] ||= { version: spec.version, checksum: spec.checksum }
+ end
+
+ break if map[:stable] && map[:devel]
+ end
+ end
+
+ map[:stable] ||= {}
+ map[:devel] ||= {}
+
+ map
+ end
+
def version_attributes_map(attributes, branch)
attributes_map = {}
return attributes_map if attributes.empty?