enumerate all formulae by files rather than names
Before ``` $ time brew readall brew readall 10.63s user 0.36s system 99% cpu 11.003 total ``` After ``` $ time brew readall brew readall 5.62s user 0.24s system 99% cpu 5.859 total ``` Closes Homebrew/homebrew#42302. Signed-off-by: Xu Cheng <xucheng@me.com>
This commit is contained in:
parent
aa28226423
commit
ac738ae2cd
@ -32,18 +32,18 @@ module Homebrew
|
||||
|
||||
formulae = []
|
||||
if ARGV.named.empty?
|
||||
formulae = Formula.full_names
|
||||
formulae = Formula.files
|
||||
else
|
||||
tap = Tap.new(*tap_args)
|
||||
raise TapUnavailableError, tap.name unless tap.installed?
|
||||
formulae = tap.formula_files
|
||||
end
|
||||
|
||||
formulae.sort.each do |n|
|
||||
formulae.each do |file|
|
||||
begin
|
||||
Formulary.factory(n)
|
||||
Formulary.factory(file)
|
||||
rescue Exception => e
|
||||
onoe "problem in #{Formulary.path(n)}"
|
||||
onoe "problem in #{file}"
|
||||
puts e
|
||||
Homebrew.failed = true
|
||||
end
|
||||
|
||||
@ -655,28 +655,43 @@ class Formula
|
||||
@core_names ||= Dir["#{HOMEBREW_LIBRARY}/Formula/*.rb"].map{ |f| File.basename f, ".rb" }.sort
|
||||
end
|
||||
|
||||
# an array of all core {Formula} files
|
||||
def self.core_files
|
||||
@core_files ||= Pathname.glob("#{HOMEBREW_LIBRARY}/Formula/*.rb")
|
||||
end
|
||||
|
||||
# an array of all tap {Formula} names
|
||||
def self.tap_names
|
||||
@tap_names ||= Tap.map(&:formula_names).flatten.sort
|
||||
end
|
||||
|
||||
# an array of all tap {Formula} files
|
||||
def self.tap_files
|
||||
@tap_files ||= Tap.map(&:formula_files).flatten
|
||||
end
|
||||
|
||||
# an array of all {Formula} names
|
||||
def self.names
|
||||
@names ||= (core_names + tap_names.map { |name| name.split("/")[-1] }).sort.uniq
|
||||
end
|
||||
|
||||
# an array of all {Formula} files
|
||||
def self.files
|
||||
@files ||= core_files + tap_files
|
||||
end
|
||||
|
||||
# an array of all {Formula} names, which the tap formulae have the fully-qualified name
|
||||
def self.full_names
|
||||
@full_names ||= core_names + tap_names
|
||||
end
|
||||
|
||||
def self.each
|
||||
full_names.each do |name|
|
||||
files.each do |file|
|
||||
begin
|
||||
yield Formulary.factory(name)
|
||||
yield Formulary.factory(file)
|
||||
rescue StandardError => e
|
||||
# Don't let one broken formula break commands. But do complain.
|
||||
onoe "Failed to import: #{name}"
|
||||
onoe "Failed to import: #{file}"
|
||||
puts e
|
||||
next
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user