diff options
| author | Xu Cheng | 2015-09-09 13:46:08 +0800 | 
|---|---|---|
| committer | Xu Cheng | 2015-09-10 13:37:58 +0800 | 
| commit | 71be19235feb06b163aa8d494cfd817b483da8b5 (patch) | |
| tree | d9e4cee251593675b34413c3db443af570281d96 | |
| parent | 80514ee5d7f981c820d453baa70a189ad693280d (diff) | |
| download | brew-71be19235feb06b163aa8d494cfd817b483da8b5.tar.bz2 | |
Descriptions.cache_fresh?: return early
| -rw-r--r-- | Library/Homebrew/descriptions.rb | 26 | 
1 files changed, 16 insertions, 10 deletions
| diff --git a/Library/Homebrew/descriptions.rb b/Library/Homebrew/descriptions.rb index 428f42a5e..e74a84028 100644 --- a/Library/Homebrew/descriptions.rb +++ b/Library/Homebrew/descriptions.rb @@ -42,20 +42,26 @@ class Descriptions    # Return true if the cache exists, and neither Homebrew nor any of the Taps    # repos were updated more recently than it was.    def self.cache_fresh? -    if CACHE_FILE.exist? -      cache_date = File.mtime(CACHE_FILE) +    return false unless CACHE_FILE.exist? +    cache_mtime = File.mtime(CACHE_FILE) +    ref_master = ".git/refs/heads/master" -      ref_master = ".git/refs/heads/master" -      master = HOMEBREW_REPOSITORY/ref_master +    master = HOMEBREW_REPOSITORY/ref_master -      last_update = (master.exist? ? File.mtime(master) : Time.at(0)) +    # If ref_master doesn't exist, it means brew update is never run. +    # Since cache is found, we can assume it's fresh. +    if master.exist? +      core_mtime = File.mtime(master) +      return false if core_mtime > cache_mtime +    end -      Dir.glob(HOMEBREW_LIBRARY/"Taps/**"/ref_master).each do |repo| -        repo_mtime = File.mtime(repo) -        last_update = repo_mtime if repo_mtime > last_update -      end -      last_update <= cache_date +    Tap.each do |tap| +      next unless tap.git? +      repo_mtime = File.mtime(tap.path/ref_master) +      return false if repo_mtime > cache_mtime      end + +    true    end    # Create the cache if it doesn't already exist. | 
