From a597a1eecbe4b8996be048ef73d7c267bcb4a51a Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Wed, 28 Aug 2024 18:58:27 +0800 Subject: [PATCH] Reverse order of `if` conditional Checking for readability is a cheaper operation that `git diff-index`. --- Library/Homebrew/brew.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 9c0be7cbdc..cace4206ee 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -458,8 +458,8 @@ if [[ -n "${GIT_REVISION}" ]] then GIT_DESCRIBE_CACHE_FILE="${GIT_DESCRIBE_CACHE}/${GIT_REVISION}" # Pass `--` to guard against `git` being confused by a file named `HEAD`. - if "${HOMEBREW_GIT}" -C "${HOMEBREW_REPOSITORY}" diff-index --quiet --exit-code HEAD -- 2>/dev/null && - [[ -r "${GIT_DESCRIBE_CACHE_FILE}" ]] + if [[ -r "${GIT_DESCRIBE_CACHE_FILE}" ]] && + "${HOMEBREW_GIT}" -C "${HOMEBREW_REPOSITORY}" diff-index --quiet HEAD -- 2>/dev/null then read -r GIT_DESCRIBE_CACHE_HOMEBREW_VERSION <"${GIT_DESCRIBE_CACHE_FILE}" if [[ -n "${GIT_DESCRIBE_CACHE_HOMEBREW_VERSION}" && "${GIT_DESCRIBE_CACHE_HOMEBREW_VERSION}" != *"-dirty" ]]