build: make git fetch resilient on slow links

- improved_git now returns real git exit code; prefers HTTP/1.1
- fetch_from_repo retries fetch with depth=1 once and fails fast on fetch errors
This commit is contained in:
OrangePi CM5 Builder 2026-04-09 19:27:57 +08:00
parent f0226ed24e
commit 5609b17e9e
1 changed files with 28 additions and 10 deletions

View File

@ -315,21 +315,27 @@ create_sources_list()
#
improved_git()
{
local realgit=$(command -v git)
local realgit
realgit=$(command -v git)
local retries=3
local delay=10
local count=1
local last_status=0
# Prefer HTTP/1.1 for stability on flaky links.
# Also disable low-speed aborts (many environments have very low throughput).
while [ $count -lt $retries ]; do
$realgit "$@"
if [[ $? -eq 0 || -f .git/index.lock ]]; then
retries=0
$realgit -c http.version=HTTP/1.1 -c http.lowSpeedLimit=0 -c http.lowSpeedTime=0 "$@"
last_status=$?
if [[ $last_status -eq 0 || -f .git/index.lock ]]; then
break
fi
let count=$count+1
sleep $delay
let count=$count+1
sleep $delay
done
return $last_status
}
clean_up_git ()
@ -630,14 +636,26 @@ fetch_from_repo()
fi # offline
if [[ $changed == true ]]; then
local fetch_depth=${GIT_FETCH_DEPTH:-200}
# remote was updated, fetch and check out updates
display_alert "Fetching updates"
case $ref_type in
branch) improved_git fetch --depth 200 origin "${ref_name}" ;;
tag) improved_git fetch --depth 200 origin tags/"${ref_name}" ;;
head) improved_git fetch --depth 200 origin HEAD ;;
branch) improved_git fetch --depth "${fetch_depth}" origin "${ref_name}" ;;
tag) improved_git fetch --depth "${fetch_depth}" origin tags/"${ref_name}" ;;
head) improved_git fetch --depth "${fetch_depth}" origin HEAD ;;
esac
local fetch_status=$?
if [[ $fetch_status -ne 0 && "${fetch_depth}" != "1" ]]; then
display_alert "Fetch failed; retrying with depth=1" "${workdir}" "wrn"
case $ref_type in
branch) improved_git fetch --depth 1 origin "${ref_name}" ;;
tag) improved_git fetch --depth 1 origin tags/"${ref_name}" ;;
head) improved_git fetch --depth 1 origin HEAD ;;
esac
fetch_status=$?
fi
[[ $fetch_status -ne 0 ]] && exit_with_error "Failed to fetch git sources" "${url} ${ref}"
# commit type needs support for older git servers that doesn't support fetching id directly
if [[ $ref_type == commit ]]; then