summaryrefslogtreecommitdiff
path: root/include/git.sh
diff options
context:
space:
mode:
Diffstat (limited to 'include/git.sh')
-rw-r--r--include/git.sh64
1 files changed, 38 insertions, 26 deletions
diff --git a/include/git.sh b/include/git.sh
index 58f62ef3..2c43cd22 100644
--- a/include/git.sh
+++ b/include/git.sh
@@ -2,18 +2,18 @@
# Copyright (c) 2020-2021,2023-2024 Leah Rowe <leah@libreboot.org>
# Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
-eval `setvars "" loc url bkup_url subfile mdir subhash subrepo subrepo_bkup \
- depend subfile_bkup`
+eval `setvars "" loc url bkup_url subfile subhash subrepo subrepo_bkup \
+ depend subfile_bkup repofail`
fetch_targets()
{
[ -n "$tree_depend" ] && [ "$tree_depend" != "$tree" ] && \
- x_ ./update trees -f "$project" "$tree_depend"
+ x_ ./mk -f "$project" "$tree_depend"
e "src/$project/$tree" d && return 0
printf "Creating %s tree %s\n" "$project" "$tree"
git_prep "$loc" "$loc" "$PWD/$configdir/$tree/patches" \
- "${loc%/*}/$tree" u; nuke "$project/$tree" "$project/$tree"
+ "src/$project/$tree" u; nuke "$project/$tree" "$project/$tree"
}
fetch_project()
@@ -23,10 +23,10 @@ fetch_project()
chkvars url
- [ -n "$xtree" ] && x_ ./update trees -f coreboot "$xtree"
+ [ -n "$xtree" ] && x_ ./mk -f coreboot "$xtree"
[ -z "$depend" ] || for d in $depend ; do
printf "'%s' needs '%s'; grabbing '%s'\n" "$project" "$d" "$d"
- x_ ./update trees -f $d
+ x_ ./mk -f $d
done
clone_project
@@ -37,41 +37,32 @@ fetch_project()
clone_project()
{
- loc="src/$project/$project" && singletree "$project" && loc="${loc%/*}"
-
+ loc="$XBMK_CACHE/repo/$project" && singletree "$project" && \
+ loc="src/$project"
printf "Downloading project '%s' to '%s'\n" "$project" "$loc"
- e "$loc" d && return 0
- remkdir "${tmpgit%/*}"
- git_prep "$url" "$bkup_url" "$PWD/config/$project/patches" "$loc"
+ e "$loc" d missing && remkdir "${tmpgit%/*}" && git_prep \
+ "$url" "$bkup_url" "$PWD/config/$project/patches" "$loc"; :
}
git_prep()
{
- _patchdir="$3" # $1 and $2 are gitrepo and gitrepo_backup
- _loc="$4"
-
- chkvars rev
+ _patchdir="$3"; _loc="$4" # $1 and $2 are gitrepo and gitrepo_backup
- tmpclone "$1" "$2" "$tmpgit" "$rev" "$_patchdir"
+ chkvars rev; tmpclone "$1" "$2" "$tmpgit" "$rev" "$_patchdir"
if singletree "$project" || [ $# -gt 4 ]; then
- prep_submodules "$_loc"
- fi
+ prep_submodules "$_loc"; fi
[ "$project" = "coreboot" ] && [ -n "$xtree" ] && [ $# -gt 2 ] && \
[ "$xtree" != "$tree" ] && link_crossgcc "$_loc"
-
- [ "$XBMK_RELEASE" = "y" ] && [ "$_loc" != "src/$project/$project" ] \
- && rmgit "$tmpgit"
+ [ "$XBMK_RELEASE" = "y" ] && \
+ [ "$_loc" != "$XBMK_CACHE/repo/$project" ] && rmgit "$tmpgit"
move_repo "$_loc"
}
prep_submodules()
{
- mdir="$PWD/config/submodule/$project"
- [ -n "$tree" ] && mdir="$mdir/$tree"
-
[ -f "$mdir/module.list" ] && while read -r msrcdir; do
fetch_submodule "$msrcdir"
done < "$mdir/module.list"; return 0
@@ -88,7 +79,6 @@ fetch_submodule()
_seval="if [ -n \"\$sub$xt\" ] || [ -n \"\$sub${xt}_bkup\" ]"
eval "$_seval; then st=\"\$st \$xt\"; fi"
done
-
st="${st# }" && [ "$st" = "repo file" ] && $err "$mdir: repo+file"
[ -z "$st" ] && return 0 # subrepo/subfile not defined
@@ -101,11 +91,33 @@ fetch_submodule()
"$mdir/${1##*/}/patches"
}
+livepull="n"
tmpclone()
{
- git clone $1 "$3" || git clone $2 "$3" || $err "!clone $1 $2 $3 $4 $5"
+ [ "$repofail" = "y" ] && \
+ printf "Cached clone failed; trying online.\n" 1>&2 && livepull="y"
+
+ repofail="n"
+
+ [ $# -lt 6 ] || rm -Rf "$3" || $err "git retry: !rm $3 ($1)"
+ repodir="$XBMK_CACHE/repo/${1##*/}" && [ $# -gt 5 ] && repodir="$3"
+ mkdir -p "$XBMK_CACHE/repo" || $err "!rmdir $XBMK_CACHE/repo"
+
+ if [ "$livepull" = "y" ] && [ ! -d "$repodir" ]; then
+ git clone $1 "$repodir" || git clone $2 "$repodir" || \
+ $err "!clone $1 $2 $repodir $4 $5" #
+ elif [ -d "$repodir" ] && [ $# -lt 6 ]; then
+ git -C "$repodir" pull || sleep 3 || git -C "$repodir" pull \
+ || sleep 3 || git -C "$repodir" pull || :
+ fi
+ (
+ [ $# -gt 5 ] || git clone "$repodir" "$3" || $err "!clone $repodir $3"
git -C "$3" reset --hard "$4" || $err "!reset $1 $2 $3 $4 $5"
git_am_patches "$3" "$5"
+ ) || repofail="y"
+
+ [ "$repofail" = "y" ] && [ $# -lt 6 ] && tmpclone $@ retry
+ [ "$repofail" = "y" ] && $err "!clone $1 $2 $3 $4 $5"; :
}
git_am_patches()