Commit a1818e1cb585c3327ff0d07c076b666fe8534286

Thomas de Grivel 2023-02-13T17:46:07

wip shpkg_tag_log

diff --git a/bin/shpkg b/bin/shpkg
index a43680d..598168a 100755
--- a/bin/shpkg
+++ b/bin/shpkg
@@ -18,7 +18,7 @@ usage () {
     echo "Usage: shpkg OPERATION PKG ...
 
 Source directory operations :
- checkout         shortcut for git checkout
+ checkout TREE    shortcut for git checkout
  clone            shortcut for git clone
  fetch            shortcut for git fetch
  pull             shortcut for git pull
diff --git a/share/shpkg/shpkg.subr b/share/shpkg/shpkg.subr
index 8d06a90..2c979fe 100644
--- a/share/shpkg/shpkg.subr
+++ b/share/shpkg/shpkg.subr
@@ -59,20 +59,25 @@ err () {
 # Logging
 
 shpkg_start_logging () {
-    SHPKG_LOG="${SHPKG_LOG_DIR}/all/shpkg_${SHPKG_DATE}_$$.log"
+    SHPKG_LOG_ALL_DIR="${SHPKG_LOG_DIR}/all"
+    SHPKG_LOG="${SHPKG_LOG_ALL_DIR}/shpkg_${SHPKG_DATE}_$$.log"
     SHPKG_LOG_RELATIVE="../all/$(basename "${SHPKG_LOG}")"
     SHPKG_LOG_TAGS_DIR="${SHPKG_LOG_DIR}/tags"
-    if ! [ -d "${SHPKG_LOG_DIR}" ]; then
-        verbose 1 mkdir -p "${SHPKG_LOG_DIR}"
-    fi
+    SHPKG_LOG_TMP_DIR="${SHPKG_LOG_DIR}/tmp"
     if [ -f "${SHPKG_LOG}" ]; then
         err 1 "log file already present"
     fi
+    if ! [ -d "${SHPKG_LOG_ALL_DIR}" ]; then
+        verbose 1 mkdir -p "${SHPKG_LOG_ALL_DIR}"
+    fi
     {
         verbose -n 2 "shpkg_start_logging: see log with less -R ${SHPKG_LOG}"
         if ! [ -d "${SHPKG_LOG_TAGS_DIR}" ]; then
             verbose 1 mkdir -p "${SHPKG_LOG_TAGS_DIR}"
         fi
+        if ! [ -d "${SHPKG_LOG_TMP_DIR}" ]; then
+            verbose 1 mkdir -p "${SHPKG_LOG_TMP_DIR}"
+        fi
     } | tee "${SHPKG_LOG}"
 }
 
@@ -229,6 +234,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 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}" &&
@@ -243,12 +249,16 @@ shpkg_clone () {
 shpkg_fetch () {
     for SHPKG_REPO; do
         SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
+        SHPKG_REPO_LOG_FETCH="${SHPKG_LOG_TMP_DIR}/${SHPKG_REPO}.fetch.log"
         if [ "x${SHPKG_REPO_DIR}" = "x" ]; then
             err 1 "shpkg_fetch: unknown repo: $SHPKG_REPO"
         fi
         ( verbose 1 cd "${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}" &&
-              verbose 1 git fetch --recurse-submodules --tags
-        )
+              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"
+        fi
     done
 }
 
@@ -258,9 +268,14 @@ shpkg_pull () {
         if [ "x${SHPKG_REPO_DIR}" = "x" ]; then
             err 1 "shpkg_pull: unknown repo: $SHPKG_REPO"
         fi
+        SHPKG_REPO_VERSION_A="$(shpkg_version "${SHPKG_REPO}")"
         ( verbose 1 cd "${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}" &&
               verbose 1 git pull &&
               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}.pull"
+        fi
     done
 }