summaryrefslogtreecommitdiff
path: root/include/get.sh
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2025-10-16 00:26:46 +0100
committerLeah Rowe <leah@libreboot.org>2025-10-16 13:29:59 +0100
commitd83dd506c2b8a5846e2f6a07cbd93ef6ba37ded9 (patch)
tree66ec3e400336288d9c58e957ddb861439bf4adb4 /include/get.sh
parent18c63682e7a1e7b90ade549d5c84a3c3e4dcdccd (diff)
get.sh: More reliable git remote caching
Don't do one repository for all remotes. Do one *clone* per remote. This also means that users no longer download information twice, in practice, because the backup repository will only be downloaded if the main one didn't work. Theoretically, this change is makes the process less efficient, but in practise it's more reliable now. We do now use --mirror on the git clone command for caches, but we already did git pull --all before. This just ensures that we absolutely have all local code. NOTE: The new code isn't used by default. To use it, you must do: export XBMK_CACHE_MIRROR="y" Otherwise, the old behaviour will continue to be used. This is because the new code, while correct, puts more strain on upstream servers (more code being downloaded), and can result in higher amounts of disk space being used. The old behaviour wasn't broken, so we'll also support that method. TODO: perhaps also have a check in place to re-use both caches, where available, regardless of XBMK_CACHE_MIRROR? Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'include/get.sh')
-rw-r--r--include/get.sh54
1 files changed, 42 insertions, 12 deletions
diff --git a/include/get.sh b/include/get.sh
index 4731c694..35cf2dbf 100644
--- a/include/get.sh
+++ b/include/get.sh
@@ -52,7 +52,9 @@ fetch_project()
clone_project()
{
- loc="$XBMK_CACHE/clone/$project"
+ # if loc is blank, don't create a target
+ # directory; just update the caches
+ loc=""
if singletree "$project"; then
loc="src/$project"
fi
@@ -83,7 +85,17 @@ git_prep()
if [ "$_loc" != "${_loc%/*}" ]; then
x_ xbmkdir "${_loc%/*}"
fi
- x_ mv "$tmpgit" "$_loc"
+
+ if [ -z "$_loc" ]; then
+ # we only used git_prep to update caches, on
+ # a multi-tree project. tmpgit is useless now.
+
+ x_ rm -Rf "$tmpgit"
+ else
+ # actual downloaded
+
+ x_ mv "$tmpgit" "$_loc"
+ fi
}
fetch_submodule()
@@ -191,11 +203,19 @@ try_fetch()
try_fetch_git()
{
- # always the main repo as basis for naming,
- # in case the backup has another name
+ if [ "$XBMK_CACHE_MIRROR" = "y" ]; then
+ # 1st argument $1 is the current git remote being tried,
+ # let's say it was https://foo.example.com/repo, then cached
+ # directories becomes cache/mirror/foo.example.com/repo
- cached="clone/${3##*/}"
- cached="${cached%.git}"
+ cached="mirror/${1#*://}"
+ else
+ # always the main repo as basis for naming,
+ # in case the backup has another name
+
+ cached="clone/${3##*/}"
+ cached="${cached%.git}"
+ fi
cached="$XBMK_CACHE/$cached"
x_ xbmkdir "${5%/*}" "${cached%/*}"
@@ -282,7 +302,12 @@ try_git()
x_ rm -Rf "$tmpgitcache"
if [ ! -d "$gitdest" ]; then
- ( x_ git clone "$2" "$tmpgitcache" ) || return 1
+ if [ "$XBMK_CACHE_MIRROR" = "y" ]; then
+ ( x_ git clone --mirror "$2" "$tmpgitcache" ) || \
+ return 1
+ else
+ ( x_ git clone "$2" "$tmpgitcache" ) || return 1
+ fi
x_ xbmkdir "${gitdest%/*}"
x_ mv "$tmpgitcache" "$gitdest"
@@ -298,13 +323,18 @@ try_git()
return 0
fi
- ( x_ git -C "$gitdest" remote remove main ) || :
- ( x_ git -C "$gitdest" remote remove backup ) || :
+ if [ "$XBMK_CACHE_MIRROR" = "y" ]; then
+ ( x_ git -C "$gitdest" fetch ) || :; :
+ ( x_ git -C "$gitdest" update-server-info ) || :; :
+ else
+ ( x_ git -C "$gitdest" remote remove main ) || :
+ ( x_ git -C "$gitdest" remote remove backup ) || :
- x_ git -C "$gitdest" remote add main "$4"
- x_ git -C "$gitdest" remote add backup "$5"
+ x_ git -C "$gitdest" remote add main "$4"
+ x_ git -C "$gitdest" remote add backup "$5"
- ( x_ git -C "$gitdest" pull --all ) || :; :
+ ( x_ git -C "$gitdest" pull --all ) || :; :
+ fi
}
bad_checksum()