New implementation through BASH regexes match
This commit is contained in:
parent
a1e9e93902
commit
01d1e9b228
@ -18,7 +18,6 @@
|
||||
# HOMEBREW_USER_AGENT_CURL are set by brew.sh
|
||||
# shellcheck disable=SC2154
|
||||
source "${HOMEBREW_LIBRARY}/Homebrew/utils/lock.sh"
|
||||
source "${HOMEBREW_LIBRARY}/Homebrew/utils/url.sh"
|
||||
|
||||
# Replaces the function in Library/Homebrew/brew.sh to cache the Curl/Git executable to
|
||||
# provide speedup when using Curl/Git repeatedly (as update.sh does).
|
||||
@ -629,19 +628,18 @@ EOS
|
||||
# the refspec ensures that the default upstream branch gets updated
|
||||
(
|
||||
UPSTREAM_REPOSITORY_URL="$(git config remote.origin.url)"
|
||||
eval UPSTREAM_REPOSITORY_URL_PARSED=( $(url_get "${UPSTREAM_REPOSITORY_URL}" user pass host path) )
|
||||
if [[ ${#UPSTREAM_REPOSITORY_URL_PARSED[@]} -ne 4 ]]; then
|
||||
echo "Failed to parse repository URL=${UPSTREAM_REPOSITORY_URL} \!" >&2
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
# HOMEBREW_UPDATE_FORCE and HOMEBREW_UPDATE_AUTO aren't modified here so ignore subshell warning.
|
||||
# shellcheck disable=SC2030
|
||||
if [[ "${UPSTREAM_REPOSITORY_URL}" =~ https://(([^:@]+)(:([^@]+))?@)?github.com/(.*)$ ]] \
|
||||
then
|
||||
UPSTREAM_REPOSITORY="${BASH_REMATCH[5]%.git}"
|
||||
# HOMEBREW_GITHUB_API_TOKEN is optionally defined in the user environment.
|
||||
# can be superseded a token from the local repository URL
|
||||
# shellcheck disable=SC2153
|
||||
if [[ -n "${UPSTREAM_REPOSITORY_URL_PARSED[1]}" ]]
|
||||
if [[ -n "${BASH_REMATCH[4]}" ]]
|
||||
then
|
||||
CURL_GITHUB_API_ARGS=("--header" "Authorization: token ${UPSTREAM_REPOSITORY_URL_PARSED[1]}")
|
||||
CURL_GITHUB_API_ARGS=("--header" "Authorization: token ${BASH_REMATCH[4]}")
|
||||
elif [[ -n "${HOMEBREW_GITHUB_API_TOKEN}" ]]
|
||||
then
|
||||
CURL_GITHUB_API_ARGS=("--header" "Authorization: token ${HOMEBREW_GITHUB_API_TOKEN}")
|
||||
@ -649,12 +647,6 @@ EOS
|
||||
CURL_GITHUB_API_ARGS=()
|
||||
fi
|
||||
|
||||
# HOMEBREW_UPDATE_FORCE and HOMEBREW_UPDATE_AUTO aren't modified here so ignore subshell warning.
|
||||
# shellcheck disable=SC2030
|
||||
if [[ "${UPSTREAM_REPOSITORY_URL}" == "https://github.com/"* ]] \
|
||||
|| [[ "${UPSTREAM_REPOSITORY_URL_PARSED[2]}" == "github.com" ]]
|
||||
then
|
||||
UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY_URL_PARSED[3]%.git}"
|
||||
|
||||
if [[ "${DIR}" == "${HOMEBREW_REPOSITORY}" && -n "${HOMEBREW_UPDATE_TO_TAG}" ]]
|
||||
then
|
||||
|
||||
@ -1,53 +0,0 @@
|
||||
# url_get <URL> [key] [key] ...
|
||||
# where:
|
||||
# URL ~ [scheme://][user[:pass]@]host[:port][path]
|
||||
# key is one of the element composing the URL
|
||||
url_get() {
|
||||
[[ ${#} -gt 0 ]] || return
|
||||
|
||||
local url="${1}"
|
||||
[[ -z "${url}" ]] && return
|
||||
shift
|
||||
|
||||
local _uphpp="${url#*://}"
|
||||
local _scheme="${url%%://*}"
|
||||
if [[ "${url}" == "${_uphpp}" ]]; then
|
||||
_scheme=""
|
||||
fi
|
||||
|
||||
local _hpp="${_uphpp#*@}"
|
||||
local _up="${_uphpp%%@*}"
|
||||
if [[ "${_uphpp}" == "${_hpp}" ]]; then
|
||||
local _user=""
|
||||
local _pass=""
|
||||
else
|
||||
local _user="${_up%:*}"
|
||||
local _pass="${_up#*:}"
|
||||
if [[ "${_user}" == "${_up}" ]]; then
|
||||
_pass=""
|
||||
fi
|
||||
fi
|
||||
|
||||
local _hp="${_hpp%%/*}"
|
||||
# TODO: split path from arguments (path?arg=...&....)
|
||||
local _path="${_hpp#*/}"
|
||||
if [[ "${_hp}" == "${_hpp}" ]]; then
|
||||
_path=""
|
||||
elif [[ -z "${_path}" ]]; then
|
||||
_path="/"
|
||||
fi
|
||||
|
||||
local _host="${_hp%:*}"
|
||||
local _port="${_hp#*:}"
|
||||
if [[ "${_hp}" == "${_host}" ]]; then
|
||||
_port=""
|
||||
fi
|
||||
|
||||
while [[ ${#} -gt 0 ]]; do
|
||||
echo -n \""$(eval echo -n "\${_${1}}")"\"
|
||||
[[ ${#} -gt 1 ]] && echo -n "${IFS:- }"
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
# EoF
|
||||
Loading…
x
Reference in New Issue
Block a user