[pacman-dev] [PATCH 1/3] 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: Eli Schwartz <eschwartz@archlinux.org> --- .../libmakepkg/integrity/generate_checksum.sh.in | 2 +- .../libmakepkg/integrity/verify_signature.sh.in | 4 ++-- scripts/libmakepkg/source.sh.in | 16 ++++++++-------- scripts/libmakepkg/util/source.sh.in | 14 ++++++++------ 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/scripts/libmakepkg/integrity/generate_checksum.sh.in b/scripts/libmakepkg/integrity/generate_checksum.sh.in index eb9b74fc..b8b078ec 100644 --- a/scripts/libmakepkg/integrity/generate_checksum.sh.in +++ b/scripts/libmakepkg/integrity/generate_checksum.sh.in @@ -52,7 +52,7 @@ generate_one_checksum() { proto="$(get_protocol "$netfile")" case $proto in - bzr*|git*|hg*|svn*) + bzr|git|hg|svn) sum="SKIP" ;; *) diff --git a/scripts/libmakepkg/integrity/verify_signature.sh.in b/scripts/libmakepkg/integrity/verify_signature.sh.in index ea877822..38f8afa1 100644 --- a/scripts/libmakepkg/integrity/verify_signature.sh.in +++ b/scripts/libmakepkg/integrity/verify_signature.sh.in @@ -49,7 +49,7 @@ check_pgpsigs() { for netfile in "${all_sources[@]}"; do proto="$(get_protocol "$netfile")" - if [[ $proto = git* ]]; then + if [[ $proto = git ]]; then verify_git_signature "$netfile" "$statusfile" || continue else verify_file_signature "$netfile" "$statusfile" || continue @@ -263,7 +263,7 @@ source_has_signatures() { proto="$(get_protocol "$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 fi done diff --git a/scripts/libmakepkg/source.sh.in b/scripts/libmakepkg/source.sh.in index 5d7df732..198efd5e 100644 --- a/scripts/libmakepkg/source.sh.in +++ b/scripts/libmakepkg/source.sh.in @@ -63,16 +63,16 @@ download_sources() { local) download_local "$netfile" ;; - bzr*) + bzr) (( get_vcs )) && download_bzr "$netfile" ;; - git*) + git) (( get_vcs )) && download_git "$netfile" ;; - hg*) + hg) (( get_vcs )) && download_hg "$netfile" ;; - svn*) + svn) (( get_vcs )) && download_svn "$netfile" ;; *) @@ -93,16 +93,16 @@ extract_sources() { local file=$(get_filename "$netfile") local proto=$(get_protocol "$netfile") case "$proto" in - bzr*) + bzr) extract_bzr "$netfile" ;; - git*) + git) extract_git "$netfile" ;; - hg*) + hg) extract_hg "$netfile" ;; - svn*) + svn) extract_svn "$netfile" ;; *) diff --git a/scripts/libmakepkg/util/source.sh.in b/scripts/libmakepkg/util/source.sh.in index 17e44664..faa7061b 100644 --- a/scripts/libmakepkg/util/source.sh.in +++ b/scripts/libmakepkg/util/source.sh.in @@ -41,10 +41,12 @@ get_protocol() { if [[ $1 = *://* ]]; then # strip leading filename local proto="${1#*::}" - printf "%s\n" "${proto%%://*}" + proto="${proto%%://*}" + # strip proto+uri:// + printf "%s\n" "${proto%%+*}" elif [[ $1 = *lp:* ]]; then local proto="${1#*::}" - printf "%s\n" "${proto%%lp:*}" + printf "%s\n" "${proto%%+lp:*}" else printf "%s\n" local fi @@ -63,15 +65,15 @@ get_filename() { local proto=$(get_protocol "$netfile") case $proto in - bzr*|git*|hg*|svn*) + bzr|git|hg|svn) filename=${netfile%%#*} filename=${filename%%\?*} filename=${filename%/} filename=${filename##*/} - if [[ $proto = bzr* ]]; then + if [[ $proto = bzr ]]; then filename=${filename#*lp:} fi - if [[ $proto = git* ]]; then + if [[ $proto = git ]]; then filename=${filename%%.git*} fi ;; @@ -89,7 +91,7 @@ get_filepath() { local proto="$(get_protocol "$1")" case $proto in - bzr*|git*|hg*|svn*) + bzr|git|hg|svn) if [[ -d "$startdir/$file" ]]; then file="$startdir/$file" elif [[ -d "$SRCDEST/$file" ]]; then -- 2.17.0
Lookup the existence of matching functions for each protocol, and fallback on the generic file handler. New source protocols can then be added via thirdparty libmakepkg drop-ins without requiring modifications to source.sh Fixes FS#49076 Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- scripts/libmakepkg/source.sh.in | 46 +++++++++------------------------ 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/scripts/libmakepkg/source.sh.in b/scripts/libmakepkg/source.sh.in index 198efd5e..c07ce76d 100644 --- a/scripts/libmakepkg/source.sh.in +++ b/scripts/libmakepkg/source.sh.in @@ -60,25 +60,15 @@ download_sources() { local proto=$(get_protocol "$netfile") case "$proto" in - local) - download_local "$netfile" - ;; - bzr) - (( get_vcs )) && download_bzr "$netfile" - ;; - git) - (( get_vcs )) && download_git "$netfile" - ;; - hg) - (( get_vcs )) && download_hg "$netfile" - ;; - svn) - (( get_vcs )) && download_svn "$netfile" - ;; - *) - download_file "$netfile" + bzr|git|hg|svn) + (( get_vcs )) || continue ;; esac + if declare -f download_$proto > /dev/null; then + download_$proto "$netfile" + else + download_file "$netfile" + fi popd &>/dev/null done @@ -92,22 +82,10 @@ extract_sources() { for netfile in "${all_sources[@]}"; do local file=$(get_filename "$netfile") local proto=$(get_protocol "$netfile") - case "$proto" in - bzr) - extract_bzr "$netfile" - ;; - git) - extract_git "$netfile" - ;; - hg) - extract_hg "$netfile" - ;; - svn) - extract_svn "$netfile" - ;; - *) - extract_file "$file" - ;; - esac + if declare -f extract_$proto > /dev/null; then + extract_$proto "$netfile" + else + extract_file "$file" + fi done } -- 2.17.0
On 29/05/18 14:30, Eli Schwartz wrote:
Lookup the existence of matching functions for each protocol, and fallback on the generic file handler. New source protocols can then be added via thirdparty libmakepkg drop-ins without requiring modifications to source.sh
Fixes FS#49076
Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- scripts/libmakepkg/source.sh.in | 46 +++++++++------------------------ 1 file changed, 12 insertions(+), 34 deletions(-)
diff --git a/scripts/libmakepkg/source.sh.in b/scripts/libmakepkg/source.sh.in index 198efd5e..c07ce76d 100644 --- a/scripts/libmakepkg/source.sh.in +++ b/scripts/libmakepkg/source.sh.in @@ -60,25 +60,15 @@ download_sources() {
local proto=$(get_protocol "$netfile") case "$proto" in - local) - download_local "$netfile" - ;; - bzr) - (( get_vcs )) && download_bzr "$netfile" - ;; - git) - (( get_vcs )) && download_git "$netfile" - ;; - hg) - (( get_vcs )) && download_hg "$netfile" - ;; - svn) - (( get_vcs )) && download_svn "$netfile" - ;; - *) - download_file "$netfile" + bzr|git|hg|svn) + (( get_vcs )) || continue ;;
Should this be moved into the download_$proto functions? I'd guess most of the dropins would be for other vcs systems, and this is not extendable.
esac + if declare -f download_$proto > /dev/null; then + download_$proto "$netfile" + else + download_file "$netfile" + fi
popd &>/dev/null done @@ -92,22 +82,10 @@ extract_sources() { for netfile in "${all_sources[@]}"; do local file=$(get_filename "$netfile") local proto=$(get_protocol "$netfile") - case "$proto" in - bzr) - extract_bzr "$netfile" - ;; - git) - extract_git "$netfile" - ;; - hg) - extract_hg "$netfile" - ;; - svn) - extract_svn "$netfile" - ;; - *) - extract_file "$file" - ;; - esac + if declare -f extract_$proto > /dev/null; then + extract_$proto "$netfile" + else + extract_file "$file" + fi done }
On 06/04/2018 02:56 AM, Allan McRae wrote:
+ bzr|git|hg|svn) + (( get_vcs )) || continue ;;
Should this be moved into the download_$proto functions? I'd guess most of the dropins would be for other vcs systems, and this is not extendable. Hmm.
Well, other VCS systems could implement private routines for "return 0" early on this, but it isn't strictly necessary for here. It's mildly more verbose, but OTOH it also makes things slightly more obvious. I guess just for the sake of clarity it should do as you suggested... -- Eli Schwartz Bug Wrangler and Trusted User
Lookup the existence of matching functions for each protocol, and fallback on the generic file handler. New source protocols can then be added via thirdparty libmakepkg drop-ins without requiring modifications to source.sh Fixes FS#49076 Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- v2: In order to be truly extensible, put the get_vcs check into the separate download_$proto functions. It's technically extensible either way, but if this is going to be extended then our existing methods should set a good example how to do so -- and the code is clearer. scripts/libmakepkg/source.sh.in | 47 ++++++----------------------- scripts/libmakepkg/source/bzr.sh.in | 5 +++ scripts/libmakepkg/source/git.sh.in | 5 +++ scripts/libmakepkg/source/hg.sh.in | 5 +++ scripts/libmakepkg/source/svn.sh.in | 5 +++ 5 files changed, 30 insertions(+), 37 deletions(-) diff --git a/scripts/libmakepkg/source.sh.in b/scripts/libmakepkg/source.sh.in index 198efd5e..2cb7dae1 100644 --- a/scripts/libmakepkg/source.sh.in +++ b/scripts/libmakepkg/source.sh.in @@ -59,26 +59,11 @@ download_sources() { pushd "$SRCDEST" &>/dev/null local proto=$(get_protocol "$netfile") - case "$proto" in - local) - download_local "$netfile" - ;; - bzr) - (( get_vcs )) && download_bzr "$netfile" - ;; - git) - (( get_vcs )) && download_git "$netfile" - ;; - hg) - (( get_vcs )) && download_hg "$netfile" - ;; - svn) - (( get_vcs )) && download_svn "$netfile" - ;; - *) - download_file "$netfile" - ;; - esac + if declare -f download_$proto > /dev/null; then + download_$proto "$netfile" + else + download_file "$netfile" + fi popd &>/dev/null done @@ -92,22 +77,10 @@ extract_sources() { for netfile in "${all_sources[@]}"; do local file=$(get_filename "$netfile") local proto=$(get_protocol "$netfile") - case "$proto" in - bzr) - extract_bzr "$netfile" - ;; - git) - extract_git "$netfile" - ;; - hg) - extract_hg "$netfile" - ;; - svn) - extract_svn "$netfile" - ;; - *) - extract_file "$file" - ;; - esac + if declare -f extract_$proto > /dev/null; then + extract_$proto "$netfile" + else + extract_file "$file" + fi done } diff --git a/scripts/libmakepkg/source/bzr.sh.in b/scripts/libmakepkg/source/bzr.sh.in index 52193b58..d3f7db3b 100644 --- a/scripts/libmakepkg/source/bzr.sh.in +++ b/scripts/libmakepkg/source/bzr.sh.in @@ -29,6 +29,11 @@ source "$LIBRARY/util/pkgbuild.sh" download_bzr() { + # abort early if parent says not to fetch + if declare -p get_vcs > /dev/null 2>&1; then + (( get_vcs )) || return + fi + local netfile=$1 local url=$(get_url "$netfile") diff --git a/scripts/libmakepkg/source/git.sh.in b/scripts/libmakepkg/source/git.sh.in index 130c11e1..497a668c 100644 --- a/scripts/libmakepkg/source/git.sh.in +++ b/scripts/libmakepkg/source/git.sh.in @@ -29,6 +29,11 @@ source "$LIBRARY/util/pkgbuild.sh" download_git() { + # abort early if parent says not to fetch + if declare -p get_vcs > /dev/null 2>&1; then + (( get_vcs )) || return + fi + local netfile=$1 local dir=$(get_filepath "$netfile") diff --git a/scripts/libmakepkg/source/hg.sh.in b/scripts/libmakepkg/source/hg.sh.in index ae9aed3b..4984883e 100644 --- a/scripts/libmakepkg/source/hg.sh.in +++ b/scripts/libmakepkg/source/hg.sh.in @@ -29,6 +29,11 @@ source "$LIBRARY/util/pkgbuild.sh" download_hg() { + # abort early if parent says not to fetch + if declare -p get_vcs > /dev/null 2>&1; then + (( get_vcs )) || return + fi + local netfile=$1 local dir=$(get_filepath "$netfile") diff --git a/scripts/libmakepkg/source/svn.sh.in b/scripts/libmakepkg/source/svn.sh.in index f98779f2..48f4f24e 100644 --- a/scripts/libmakepkg/source/svn.sh.in +++ b/scripts/libmakepkg/source/svn.sh.in @@ -29,6 +29,11 @@ source "$LIBRARY/util/pkgbuild.sh" download_svn() { + # abort early if parent says not to fetch + if declare -p get_vcs > /dev/null 2>&1; then + (( get_vcs )) || return + fi + local netfile=$1 local fragment=${netfile#*#} -- 2.20.1
Lookup the existence of matching functions for each protocol, and fallback on the generic file handler. New verification protocols can then be added via thirdparty libmakepkg drop-ins without requiring modifications to verify_signature.sh Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- scripts/libmakepkg/integrity/verify_signature.sh.in | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/libmakepkg/integrity/verify_signature.sh.in b/scripts/libmakepkg/integrity/verify_signature.sh.in index 38f8afa1..3fa5cd53 100644 --- a/scripts/libmakepkg/integrity/verify_signature.sh.in +++ b/scripts/libmakepkg/integrity/verify_signature.sh.in @@ -49,8 +49,8 @@ check_pgpsigs() { for netfile in "${all_sources[@]}"; do proto="$(get_protocol "$netfile")" - if [[ $proto = git ]]; then - verify_git_signature "$netfile" "$statusfile" || continue + if declare -f verify_${proto}_signature > /dev/null; then + verify_${proto}_signature "$netfile" "$statusfile" || continue else verify_file_signature "$netfile" "$statusfile" || continue fi @@ -263,7 +263,8 @@ source_has_signatures() { proto="$(get_protocol "$netfile")" query=$(get_uri_query "$netfile") - if [[ ${netfile%%::*} = *.@(sig?(n)|asc) || ( $proto = git && $query = signed ) ]]; then + if [[ ${netfile%%::*} = *.@(sig?(n)|asc) ]] || \ + ( declare -f verify_${proto}_signature > /dev/null && [[ $query = signed ]] ); then return 0 fi done -- 2.17.0
participants (2)
-
Allan McRae
-
Eli Schwartz