From 755838425ff669264fdfc73dc6af8431ad08b545 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 25 Aug 2021 09:21:57 +0300 Subject: [PATCH 1/7] kiss: git caching --- kiss | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/kiss b/kiss index f53fc30..f2d5dea 100755 --- a/kiss +++ b/kiss @@ -358,6 +358,8 @@ pkg_source_resolve() { # Git repository. if null "${2##git+*}"; then _res=$2 + _des=$src_dir/$1/${3:+"$3/"}${2##*/} + _des=${_des%[@#]*} # Remote source (cached). elif [ -f "$src_dir/$1/${3:+"$3/"}${2##*/}" ]; then @@ -410,12 +412,16 @@ pkg_source() { # arg4: resolved source run_hook pre-source "$1" "$src" "$_fnr" - case $_res in url+*) - # Create directory structure in source cache. This prevents cache - # conflicts between identical sources with differing dests. - mkcd "${_des%/*}" + case $_res in + url+*) + mkcd "${_des%/*}" + pkg_source_get "$_des" "${_res##url+}" + ;; - pkg_source_get "$_des" "${_res##url+}" + git+*) + mkcd "$_des" + pkg_source_git "${_res##git+}" + ;; esac # arg1: post-source @@ -443,19 +449,21 @@ pkg_source_get() { } pkg_source_git() { - # This magic will shallow clone branches, commits or the - # regular repository. It correctly handles cases where a - # shallow clone is not possible. - log "$repo_name" "Cloning $1" + com=${1##*[@#]} + com=${com#${1%[#@]*}} - # Split the source into URL + OBJECT (branch or commit). - url=$1 - com=${url##*[@#]} - com=${com#${url%[#@]*}} + log "$repo_name" "Checking out ${com:-FETCH_HEAD}" + + [ -d .git ] || { + git init + git remote add origin "${1%[#@]*}" + } + + # Only fetch latest changes if not [#]. + case $1 in *"#$com") ;; *) + git fetch -t --filter=tree:0 origin "$com" || git fetch -t + esac - git init - git remote add origin "${url%[#@]*}" - git fetch -t --filter=tree:0 origin "$com" || git fetch -t git -c advice.detachedHead=0 checkout "${com:-FETCH_HEAD}" } @@ -527,7 +535,7 @@ pkg_extract() { case $_res in git+*) - pkg_source_git "${_res##git+}" + cp -LRf "$_des/." . ;; *.tar|*.tar.??|*.tar.???|*.tar.????|*.t?z) From c84775c152fe56c27b8475764c9c499fd2d2779d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 25 Aug 2021 14:29:39 +0300 Subject: [PATCH 2/7] kiss: handle remote swaps --- kiss | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kiss b/kiss index f2d5dea..4922931 100755 --- a/kiss +++ b/kiss @@ -454,10 +454,10 @@ pkg_source_git() { log "$repo_name" "Checking out ${com:-FETCH_HEAD}" - [ -d .git ] || { - git init + [ -d .git ] || git init + + git remote set-url origin "${1%[#@]*}" 2>/dev/null || git remote add origin "${1%[#@]*}" - } # Only fetch latest changes if not [#]. case $1 in *"#$com") ;; *) From e58a0f4f0b7ba7456c8d51f90e92fbe07070d8fd Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 25 Aug 2021 14:32:25 +0300 Subject: [PATCH 3/7] kiss: don't clone git repositories for kiss c --- kiss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kiss b/kiss index 4922931..ca26a12 100755 --- a/kiss +++ b/kiss @@ -412,8 +412,8 @@ pkg_source() { # arg4: resolved source run_hook pre-source "$1" "$src" "$_fnr" - case $_res in - url+*) + case $2$_res in + "$2url+"*) mkcd "${_des%/*}" pkg_source_get "$_des" "${_res##url+}" ;; From 47a4b2b769428cd26051348d366198d2058fd0e1 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 25 Aug 2021 17:09:37 +0300 Subject: [PATCH 4/7] kiss: add comment --- kiss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kiss b/kiss index ca26a12..78cdba3 100755 --- a/kiss +++ b/kiss @@ -412,6 +412,8 @@ pkg_source() { # arg4: resolved source run_hook pre-source "$1" "$src" "$_fnr" + # '$2' is set when this function is called from 'kiss c' and it is used + # here to skip calling the Git code. case $2$_res in "$2url+"*) mkcd "${_des%/*}" From 29c57a0115f868c00b7cd1ea6a854a6fafac29ec Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 25 Aug 2021 19:02:25 +0300 Subject: [PATCH 5/7] kiss: unify pkg_source_ --- kiss | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/kiss b/kiss index 78cdba3..4b23b88 100755 --- a/kiss +++ b/kiss @@ -358,7 +358,7 @@ pkg_source_resolve() { # Git repository. if null "${2##git+*}"; then _res=$2 - _des=$src_dir/$1/${3:+"$3/"}${2##*/} + _des=$src_dir/$1/${3:+"$3/"}${2##*/}/ _des=${_des%[@#]*} # Remote source (cached). @@ -414,16 +414,9 @@ pkg_source() { # '$2' is set when this function is called from 'kiss c' and it is used # here to skip calling the Git code. - case $2$_res in - "$2url+"*) - mkcd "${_des%/*}" - pkg_source_get "$_des" "${_res##url+}" - ;; - - git+*) - mkcd "$_des" - pkg_source_git "${_res##git+}" - ;; + case $2$_res in "$2url+"*|git+*) + mkcd "${_des%/*}" + "pkg_source_${_res%%+*}" "$_des" "${_res##"${_res%%+*}+"}" esac # arg1: post-source @@ -434,7 +427,7 @@ pkg_source() { done < "$repo_dir/sources" } -pkg_source_get() { +pkg_source_url() { log "$repo_name" "Downloading $2" # Set the arguments based on found download utility. From 4de7a6ffb4fe18d8d9f60795a463865df28391e4 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 25 Aug 2021 19:16:07 +0300 Subject: [PATCH 6/7] kiss: fix git --- kiss | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kiss b/kiss index 4b23b88..5a7d67e 100755 --- a/kiss +++ b/kiss @@ -444,18 +444,18 @@ pkg_source_url() { } pkg_source_git() { - com=${1##*[@#]} - com=${com#${1%[#@]*}} + com=${2##*[@#]} + com=${com#${2%[#@]*}} log "$repo_name" "Checking out ${com:-FETCH_HEAD}" [ -d .git ] || git init - git remote set-url origin "${1%[#@]*}" 2>/dev/null || - git remote add origin "${1%[#@]*}" + git remote set-url origin "${2%[#@]*}" 2>/dev/null || + git remote add origin "${2%[#@]*}" # Only fetch latest changes if not [#]. - case $1 in *"#$com") ;; *) + case $2 in *"#$com") ;; *) git fetch -t --filter=tree:0 origin "$com" || git fetch -t esac From ea9d8e7ad5da6ef0567e140a503cc34b546b5743 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 25 Aug 2021 19:20:28 +0300 Subject: [PATCH 7/7] kiss: fix bug with mkcd --- kiss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kiss b/kiss index 5a7d67e..544288c 100755 --- a/kiss +++ b/kiss @@ -358,8 +358,8 @@ pkg_source_resolve() { # Git repository. if null "${2##git+*}"; then _res=$2 - _des=$src_dir/$1/${3:+"$3/"}${2##*/}/ - _des=${_des%[@#]*} + _des=$src_dir/$1/${3:+"$3/"}${2##*/} + _des=${_des%[@#]*}/ # Remote source (cached). elif [ -f "$src_dir/$1/${3:+"$3/"}${2##*/}" ]; then