Skip to content

Commit e5c91bf

Browse files
authored
Merge pull request #21697 from Homebrew/remove-double-loop
bin/brew: simplify filtering of `BIN_BREW_EXPORTED_VARS`
2 parents 7af0e94 + 21f7ed2 commit e5c91bf

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

bin/brew

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,23 @@ BIN_BREW_EXPORTED_VARS=(
113113
# Load Homebrew's variable configuration files from disk.
114114
export_homebrew_env_file() {
115115
local env_file
116+
local bin_brew_exported_vars_regex
116117

117118
env_file="${1}"
118119
[[ -r "${env_file}" ]] || return 0
120+
121+
bin_brew_exported_vars_regex="^($(
122+
IFS='|'
123+
echo "${BIN_BREW_EXPORTED_VARS[*]}"
124+
))"
125+
119126
while read -r line
120127
do
121128
# only load variables defined in env_config.rb
122129
[[ "${line}" =~ ^(HOMEBREW_|SUDO_ASKPASS=|(all|no|ftp|https?)_proxy=) ]] || continue
123130

124131
# forbid overriding variables that are set in this file
125-
local invalid_variable
126-
for VAR in "${BIN_BREW_EXPORTED_VARS[@]}"
127-
do
128-
[[ "${line}" = "${VAR}"* ]] && invalid_variable="${VAR}"
129-
done
130-
[[ -n "${invalid_variable:-}" ]] && continue
132+
[[ "${line}" =~ ${bin_brew_exported_vars_regex} ]] && continue
131133

132134
export "${line?}"
133135
done <"${env_file}"

0 commit comments

Comments
 (0)