Merge pull request #6397 from amyspark/upgrade-bfs

breadth-first search for dependents upgrade
This commit is contained in:
Mike McQuaid 2019-08-23 08:25:55 +01:00 committed by GitHub
commit 4822241d6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -213,37 +213,43 @@ module Homebrew
formulae_to_upgrade = Set.new formulae_to_upgrade = Set.new
formulae_pinned = Set.new formulae_pinned = Set.new
formulae.each do |formula| formulae_to_check = formulae
checked_formulae = Set.new
until formulae_to_check.empty?
descendants = Set.new descendants = Set.new
dependents = kegs.select do |keg| formulae_to_check.each do |formula|
keg.runtime_dependencies next if checked_formulae.include?(formula)
.any? { |d| d["full_name"] == formula.full_name }
end
next if dependents.empty? dependents = kegs.select do |keg|
keg.runtime_dependencies
dependent_formulae = dependents.map(&:to_formula) .any? { |d| d["full_name"] == formula.full_name }
dependent_formulae.each do |f|
next if formulae_to_upgrade.include?(f)
next if formulae_pinned.include?(f)
if f.outdated?(fetch_head: args.fetch_HEAD?)
if f.pinned?
formulae_pinned << f
else
formulae_to_upgrade << f
end
end end
descendants << f next if dependents.empty?
dependent_formulae = dependents.map(&:to_formula)
dependent_formulae.each do |f|
next if formulae_to_upgrade.include?(f)
next if formulae_pinned.include?(f)
if f.outdated?(fetch_head: args.fetch_HEAD?)
if f.pinned?
formulae_pinned << f
else
formulae_to_upgrade << f
end
end
descendants << f
end
checked_formulae << formula
end end
upgradable_descendants, pinned_descendants = upgradable_dependents(kegs, descendants) formulae_to_check = descendants
formulae_to_upgrade.merge upgradable_descendants
formulae_pinned.merge pinned_descendants
end end
[formulae_to_upgrade, formulae_pinned] [formulae_to_upgrade, formulae_pinned]