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:
parent
f0226ed24e
commit
5609b17e9e
|
|
@ -315,21 +315,27 @@ create_sources_list()
|
||||||
#
|
#
|
||||||
improved_git()
|
improved_git()
|
||||||
{
|
{
|
||||||
|
local realgit
|
||||||
local realgit=$(command -v git)
|
realgit=$(command -v git)
|
||||||
local retries=3
|
local retries=3
|
||||||
local delay=10
|
local delay=10
|
||||||
local count=1
|
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
|
while [ $count -lt $retries ]; do
|
||||||
$realgit "$@"
|
$realgit -c http.version=HTTP/1.1 -c http.lowSpeedLimit=0 -c http.lowSpeedTime=0 "$@"
|
||||||
if [[ $? -eq 0 || -f .git/index.lock ]]; then
|
last_status=$?
|
||||||
retries=0
|
if [[ $last_status -eq 0 || -f .git/index.lock ]]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
let count=$count+1
|
let count=$count+1
|
||||||
sleep $delay
|
sleep $delay
|
||||||
done
|
done
|
||||||
|
|
||||||
|
return $last_status
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clean_up_git ()
|
clean_up_git ()
|
||||||
|
|
@ -630,14 +636,26 @@ fetch_from_repo()
|
||||||
fi # offline
|
fi # offline
|
||||||
|
|
||||||
if [[ $changed == true ]]; then
|
if [[ $changed == true ]]; then
|
||||||
|
local fetch_depth=${GIT_FETCH_DEPTH:-200}
|
||||||
|
|
||||||
# remote was updated, fetch and check out updates
|
# remote was updated, fetch and check out updates
|
||||||
display_alert "Fetching updates"
|
display_alert "Fetching updates"
|
||||||
case $ref_type in
|
case $ref_type in
|
||||||
branch) improved_git fetch --depth 200 origin "${ref_name}" ;;
|
branch) improved_git fetch --depth "${fetch_depth}" origin "${ref_name}" ;;
|
||||||
tag) improved_git fetch --depth 200 origin tags/"${ref_name}" ;;
|
tag) improved_git fetch --depth "${fetch_depth}" origin tags/"${ref_name}" ;;
|
||||||
head) improved_git fetch --depth 200 origin HEAD ;;
|
head) improved_git fetch --depth "${fetch_depth}" origin HEAD ;;
|
||||||
esac
|
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
|
# commit type needs support for older git servers that doesn't support fetching id directly
|
||||||
if [[ $ref_type == commit ]]; then
|
if [[ $ref_type == commit ]]; then
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue