# Shared by tools/build-*.sh (sourced). # clone_tag URL TAG DIR: a shallow clone of TAG into DIR, tried three times: a transfer that # stalls (GitHub's sometimes do) is given up after a minute, a connection that hangs by curl's # own timeout; a slow one is waited for. With SRC_CACHE set, a clone made is kept there and # the next build copies it rather than fetching it again (the scripts check its commit either # way). clone_tag() { local url=$1 tag=$2 dir=$3 try cached="" if [ -n "${SRC_CACHE:-}" ]; then cached="$SRC_CACHE/$(basename "$url")@$tag" if [ -d "$cached/.git" ]; then # Its files as its commit has them, whatever happened to the copy since. rm -rf "$dir" && cp -a "$cached" "$dir" && git -C "$dir" reset -q --hard && git -C "$dir" clean -qfdx && return 0 fi fi for try in 1 2 3; do rm -rf "$dir" if git -c advice.detachedHead=false -c http.lowSpeedLimit=1000 -c http.lowSpeedTime=60 \ clone -q --depth 1 --branch "$tag" "$url" "$dir"; then if [ -n "$cached" ]; then mkdir -p "$SRC_CACHE" && rm -rf "$cached.tmp" && cp -a "$dir" "$cached.tmp" && mv "$cached.tmp" "$cached" fi return 0 fi echo "cloning $url ($tag) failed, try $try of 3" >&2 sleep 5 done return 1 }