kiss: Move all git source support to pkg_extract()

This reduces the overall code size as we no longer do an
"extraction" early in pkg_sources(). Also comes with less
network usage when a source points to a specific commit.
This commit is contained in:
Dylan Araps 2020-06-06 17:07:10 +03:00
parent 90f1057bf1
commit 427dc39a16
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E

81
kiss
View File

@ -208,54 +208,13 @@ pkg_sources() {
mkdir -p "$src_dir/$1" && cd "$src_dir/$1" mkdir -p "$src_dir/$1" && cd "$src_dir/$1"
while read -r src dest || [ "$src" ]; do while read -r src dest || [ "$src" ]; do
# Comment. # Remote git repository or comment.
if [ -z "${src##\#*}" ]; then : if [ -z "${src##\#*}" ] || [ -z "${src##git+*}" ]; then :
# Remote source (cached). # Remote source (cached).
elif [ -f "${src##*/}" ]; then elif [ -f "${src##*/}" ]; then
log "$1" "Found cached source '${src##*/}'" log "$1" "Found cached source '${src##*/}'"
# Remote git repository.
elif [ -z "${src##git+*}" ]; then
# This is a checksums check, skip it.
[ "$2" ] && continue
mkdir -p "$mak_dir/$1/$dest"
# Run in a subshell to keep the variables, path and
# argument list local to each loop iteration.
(
url=${src##git+}
log "$1" "Cloning ${url%[@#]*}"
# Git has no option to clone a repository to a
# specific location so we must do it ourselves
# beforehand.
cd "$mak_dir/$1/$dest" 2>/dev/null || die
# Clear the argument list as we'll be overwriting
# it below based on what kind of checkout we're
# dealing with.
set -- "$url"
# If a branch was given, shallow clone it directly.
# This speeds things up as we don't have to grab
# a lot of unneeded commits.
[ "${src##*@*}" ] || set -- -b "${src##*@}" "${url%@*}"
# Maintain compatibility with older versions of
# kiss by shallow cloning all branches. This has
# the added benefit of allowing checkouts of
# specific commits in specific branches.
[ "${src##*#*}" ] || set -- --no-single-branch "${url%#*}"
# Always do a shallow clone as we will unshallow it if
# needed later (when a commit is desired).
git clone --depth=1 "$@" .
) || die "$1" "Failed to clone $src"
# Remote source. # Remote source.
elif [ -z "${src##*://*}" ]; then elif [ -z "${src##*://*}" ]; then
log "$1" "Downloading $src" log "$1" "Downloading $src"
@ -288,24 +247,32 @@ pkg_extract() {
while read -r src dest || [ "$src" ]; do while read -r src dest || [ "$src" ]; do
mkdir -p "$mak_dir/$1/$dest" && cd "$mak_dir/$1/$dest" mkdir -p "$mak_dir/$1/$dest" && cd "$mak_dir/$1/$dest"
case $src in case $src in \#*|'') ;;
# Git repository with supplied commit hash. # Git repository.
git+*\#*) git+*)
log "Checking out ${src##*#}" url=${src##git+}
log "$1" "Cloning ${url%[@#]*}"
# A commit was requested, unshallow the repository. case $url in
# This will convert it to a regular repository with # If a branch was given, shallow clone it directly.
# full history. # This speeds things up as we don't have to grab
git fetch --unshallow # a lot of unneeded commits.
*'@'*) git clone --depth=1 -b "${src##*@}" "${url%@*}" . ;;
# Try to checkout the repository. If we fail here, # If a commit was given, clone all branches as the
# the requested commit doesn't exist. # given commit may not be in master.
git -c advice.detachedHead=false checkout "${src##*#}" || *'#'*)
die "Commit hash ${src##*#} doesn't exist" git clone "${url%#*}" .
git checkout "${url##*#}" ||
die "Commit hash ${url##*#} not found"
;; ;;
# Git repository, comment or blank line. # Simply shallow clone everything else.
git+*|\#*|'') ;; *) git clone --depth=1 "$url" .
esac || die "$1" "Failed to clone $src"
;;
# Tarballs of any kind. This is a shell equivalent of # Tarballs of any kind. This is a shell equivalent of
# GNU tar's '--strip-components 1'. # GNU tar's '--strip-components 1'.