aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorXu Cheng2015-08-01 00:02:19 +0800
committerXu Cheng2015-08-01 00:49:50 +0800
commitac738ae2cd713e3cf836407730324b9ccc7e747a (patch)
treee048bf6e24fe386313144790666a8839f298136c /Library
parentaa28226423dcc77220f98d0b3cd888b63899462c (diff)
downloadbrew-ac738ae2cd713e3cf836407730324b9ccc7e747a.tar.bz2
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>
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/readall.rb8
-rw-r--r--Library/Homebrew/formula.rb21
2 files changed, 22 insertions, 7 deletions
diff --git a/Library/Homebrew/cmd/readall.rb b/Library/Homebrew/cmd/readall.rb
index 0714c18b1..a89b700f9 100644
--- a/Library/Homebrew/cmd/readall.rb
+++ b/Library/Homebrew/cmd/readall.rb
@@ -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
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index bc698b717..e41976d94 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -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