diff options
| author | Martin Afanasjew | 2016-01-27 00:46:31 +0100 |
|---|---|---|
| committer | Martin Afanasjew | 2016-01-27 19:07:09 +0100 |
| commit | 4cc8d3ed8b03f1cb84fe66c911f9c3ced936a185 (patch) | |
| tree | df30817de364b08723601947a91fc85fb59db434 /Library | |
| parent | 2e2d2ab6ab8ed85fbb6a5524e6abc30df1731541 (diff) | |
| download | brew-4cc8d3ed8b03f1cb84fe66c911f9c3ced936a185.tar.bz2 | |
diagnostic: speed up check for outdated Homebrew
Determine the age of the local `HEAD` first and only if it is older than
24 hours proceed with the much more expensive `git ls-remote` to check
if there are any new upstream commits (there usually will be).
This keeps the overall logic unaltered, but significantly speeds up the
check for users that have recently updated (still slow for all others).
Closes Homebrew/homebrew#48499.
Signed-off-by: Martin Afanasjew <martin@afanasjew.de>
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/diagnostic.rb | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 0743c6e03..1c74d9a0c 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -1226,28 +1226,27 @@ module Homebrew def check_for_outdated_homebrew return unless Utils.git_available? - HOMEBREW_REPOSITORY.cd do - if File.directory? ".git" + + timestamp = if File.directory?("#{HOMEBREW_REPOSITORY}/.git") + HOMEBREW_REPOSITORY.cd { `git log -1 --format="%ct" HEAD`.to_i } + else + HOMEBREW_LIBRARY.mtime.to_i + end + return if Time.now.to_i - timestamp <= 60 * 60 * 24 # 24 hours + + if File.directory?("#{HOMEBREW_REPOSITORY}/.git") + HOMEBREW_REPOSITORY.cd do local = `git rev-parse -q --verify refs/remotes/origin/master`.chomp remote = /^([a-f0-9]{40})/.match(`git ls-remote origin refs/heads/master 2>/dev/null`) - if remote.nil? || local == remote[0] - return - end - end - - timestamp = if File.directory? ".git" - `git log -1 --format="%ct" HEAD`.to_i - else - HOMEBREW_LIBRARY.mtime.to_i + return if remote.nil? || local == remote[0] end + end - if Time.now.to_i - timestamp > 60 * 60 * 24 then <<-EOS.undent + <<-EOS.undent Your Homebrew is outdated. You haven't updated for at least 24 hours. This is a long time in brewland! To update Homebrew, run `brew update`. - EOS - end - end + EOS end def check_for_unlinked_but_not_keg_only |
