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

Simplify Tap#alias_table. #16808

Merged
merged 2 commits into from
Mar 5, 2024
Merged
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
27 changes: 10 additions & 17 deletions Library/Homebrew/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ def initialize(user, repo)
@full_name = "#{@user}/homebrew-#{@repo}"
@path = TAP_DIRECTORY/@full_name.downcase
@git_repo = GitRepository.new(@path)
@alias_table = nil
@alias_reverse_table = nil
end

# Clear internal cache.
Expand Down Expand Up @@ -715,30 +713,25 @@ def aliases
@aliases ||= alias_table.keys
end

# a table mapping alias to formula name
# Mapping from aliases to formula names.
#
# @private
sig { returns(T::Hash[String, String]) }
def alias_table
return @alias_table if @alias_table

@alias_table = {}
alias_files.each do |alias_file|
@alias_table[alias_file_to_name(alias_file)] = formula_file_to_name(alias_file.resolved_path)
@alias_table ||= alias_files.each_with_object({}) do |alias_file, alias_table|
alias_table[alias_file_to_name(alias_file)] = formula_file_to_name(alias_file.resolved_path)
end
@alias_table
end

# a table mapping formula name to aliases
# Mapping from formula names to aliases.
#
# @private
sig { returns(T::Hash[String, T::Array[String]]) }
def alias_reverse_table
return @alias_reverse_table if @alias_reverse_table

@alias_reverse_table = {}
alias_table.each do |alias_name, formula_name|
@alias_reverse_table[formula_name] ||= []
@alias_reverse_table[formula_name] << alias_name
@alias_reverse_table ||= alias_table.each_with_object({}) do |(alias_name, formula_name), alias_reverse_table|
alias_reverse_table[formula_name] ||= []
alias_reverse_table[formula_name] << alias_name
end
@alias_reverse_table
end

sig { returns(Pathname) }
Expand Down