libmakepkg: optimize get_protocol to always return proto, not proto+uri

e.g. git+https:// is commonly used for git repositories cloned over
HTTPS, but we assume a proto with a plus in it is actually a protocol
followed by some URI handler. So we might as well simplify the return
value and not have to always add glob matching everywhere when checking
the proto in use.

This is required in order to use the proto directly in function calls,
which will be used in a followup patch.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Eli Schwartz 2018-05-28 23:14:03 -04:00 committed by Allan McRae
parent 1b9e358f1d
commit ac0e21a6df
4 changed files with 19 additions and 17 deletions

View file

@ -52,7 +52,7 @@ generate_one_checksum() {
proto="$(get_protocol "$netfile")" proto="$(get_protocol "$netfile")"
case $proto in case $proto in
bzr*|git*|hg*|svn*) bzr|git|hg|svn)
sum="SKIP" sum="SKIP"
;; ;;
*) *)

View file

@ -49,7 +49,7 @@ check_pgpsigs() {
for netfile in "${all_sources[@]}"; do for netfile in "${all_sources[@]}"; do
proto="$(get_protocol "$netfile")" proto="$(get_protocol "$netfile")"
if [[ $proto = git* ]]; then if [[ $proto = git ]]; then
verify_git_signature "$netfile" "$statusfile" || continue verify_git_signature "$netfile" "$statusfile" || continue
else else
verify_file_signature "$netfile" "$statusfile" || continue verify_file_signature "$netfile" "$statusfile" || continue
@ -263,7 +263,7 @@ source_has_signatures() {
proto="$(get_protocol "$netfile")" proto="$(get_protocol "$netfile")"
query=$(get_uri_query "$netfile") query=$(get_uri_query "$netfile")
if [[ ${netfile%%::*} = *.@(sig?(n)|asc) || ( $proto = git* && $query = signed ) ]]; then if [[ ${netfile%%::*} = *.@(sig?(n)|asc) || ( $proto = git && $query = signed ) ]]; then
return 0 return 0
fi fi
done done

View file

@ -63,16 +63,16 @@ download_sources() {
local) local)
download_local "$netfile" download_local "$netfile"
;; ;;
bzr*) bzr)
(( get_vcs )) && download_bzr "$netfile" (( get_vcs )) && download_bzr "$netfile"
;; ;;
git*) git)
(( get_vcs )) && download_git "$netfile" (( get_vcs )) && download_git "$netfile"
;; ;;
hg*) hg)
(( get_vcs )) && download_hg "$netfile" (( get_vcs )) && download_hg "$netfile"
;; ;;
svn*) svn)
(( get_vcs )) && download_svn "$netfile" (( get_vcs )) && download_svn "$netfile"
;; ;;
*) *)
@ -93,16 +93,16 @@ extract_sources() {
local file=$(get_filename "$netfile") local file=$(get_filename "$netfile")
local proto=$(get_protocol "$netfile") local proto=$(get_protocol "$netfile")
case "$proto" in case "$proto" in
bzr*) bzr)
extract_bzr "$netfile" extract_bzr "$netfile"
;; ;;
git*) git)
extract_git "$netfile" extract_git "$netfile"
;; ;;
hg*) hg)
extract_hg "$netfile" extract_hg "$netfile"
;; ;;
svn*) svn)
extract_svn "$netfile" extract_svn "$netfile"
;; ;;
*) *)

View file

@ -41,10 +41,12 @@ get_protocol() {
if [[ $1 = *://* ]]; then if [[ $1 = *://* ]]; then
# strip leading filename # strip leading filename
local proto="${1#*::}" local proto="${1#*::}"
printf "%s\n" "${proto%%://*}" proto="${proto%%://*}"
# strip proto+uri://
printf "%s\n" "${proto%%+*}"
elif [[ $1 = *lp:* ]]; then elif [[ $1 = *lp:* ]]; then
local proto="${1#*::}" local proto="${1#*::}"
printf "%s\n" "${proto%%lp:*}" printf "%s\n" "${proto%%+lp:*}"
else else
printf "%s\n" local printf "%s\n" local
fi fi
@ -63,15 +65,15 @@ get_filename() {
local proto=$(get_protocol "$netfile") local proto=$(get_protocol "$netfile")
case $proto in case $proto in
bzr*|git*|hg*|svn*) bzr|git|hg|svn)
filename=${netfile%%#*} filename=${netfile%%#*}
filename=${filename%%\?*} filename=${filename%%\?*}
filename=${filename%/} filename=${filename%/}
filename=${filename##*/} filename=${filename##*/}
if [[ $proto = bzr* ]]; then if [[ $proto = bzr ]]; then
filename=${filename#*lp:} filename=${filename#*lp:}
fi fi
if [[ $proto = git* ]]; then if [[ $proto = git ]]; then
filename=${filename%%.git*} filename=${filename%%.git*}
fi fi
;; ;;
@ -89,7 +91,7 @@ get_filepath() {
local proto="$(get_protocol "$1")" local proto="$(get_protocol "$1")"
case $proto in case $proto in
bzr*|git*|hg*|svn*) bzr|git|hg|svn)
if [[ -d "$startdir/$file" ]]; then if [[ -d "$startdir/$file" ]]; then
file="$startdir/$file" file="$startdir/$file"
elif [[ -d "$SRCDEST/$file" ]]; then elif [[ -d "$SRCDEST/$file" ]]; then