Commit 1edaddeacb51032df741a44b72a0d3a8ef839078

Thomas de Grivel 2023-02-13T19:33:51

colors

diff --git a/share/shpkg/shpkg.subr b/share/shpkg/shpkg.subr
index 44f1c95..14883c0 100644
--- a/share/shpkg/shpkg.subr
+++ b/share/shpkg/shpkg.subr
@@ -21,17 +21,21 @@ SHPKG_PREFIX="${SHPKG_DIR}"
 
 # Console output
 
+SHPKG_COLOR_BLUE="$(printf '\33[0;34m')"
+SHPKG_COLOR_PURPLE="$(printf '\33[0;35m')"
+SHPKG_COLOR_RESET="$(printf '\33[0m\n')"
+
 verbose__puts () {
     if [ "x$1" = "x1" ]; then
-        printf '\33[0;34m'
+        echo -n "${SHPKG_COLOR_BLUE}"
     elif [ "x$1" = "x2" ]; then
-        printf '\33[0;35m'
+        echo -n "${SHPKG_COLOR_PURPLE}"
     else
         err 1 "bad verbose level"
     fi
     shift
     echo -n "$@"
-    printf '\33[0m\n'
+    echo "${SHPKG_COLOR_RESET}"
 }
 
 verbose () {
@@ -216,7 +220,7 @@ shpkg_checkout () {
               verbose 1 git submodule update; )
         SHPKG_REPO_VERSION_B="$(shpkg_version "${SHPKG_REPO}")"
         if [ "x${SHPKG_REPO_VERSION_A}" != "x${SHPKG_REPO_VERSION_B}" ]; then
-            verbose 2 shpkg_tag_log "${SHPKG_REPO}.checkout"
+            ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.checkout"; )
         fi
     done
 }
@@ -232,7 +236,7 @@ shpkg_clone () {
         SHPKG_REPO_GIT_URL="$(shpkg_git_url "${SHPKG_REPO}")"
         SHPKG_REPO_BASENAME="$(basename "${SHPKG_REPO_DIR}")"
         if ! [ -d "${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}" ]; then
-            verbose 2 shpkg_tag_log "${SHPKG_REPO}.clone"
+            ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.clone"; )
             verbose 1 mkdir -p "${SHPKG_SRC_DIR}/${SHPKG_REPO_PARENT_DIR}"
             ( verbose 1 cd "${SHPKG_SRC_DIR}/${SHPKG_REPO_PARENT_DIR}" &&
                   verbose 1 git clone "${SHPKG_REPO_GIT_URL}" -b "${SHPKG_REPO_GIT_BRANCH}" "${SHPKG_REPO_BASENAME}" &&
@@ -240,6 +244,9 @@ shpkg_clone () {
                   verbose 1 git submodule init &&
                   verbose 1 git submodule update
             )
+            SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
+            ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.tree_${SHPKG_REPO_GIT_BRANCH}.log"; )
+            ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.version_${SHPKG_REPO_VERSION}.log"; )
         fi
     done
 }
@@ -255,7 +262,7 @@ shpkg_fetch () {
               verbose -n 1 git fetch --recurse-submodules --tags &&
               git fetch --recurse-submodules --tags | tee "${SHPKG_REPO_LOG_FETCH}"; )
         if [ -s "${SHPKG_REPO_LOG_FETCH}" ]; then
-            verbose 2 shpkg_tag_log "${SHPKG_REPO}.fetch.log"
+            ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.fetch.log"; )
         fi
     done
 }
@@ -271,8 +278,11 @@ shpkg_pull () {
               verbose 1 git pull &&
               verbose 1 git submodule update; )
         SHPKG_REPO_VERSION_B="$(shpkg_version "${SHPKG_REPO}")"
+        SHPKG_REPO_VERSION_B_TREE="$(echo "${SHPKG_REPO_VERSION_B}" | cut -d - -f 1)"
         if [ "x${SHPKG_REPO_VERSION_A}" != "x${SHPKG_REPO_VERSION_B}" ]; then
-            verbose 2 shpkg_tag_log "${SHPKG_REPO}.pull"
+            ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.pull.log"; )
+            ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.tree_${SHPKG_REPO_VERSION_B_TREE}.log"; )
+            ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.version_${SHPKG_REPO_VERSION_B}.log"; )
         fi
     done
 }
@@ -332,6 +342,7 @@ shpkg_build () {
         SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
 	if shpkg__tag_is_absent build-done; then
 	    ( verbose 2 shpkg_configure "${SHPKG_REPO}"; )
+            ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.build.log"; )
             SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
             if [ -f "${SHPKG_REPO_SRC_DIR}/Makefile" ]; then
 		( verbose 1 cd "${SHPKG_REPO_SRC_DIR}" &&
@@ -391,6 +402,7 @@ shpkg_configure () {
         SHPKG_REPO_SRC_DIR="${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}"
         SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
 	if shpkg__tag_is_absent configure-done; then
+            ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.configure.log"; )
             ( verbose 2 shpkg_autogen "${SHPKG_REPO}"; )
             SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
             if ! [ -d "${SHPKG_REPO_FAKE_DIR}" ]; then
@@ -416,6 +428,7 @@ shpkg_fake () {
         SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
         SHPKG_REPO_FAKE_DIR="$(shpkg_fake_dir "${SHPKG_REPO}")"
         SHPKG_REPO_SRC_DIR="${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}"
+        ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.fake.log"; )
         if [ -d "${SHPKG_REPO_FAKE_DIR}" ]; then
 	    verbose 1 rm -rf "${SHPKG_REPO_FAKE_DIR}"
 	fi
@@ -442,6 +455,7 @@ shpkg_package () {
         SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
         SHPKG_REPO_PACKAGE="${SHPKG_PACKAGE_DIR}/${SHPKG_REPO_DIR}-${SHPKG_REPO_VERSION}.tgz"
 	if ! [ -f "${SHPKG_REPO_PACKAGE}" ]; then
+            ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.package.log"; )
             SHPKG_REPO_FAKE_DIR="$(shpkg_fake_dir "${SHPKG_REPO}")"
 	    verbose 2 shpkg_fake "${SHPKG_REPO}"
             SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
@@ -533,7 +547,7 @@ shpkg_install () {
 	    SHPKG_REPO_INSTALLED="${SHPKG_VAR_DB_DIR}/installed/${SHPKG_REPO_DIR}"
 	    SHPKG_REPO_INSTALLED_DIR="$(dirname "${SHPKG_REPO_INSTALLED}")"
 	    if ! shpkg_is_installed "${SHPKG_REPO}"; then
-                verbose 2 shpkg_tag_log "${SHPKG_REPO}.install.log"
+                ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.install.log"; )
 	        ( verbose 2 shpkg_install_dependencies "${SHPKG_REPO}"; )
 	        ( verbose 2 shpkg_build "${SHPKG_REPO}"; )
 	        ( verbose 2 shpkg_package "${SHPKG_REPO}"; )
@@ -601,7 +615,7 @@ shpkg_uninstall () {
         fi
 	SHPKG_REPO_INSTALLED="${SHPKG_VAR_DB_DIR}/installed/${SHPKG_REPO_DIR}"
         if [ -f "${SHPKG_REPO_INSTALLED}" ]; then
-            verbose 2 shpkg_tag_log "${SHPKG_REPO}.uninstall.log"
+            ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.uninstall.log"; )
             verbose 1 cd "${SHPKG_DIR}"
             grep -v : "${SHPKG_REPO_INSTALLED}" |
                 cut -d '(' -f 2 |
@@ -634,7 +648,7 @@ shpkg_upgrade_rec () {
         if ! shpkg_is_system_package "${SHPKG_REPO_DIR}"; then
             verbose 2 shpkg_pull "${SHPKG_REPO}"
             if ! shpkg_latest_is_installed "${SHPKG_REPO}"; then
-                verbose 2 shpkg_tag_log "${SHPKG_REPO}.upgrade.log"
+                ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.upgrade.log"; )
                 verbose 2 shpkg_build "${SHPKG_REPO}"
                 verbose 2 shpkg_package "${SHPKG_REPO}"
                 verbose 2 shpkg_uninstall "${SHPKG_REPO}"