Skip to content

Commit

Permalink
Merge pull request #18402 from Homebrew/brew-tap-speedup
Browse files Browse the repository at this point in the history
Speed up `brew tap` for no arguments
  • Loading branch information
MikeMcQuaid authored Sep 25, 2024
2 parents 2a1b85d + c17154d commit 90597f7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Library/Homebrew/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions Library/Homebrew/tap.sh
Original file line number Diff line number Diff line change
@@ -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
)
}

0 comments on commit 90597f7

Please sign in to comment.