Procházet zdrojové kódy

Speedup subtree splitting by caching last split hash

Willy-JL před 1 rokem
rodič
revize
63775ca8ef
2 změnil soubory, kde provedl 22 přidání a 9 odebrání
  1. 1 0
      .gitignore
  2. 21 9
      .utils/subtree-subdir-helper.sh

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 /.vscode/
 /venv/
+.subtree-cache/

+ 21 - 9
.utils/subtree-subdir-helper.sh

@@ -21,13 +21,25 @@ temp="$(rev <<< "${repo%/}" | cut -d/ -f1,2 | rev | tr / -)-${branch}"
 fetch="_fetch-${temp}"
 split="_split-${temp}-$(tr / - <<< "${subdir}")"
 git fetch --no-tags "${repo}" "${branch}:${fetch}"
-git checkout "${fetch}"
-exec 420>&1
-result="$(git subtree split -P "${subdir}" -b "${split}" 2>&1 | tee /proc/self/fd/420)"
-if grep "is not an ancestor of commit" <<< "$result" > /dev/null; then
-    echo "Resetting split branch..."
-    git branch -D "${split}"
-    git subtree split -P "${subdir}" -b "${split}"
+mkdir -p "${path}/.subtree-cache"
+cache="${path}/.subtree-cache/${split}"
+hash="$(git rev-parse ${fetch})"
+skip=false
+if [ -f "${cache}" ]; then
+    if [ "$(<${cache})" = "${hash}" ]; then
+        skip=true
+    fi
 fi
-git checkout "${prev}"
-git subtree "${action}" -P "${path}" "${split}" -m "${action^} ${path} from ${repo}"
+if ! $skip; then
+    git checkout "${fetch}"
+    exec {capture}>&1
+    result="$(git subtree split -P "${subdir}" -b "${split}" 2>&1 | tee /proc/self/fd/$capture)"
+    if grep "is not an ancestor of commit" <<< "$result" > /dev/null; then
+        echo "Resetting split branch..."
+        git branch -D "${split}"
+        git subtree split -P "${subdir}" -b "${split}"
+    fi
+    git checkout "${prev}"
+    git subtree "${action}" -P "${path}" "${split}" -m "${action^} ${path} from ${repo}"
+fi
+echo "${hash}" > "${cache}"