diff options
| author | Mike McQuaid | 2016-02-18 10:41:09 +0000 |
|---|---|---|
| committer | Mike McQuaid | 2016-02-18 10:43:10 +0000 |
| commit | 3ac1c7b6533dc5cfe4e74155538ded8b2b1ee9ec (patch) | |
| tree | cf89969f21c4cbf5b91060a458fd5bb5a60b9d82 /Library/Homebrew/cmd | |
| parent | f2faf49e3f189885c6787f7d4beb680c3a987d4f (diff) | |
| download | brew-3ac1c7b6533dc5cfe4e74155538ded8b2b1ee9ec.tar.bz2 | |
update: use GitHub API to avoid unneeded fetches.
Check to see if `HEAD` is the same as what we have locally. If it is:
don't bother to `git fetch`.
Closes Homebrew/homebrew#47888.
Closes Homebrew/homebrew#49219.
Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
Diffstat (limited to 'Library/Homebrew/cmd')
| -rw-r--r-- | Library/Homebrew/cmd/update.sh | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index d9226cfb9..4841c96bd 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -334,6 +334,22 @@ EOS UPSTREAM_BRANCH="$(upstream_branch)" # the refspec ensures that the default upstream branch gets updated ( + UPSTREAM_REPOSITORY_URL="$(git config remote.origin.url)" + if [[ "$UPSTREAM_REPOSITORY_URL" = "https://github.com/"* ]] + then + UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY_URL#https://github.com/}" + UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY%.git}" + UPSTREAM_BRANCH_LOCAL_SHA="$(git rev-parse "refs/remotes/origin/$UPSTREAM_BRANCH")" + # Only try to `git fetch` when the upstream branch is at a different SHA + # (so the API does not return 304: unmodified). + UPSTREAM_SHA_HTTP_CODE="$(curl --silent '--max-time' 3 \ + --output /dev/null --write-out "%{http_code}" \ + -H "Accept: application/vnd.github.chitauri-preview+sha" \ + -H "If-None-Match: \"$UPSTREAM_BRANCH_LOCAL_SHA\"" \ + "https://api.github.com/repos/$UPSTREAM_REPOSITORY/commits/$UPSTREAM_BRANCH")" + [[ "$UPSTREAM_SHA_HTTP_CODE" = "304" ]] && exit + fi + git fetch "${QUIET_ARGS[@]}" origin \ "refs/heads/$UPSTREAM_BRANCH:refs/remotes/origin/$UPSTREAM_BRANCH" || \ odie "Fetching $DIR failed!" |
