Merge pull request #18402 from Homebrew/brew-tap-speedup

Speed up `brew tap` for no arguments
This commit is contained in:
Mike McQuaid 2024-09-25 10:41:37 +01:00 committed by GitHub
commit 90597f7a5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 0 deletions

View File

@ -172,6 +172,12 @@ case "$@" in
source "${HOMEBREW_LIBRARY}/Homebrew/list.sh"
homebrew-list "$@" && exit 0
;;
# homebrew-tap only handles invocations with no arguments
tap)
source "${HOMEBREW_LIBRARY}/Homebrew/tap.sh"
homebrew-tap "$@"
exit 0
;;
# falls back to cmd/help.rb on a non-zero return
help | --help | -h | --usage | "-?" | "")
homebrew-help "$@" && exit 0

27
Library/Homebrew/tap.sh Normal file
View File

@ -0,0 +1,27 @@
# Does the quickest output of brew tap possible for no arguments.
# HOMEBREW_LIBRARY is set by bin/brew
# shellcheck disable=SC2154
normalise_tap_name() {
local directory="$1"
local user
local repository
user="$(tr '[:upper:]' '[:lower:]' <<<"${directory%%/*}")"
repository="$(tr '[:upper:]' '[:lower:]' <<<"${directory#*/}")"
repository="${repository#@(home|linux)brew-}"
echo "${user}/${repository}"
}
homebrew-tap() {
local taplib="${HOMEBREW_LIBRARY}/Taps"
(
shopt -s extglob
for directory in "${taplib}"/*/*
do
[[ -d "${directory}" ]] || continue
normalise_tap_name "${directory#"${taplib}"/}"
done | sort
)
}