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 = []
|
formulae = []
|
||||||
if ARGV.named.empty?
|
if ARGV.named.empty?
|
||||||
formulae = Formula.full_names
|
formulae = Formula.files
|
||||||
else
|
else
|
||||||
tap = Tap.new(*tap_args)
|
tap = Tap.new(*tap_args)
|
||||||
raise TapUnavailableError, tap.name unless tap.installed?
|
raise TapUnavailableError, tap.name unless tap.installed?
|
||||||
formulae = tap.formula_files
|
formulae = tap.formula_files
|
||||||
end
|
end
|
||||||
|
|
||||||
formulae.sort.each do |n|
|
formulae.each do |file|
|
||||||
begin
|
begin
|
||||||
Formulary.factory(n)
|
Formulary.factory(file)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
onoe "problem in #{Formulary.path(n)}"
|
onoe "problem in #{file}"
|
||||||
puts e
|
puts e
|
||||||
Homebrew.failed = true
|
Homebrew.failed = true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -655,28 +655,43 @@ class Formula
|
|||||||
@core_names ||= Dir["#{HOMEBREW_LIBRARY}/Formula/*.rb"].map{ |f| File.basename f, ".rb" }.sort
|
@core_names ||= Dir["#{HOMEBREW_LIBRARY}/Formula/*.rb"].map{ |f| File.basename f, ".rb" }.sort
|
||||||
end
|
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
|
# an array of all tap {Formula} names
|
||||||
def self.tap_names
|
def self.tap_names
|
||||||
@tap_names ||= Tap.map(&:formula_names).flatten.sort
|
@tap_names ||= Tap.map(&:formula_names).flatten.sort
|
||||||
end
|
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
|
# an array of all {Formula} names
|
||||||
def self.names
|
def self.names
|
||||||
@names ||= (core_names + tap_names.map { |name| name.split("/")[-1] }).sort.uniq
|
@names ||= (core_names + tap_names.map { |name| name.split("/")[-1] }).sort.uniq
|
||||||
end
|
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
|
# an array of all {Formula} names, which the tap formulae have the fully-qualified name
|
||||||
def self.full_names
|
def self.full_names
|
||||||
@full_names ||= core_names + tap_names
|
@full_names ||= core_names + tap_names
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.each
|
def self.each
|
||||||
full_names.each do |name|
|
files.each do |file|
|
||||||
begin
|
begin
|
||||||
yield Formulary.factory(name)
|
yield Formulary.factory(file)
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
# Don't let one broken formula break commands. But do complain.
|
# Don't let one broken formula break commands. But do complain.
|
||||||
onoe "Failed to import: #{name}"
|
onoe "Failed to import: #{file}"
|
||||||
puts e
|
puts e
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user