From d9109773d09ee22b30592e5241247155b2250300 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 19 Feb 2020 15:26:34 +0200 Subject: [PATCH 1/4] kiss: less git pulls --- kiss | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/kiss b/kiss index d59fc99..f698c13 100755 --- a/kiss +++ b/kiss @@ -193,10 +193,16 @@ pkg_sources() { log "$1" "Cloning ${repo_src%#*}" - [ "${src##*#*}" ] && shallow=--depth=1 + # If a commit hash or branch was given, grab the latest + # commit from all branches. This gives a speed-up when + # wanting to checkout a specific branch. + [ "${src##*#*}" ] || + branch=--no-single-branch + # Always do a shallow clone as we will unshallow it if + # needed later (when a commit is desired). cd "$mak_dir/$1/$dest" && - git clone "${shallow:---}" "${repo_src%#*}" . + git clone --depth=1 "${branch:---}" "${repo_src%#*}" . ) || die "$1" "Failed to clone $src" @@ -234,8 +240,21 @@ pkg_extract() { git+*\#*) log "Checking out ${src##*#}" - git -c advice.detachedHead=false checkout "${src##*#}" || - die "Commit hash ${src##*#} doesn't exist" + ( + set -- git -c advice.detachedHead=false checkout + + # Try to checkout the commit or branch. If it fails, + # unshallow the repository as we're dealing with a + # specific commit. + "$@" "${src##*#}" >/dev/null 2>&1 || + git fetch --unshallow + + # Checkout the repository a second time. If this + # fails, the desired commit or branch doesn't exist. + # This will do nothing if the above checkout succeeded. + "$@" "${src##*#}" 2>/dev/null || + die "${src##*#} doesn't exist" + ) ;; # Git repository, comment or blank line. From 5cfbe0277d2887059cff4f3ebf7cd2b46dbb1e7c Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 19 Feb 2020 16:11:02 +0200 Subject: [PATCH 2/4] kiss: shallow branch support --- kiss | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/kiss b/kiss index f698c13..1aed25d 100755 --- a/kiss +++ b/kiss @@ -187,22 +187,27 @@ pkg_sources() { mkdir -p "$mak_dir/$1/$dest" - # Run in a subshell to keep variables local. + # Run in a subshell to keep the variables, path and + # argument list local to each loop iteration. ( repo_src=${src##git+} - log "$1" "Cloning ${repo_src%#*}" + log "$1" "Cloning ${repo_src%[@#]*}" - # If a commit hash or branch was given, grab the latest - # commit from all branches. This gives a speed-up when - # wanting to checkout a specific branch. - [ "${src##*#*}" ] || - branch=--no-single-branch + # Git has no option to clone a repository to a + # specific location so we must do it ourselves + # beforehand. + cd "$mak_dir/$1/$dest" || die 2>/dev/null + + # 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 -- || + set -- -b "${src##*@}" "${repo_src%@*}" # Always do a shallow clone as we will unshallow it if # needed later (when a commit is desired). - cd "$mak_dir/$1/$dest" && - git clone --depth=1 "${branch:---}" "${repo_src%#*}" . + git clone --depth=1 "${@:-${repo_src%#*}}" . ) || die "$1" "Failed to clone $src" @@ -241,19 +246,15 @@ pkg_extract() { log "Checking out ${src##*#}" ( - set -- git -c advice.detachedHead=false checkout + # A commit was requested, unshallow the repository. + # This will convert it to a regular repository with + # full history. + git fetch --unshallow - # Try to checkout the commit or branch. If it fails, - # unshallow the repository as we're dealing with a - # specific commit. - "$@" "${src##*#}" >/dev/null 2>&1 || - git fetch --unshallow - - # Checkout the repository a second time. If this - # fails, the desired commit or branch doesn't exist. - # This will do nothing if the above checkout succeeded. - "$@" "${src##*#}" 2>/dev/null || - die "${src##*#} doesn't exist" + # Try to checkout the repository. If we fail here, + # the requested commit doesn't exist. + git -c advice.detachedHead=false checkout "${src##*#}" || + die "Commit hash ${src##*#} doesn't exist" ) ;; From 1787cbe5b05267b97d2970ee83c89a19f5164794 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 19 Feb 2020 16:13:15 +0200 Subject: [PATCH 3/4] kiss: remove left over subshell --- kiss | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/kiss b/kiss index 1aed25d..a59a502 100755 --- a/kiss +++ b/kiss @@ -245,17 +245,15 @@ pkg_extract() { git+*\#*) log "Checking out ${src##*#}" - ( - # A commit was requested, unshallow the repository. - # This will convert it to a regular repository with - # full history. - git fetch --unshallow + # A commit was requested, unshallow the repository. + # This will convert it to a regular repository with + # full history. + git fetch --unshallow - # Try to checkout the repository. If we fail here, - # the requested commit doesn't exist. - git -c advice.detachedHead=false checkout "${src##*#}" || - die "Commit hash ${src##*#} doesn't exist" - ) + # Try to checkout the repository. If we fail here, + # the requested commit doesn't exist. + git -c advice.detachedHead=false checkout "${src##*#}" || + die "Commit hash ${src##*#} doesn't exist" ;; # Git repository, comment or blank line. From 9d3252cb59fdba96ef104044c512484ead2e1b76 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 19 Feb 2020 16:28:44 +0200 Subject: [PATCH 4/4] kiss: Fix old behavior --- kiss | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/kiss b/kiss index a59a502..956d2d5 100755 --- a/kiss +++ b/kiss @@ -199,15 +199,27 @@ pkg_sources() { # beforehand. cd "$mak_dir/$1/$dest" || die 2>/dev/null + # Clear the argument list as we'll be overwriting + # it below based on what kind of checkout we're + # dealing with. + set -- "$repo_src" + # 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 -- || + [ "${src##*@*}" ] || set -- -b "${src##*@}" "${repo_src%@*}" + # 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 "${repo_src%#*}" + # Always do a shallow clone as we will unshallow it if # needed later (when a commit is desired). - git clone --depth=1 "${@:-${repo_src%#*}}" . + git clone --depth=1 "$@" . ) || die "$1" "Failed to clone $src"