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

Refactor rename/migration handling in Formulary. #16595

Merged

Conversation

reitermarkus
Copy link
Member

@reitermarkus reitermarkus commented Feb 6, 2024

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Merge most of the code paths for loading with/without API. Instead of checking if the renamed/alias file exists, we simply assume so, as the end result is an error anyways if it doesn't.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me but would like to see ✅ from @Bo98 and/or @apainintheneck as they've been working here recently.

Copy link
Contributor

@apainintheneck apainintheneck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me. From what I can tell Formulary.loader_for doesn't have [m]any tests but the loader code should be tested pretty well indirectly through all of the Formulary.factory tests so I'm not too worried about this change.

@reitermarkus reitermarkus merged commit fe5769f into Homebrew:master Feb 8, 2024
24 checks passed
@reitermarkus reitermarkus deleted the formula-rename-migration branch February 8, 2024 10:55
@reitermarkus reitermarkus mentioned this pull request Feb 8, 2024
7 tasks
Comment on lines -905 to +927
def self.tap_formula_name_path(tapped_name, warn:)
def self.tap_formula_name_type(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, tap = 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
type = nil

if (possible_alias = tap.alias_table[name].presence)
name = possible_alias
type = :alias
elsif (new_name = tap.formula_renames[name].presence)
old_name = name
name = new_name
new_name = tap.core_tap? ? name : "#{tap}/#{name}"
type = :rename
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, tap, = Formulary.tap_formula_name_type(new_tapped_name, warn: false)
old_name = tapped_name
new_name = new_tap.core_tap? ? name : new_tapped_name
type = :migration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the main difference in this logic at second glance is the removal of the Formulary.find_formula_in_tap and file path checks. Maybe those helped prevent infinite loops before and would have helped prevent what happened in #16628.

CC: @dduugg

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, previously it would just skip all this if the formula path exists.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the attention and fix here, @apainintheneck @reitermarkus 🥰

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reitermarkus @apainintheneck @dduugg Should we revert this PR given #16628 is still open?

@github-actions github-actions bot added the outdated PR was locked due to age label Mar 14, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants