Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Refactor TapLoader to fix tap migrations with API" #16214

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 40 additions & 46 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,43 @@

# Loads tapped formulae.
class TapLoader < FormulaLoader
def initialize(tapped_name, from:, warn:)
name, path, tap = formula_name_path(tapped_name, warn: warn)
super name, path, tap: tap
end

def formula_name_path(tapped_name, warn:)
user, repo, name = tapped_name.split("/", 3).map(&:downcase)
tap = Tap.fetch user, repo
path = find_formula_from_name(name, tap)

unless path.file?
if (possible_alias = tap.alias_dir/name).file?
path = possible_alias.resolved_path
name = path.basename(".rb").to_s

Check warning on line 629 in Library/Homebrew/formulary.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formulary.rb#L629

Added line #L629 was not covered by tests
elsif (new_name = tap.formula_renames[name].presence) &&
(new_path = find_formula_from_name(new_name, tap)).file?
old_name = name
path = new_path
name = new_name
new_name = tap.core_tap? ? name : "#{tap}/#{name}"
elsif (new_tap_name = tap.tap_migrations[name].presence)
new_tap_user, new_tap_repo, = new_tap_name.split("/")
new_tap_name = "#{new_tap_user}/#{new_tap_repo}"
new_tap = Tap.fetch new_tap_name
new_tap.ensure_installed!
new_tapped_name = "#{new_tap_name}/#{name}"
name, path = formula_name_path(new_tapped_name, warn: false)
old_name = tapped_name

Check warning on line 643 in Library/Homebrew/formulary.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formulary.rb#L638-L643

Added lines #L638 - L643 were not covered by tests
new_name = new_tap.core_tap? ? name : new_tapped_name
end

opoo "Formula #{old_name} was renamed to #{new_name}." if warn && old_name && new_name
end

[name, path, tap]
end

def get_formula(spec, alias_path: nil, force_bottle: false, flags: [], ignore_errors: false)
super
rescue FormulaUnreadableError => e
Expand Down Expand Up @@ -891,49 +928,6 @@
loader_for(ref).path
end

def self.tap_formula_name_path(tapped_name, warn:)
user, repo, name = tapped_name.split("/", 3).map(&:downcase)
tap = Tap.fetch user, repo
path = Formulary.find_formula_in_tap(name, tap)

unless path.file?
if (possible_alias = tap.alias_dir/name).file?
path = possible_alias.resolved_path
name = path.basename(".rb").to_s
elsif (new_name = tap.formula_renames[name].presence) &&
(new_path = Formulary.find_formula_in_tap(new_name, tap)).file?
old_name = name
path = new_path
name = new_name
new_name = tap.core_tap? ? name : "#{tap}/#{name}"
elsif (new_tap_name = tap.tap_migrations[name].presence)
new_tap_user, new_tap_repo, = new_tap_name.split("/")
new_tap_name = "#{new_tap_user}/#{new_tap_repo}"
new_tap = Tap.fetch new_tap_name
new_tap.ensure_installed!
new_tapped_name = "#{new_tap_name}/#{name}"
name, path = Formulary.tap_formula_name_path(new_tapped_name, warn: false)
old_name = tapped_name
new_name = new_tap.core_tap? ? name : new_tapped_name
end

opoo "Formula #{old_name} was renamed to #{new_name}." if warn && old_name && new_name
end

[name, path, tap]
end

def self.tap_loader_for(tapped_name, warn:)
name, path, tap = Formulary.tap_formula_name_path(tapped_name, warn: warn)

if name.exclude?("/") && !Homebrew::EnvConfig.no_install_from_api? &&
Homebrew::API::Formula.all_formulae.key?(name)
FormulaAPILoader.new(name)
else
TapLoader.new(name, path, tap: tap)
end
end

def self.loader_for(ref, from: nil, warn: true)
case ref
when HOMEBREW_BOTTLES_EXTNAME_REGEX
Expand All @@ -947,7 +941,7 @@
return AliasAPILoader.new(name) if Homebrew::API::Formula.all_aliases.key?(name)
end

return Formulary.tap_loader_for(ref, warn: warn)
return TapLoader.new(ref, from: from, warn: warn)
end

pathname_ref = Pathname.new(ref)
Expand Down Expand Up @@ -982,7 +976,7 @@
return FormulaAPILoader.new(CoreTap.instance.formula_renames[ref])
end

return Formulary.tap_loader_for("#{CoreTap.instance}/#{ref}", warn: warn)
return TapLoader.new("#{CoreTap.instance}/#{ref}", from: from, warn: warn)
end

possible_taps = Tap.select { |tap| tap.formula_renames.key?(ref) }
Expand All @@ -992,7 +986,7 @@
raise TapFormulaWithOldnameAmbiguityError.new(ref, possible_tap_newname_formulae)
end

return Formulary.tap_loader_for("#{possible_taps.first}/#{ref}", warn: warn) unless possible_taps.empty?
return TapLoader.new("#{possible_taps.first}/#{ref}", from: from, warn: warn) unless possible_taps.empty?

possible_keg_formula = Pathname.new("#{HOMEBREW_PREFIX}/opt/#{ref}/.brew/#{ref}.rb")
return FormulaLoader.new(ref, possible_keg_formula) if possible_keg_formula.file?
Expand Down
Loading