formula: refactor outdated_kegs logic.
- Use the `Formula.cache` and `Cacheable` rather than rolling our own. - Use keyword arguments instead of `options = {}` - Improve readability in general
This commit is contained in:
parent
ed27f237c2
commit
ee1cbfc8d3
@ -495,22 +495,18 @@ class Formula
|
|||||||
prefix(head_version) if head_version
|
prefix(head_version) if head_version
|
||||||
end
|
end
|
||||||
|
|
||||||
def head_version_outdated?(version, options = {})
|
def head_version_outdated?(version, fetch_head: false)
|
||||||
tab = Tab.for_keg(prefix(version))
|
tab = Tab.for_keg(prefix(version))
|
||||||
|
|
||||||
return true if tab.version_scheme < version_scheme
|
return true if tab.version_scheme < version_scheme
|
||||||
return true if stable && tab.stable_version && tab.stable_version < stable.version
|
return true if stable && tab.stable_version && tab.stable_version < stable.version
|
||||||
return true if devel && tab.devel_version && tab.devel_version < devel.version
|
return true if devel && tab.devel_version && tab.devel_version < devel.version
|
||||||
|
return false unless fetch_head
|
||||||
|
return false unless head&.downloader.is_a?(VCSDownloadStrategy)
|
||||||
|
|
||||||
if options[:fetch_head]
|
downloader = head.downloader
|
||||||
return false unless head&.downloader.is_a?(VCSDownloadStrategy)
|
downloader.shutup! unless ARGV.verbose?
|
||||||
|
downloader.commit_outdated?(version.version.commit)
|
||||||
downloader = head.downloader
|
|
||||||
downloader.shutup! unless ARGV.verbose?
|
|
||||||
downloader.commit_outdated?(version.version.commit)
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# The latest prefix for this formula. Checks for {#head}, then {#devel}
|
# The latest prefix for this formula. Checks for {#head}, then {#devel}
|
||||||
@ -1173,43 +1169,41 @@ class Formula
|
|||||||
end
|
end
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
def outdated_kegs(options = {})
|
def outdated_kegs(fetch_head: false)
|
||||||
@outdated_kegs ||= Hash.new do |cache, key|
|
raise Migrator::MigrationNeededError, self if migration_needed?
|
||||||
raise Migrator::MigrationNeededError, self if migration_needed?
|
|
||||||
|
|
||||||
cache[key] = _outdated_kegs(key)
|
cache_key = "#{name}-#{fetch_head}"
|
||||||
end
|
Formula.cache[:outdated_kegs] ||= {}
|
||||||
@outdated_kegs[options]
|
Formula.cache[:outdated_kegs][cache_key] ||= begin
|
||||||
end
|
all_kegs = []
|
||||||
|
current_version = false
|
||||||
|
|
||||||
def _outdated_kegs(options = {})
|
installed_kegs.each do |keg|
|
||||||
all_kegs = []
|
all_kegs << keg
|
||||||
|
version = keg.version
|
||||||
|
next if version.head?
|
||||||
|
|
||||||
installed_kegs.each do |keg|
|
tab = Tab.for_keg(keg)
|
||||||
all_kegs << keg
|
next if version_scheme > tab.version_scheme
|
||||||
version = keg.version
|
next if version_scheme == tab.version_scheme && pkg_version > version
|
||||||
next if version.head?
|
|
||||||
|
|
||||||
tab = Tab.for_keg(keg)
|
# don't consider this keg current if there's a newer formula available
|
||||||
next if version_scheme > tab.version_scheme
|
next if follow_installed_alias? && new_formula_available?
|
||||||
next if version_scheme == tab.version_scheme && pkg_version > version
|
|
||||||
|
|
||||||
# don't consider this keg current if there's a newer formula available
|
# this keg is the current version of the formula, so it's not outdated
|
||||||
next if follow_installed_alias? && new_formula_available?
|
current_version = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
return [] # this keg is the current version of the formula, so it's not outdated
|
if current_version
|
||||||
end
|
[]
|
||||||
|
elsif (head_version = latest_head_version) &&
|
||||||
# Even if this formula hasn't been installed, there may be installations
|
!head_version_outdated?(head_version, fetch_head: fetch_head)
|
||||||
# of other formulae which used to be targets of the alias currently
|
[]
|
||||||
# targetting this formula. These should be counted as outdated versions.
|
else
|
||||||
all_kegs.concat old_installed_formulae.flat_map(&:installed_kegs)
|
all_kegs += old_installed_formulae.flat_map(&:installed_kegs)
|
||||||
|
all_kegs.sort_by(&:version)
|
||||||
head_version = latest_head_version
|
end
|
||||||
if head_version && !head_version_outdated?(head_version, options)
|
|
||||||
[]
|
|
||||||
else
|
|
||||||
all_kegs.sort_by(&:version)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1257,8 +1251,8 @@ class Formula
|
|||||||
end
|
end
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
def outdated?(options = {})
|
def outdated?(fetch_head: false)
|
||||||
!outdated_kegs(options).empty?
|
!outdated_kegs(fetch_head: fetch_head).empty?
|
||||||
rescue Migrator::MigrationNeededError
|
rescue Migrator::MigrationNeededError
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
@ -1091,10 +1091,6 @@ describe Formula do
|
|||||||
tab
|
tab
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_outdated_kegs
|
|
||||||
f.instance_variable_set(:@outdated_kegs, nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
example "greater different tap installed" do
|
example "greater different tap installed" do
|
||||||
setup_tab_for_prefix(greater_prefix, tap: "user/repo")
|
setup_tab_for_prefix(greater_prefix, tap: "user/repo")
|
||||||
expect(f.outdated_kegs).to be_empty
|
expect(f.outdated_kegs).to be_empty
|
||||||
@ -1208,7 +1204,7 @@ describe Formula do
|
|||||||
expect(f.outdated_kegs).to be_empty
|
expect(f.outdated_kegs).to be_empty
|
||||||
|
|
||||||
setup_tab_for_prefix(greater_prefix, tap: "homebrew/core")
|
setup_tab_for_prefix(greater_prefix, tap: "homebrew/core")
|
||||||
reset_outdated_kegs
|
described_class.clear_cache
|
||||||
|
|
||||||
expect(f.outdated_kegs).to be_empty
|
expect(f.outdated_kegs).to be_empty
|
||||||
end
|
end
|
||||||
@ -1220,12 +1216,12 @@ describe Formula do
|
|||||||
|
|
||||||
setup_tab_for_prefix(outdated_prefix)
|
setup_tab_for_prefix(outdated_prefix)
|
||||||
setup_tab_for_prefix(extra_outdated_prefix, tap: "homebrew/core")
|
setup_tab_for_prefix(extra_outdated_prefix, tap: "homebrew/core")
|
||||||
reset_outdated_kegs
|
described_class.clear_cache
|
||||||
|
|
||||||
expect(f.outdated_kegs).not_to be_empty
|
expect(f.outdated_kegs).not_to be_empty
|
||||||
|
|
||||||
setup_tab_for_prefix(outdated_prefix, tap: "user/repo")
|
setup_tab_for_prefix(outdated_prefix, tap: "user/repo")
|
||||||
reset_outdated_kegs
|
described_class.clear_cache
|
||||||
|
|
||||||
expect(f.outdated_kegs).not_to be_empty
|
expect(f.outdated_kegs).not_to be_empty
|
||||||
end
|
end
|
||||||
@ -1237,7 +1233,7 @@ describe Formula do
|
|||||||
expect(f.outdated_kegs).to be_empty
|
expect(f.outdated_kegs).to be_empty
|
||||||
|
|
||||||
setup_tab_for_prefix(same_prefix, tap: "user/repo")
|
setup_tab_for_prefix(same_prefix, tap: "user/repo")
|
||||||
reset_outdated_kegs
|
described_class.clear_cache
|
||||||
|
|
||||||
expect(f.outdated_kegs).to be_empty
|
expect(f.outdated_kegs).to be_empty
|
||||||
end
|
end
|
||||||
@ -1249,7 +1245,7 @@ describe Formula do
|
|||||||
|
|
||||||
tab.source["versions"] = { "stable" => f.version.to_s }
|
tab.source["versions"] = { "stable" => f.version.to_s }
|
||||||
tab.write
|
tab.write
|
||||||
reset_outdated_kegs
|
described_class.clear_cache
|
||||||
|
|
||||||
expect(f.outdated_kegs).to be_empty
|
expect(f.outdated_kegs).to be_empty
|
||||||
end
|
end
|
||||||
@ -1288,15 +1284,15 @@ describe Formula do
|
|||||||
|
|
||||||
tab_a.source["versions"] = { "stable" => f.version.to_s }
|
tab_a.source["versions"] = { "stable" => f.version.to_s }
|
||||||
tab_a.write
|
tab_a.write
|
||||||
reset_outdated_kegs
|
described_class.clear_cache
|
||||||
expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
|
expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
|
||||||
|
|
||||||
head_prefix_a.rmtree
|
head_prefix_a.rmtree
|
||||||
reset_outdated_kegs
|
described_class.clear_cache
|
||||||
expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
|
expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
|
||||||
|
|
||||||
setup_tab_for_prefix(head_prefix_c, source_modified_time: 1)
|
setup_tab_for_prefix(head_prefix_c, source_modified_time: 1)
|
||||||
reset_outdated_kegs
|
described_class.clear_cache
|
||||||
expect(f.outdated_kegs(fetch_head: true)).to be_empty
|
expect(f.outdated_kegs(fetch_head: true)).to be_empty
|
||||||
ensure
|
ensure
|
||||||
testball_repo.rmtree if testball_repo.exist?
|
testball_repo.rmtree if testball_repo.exist?
|
||||||
@ -1348,13 +1344,13 @@ describe Formula do
|
|||||||
setup_tab_for_prefix(prefix_b, versions: { "stable" => "2.14", "version_scheme" => 2 })
|
setup_tab_for_prefix(prefix_b, versions: { "stable" => "2.14", "version_scheme" => 2 })
|
||||||
|
|
||||||
expect(f.outdated_kegs).not_to be_empty
|
expect(f.outdated_kegs).not_to be_empty
|
||||||
reset_outdated_kegs
|
described_class.clear_cache
|
||||||
|
|
||||||
prefix_c = HOMEBREW_CELLAR/"testball/20141009"
|
prefix_c = HOMEBREW_CELLAR/"testball/20141009"
|
||||||
setup_tab_for_prefix(prefix_c, versions: { "stable" => "20141009", "version_scheme" => 3 })
|
setup_tab_for_prefix(prefix_c, versions: { "stable" => "20141009", "version_scheme" => 3 })
|
||||||
|
|
||||||
expect(f.outdated_kegs).not_to be_empty
|
expect(f.outdated_kegs).not_to be_empty
|
||||||
reset_outdated_kegs
|
described_class.clear_cache
|
||||||
|
|
||||||
prefix_d = HOMEBREW_CELLAR/"testball/20141011"
|
prefix_d = HOMEBREW_CELLAR/"testball/20141011"
|
||||||
setup_tab_for_prefix(prefix_d, versions: { "stable" => "20141009", "version_scheme" => 3 })
|
setup_tab_for_prefix(prefix_d, versions: { "stable" => "20141009", "version_scheme" => 3 })
|
||||||
@ -1377,7 +1373,7 @@ describe Formula do
|
|||||||
setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0", "version_scheme" => 1 })
|
setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0", "version_scheme" => 1 })
|
||||||
expect(f.outdated_kegs).not_to be_empty
|
expect(f.outdated_kegs).not_to be_empty
|
||||||
|
|
||||||
reset_outdated_kegs
|
described_class.clear_cache
|
||||||
head_prefix.rmtree
|
head_prefix.rmtree
|
||||||
|
|
||||||
setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0", "version_scheme" => 2 })
|
setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0", "version_scheme" => 2 })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user