[pacman-dev] [PATCH v2] libmakepkg: implement extendable source protocols
Eli Schwartz
eschwartz at archlinux.org
Mon Jan 21 23:33:36 UTC 2019
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 at 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
More information about the pacman-dev
mailing list