Skip to content

Commit 80a77f4

Browse files
committed
pacman-helper quick_add: allow for concurrent deployments
It is completely normal to have multiple concurrent deployments, say, `mingw-w64-curl` and `mingw-w64-git-extra`. This means that `pacman-helper quick_add` might update a branch locally that cannot be pushed because another deployment has already pushed the branch in the meantime. This is not a problem, as long as the deployments touch separate packages. In that instance, we simply need to revert the changes to the package database, then rebase to the latest commit from the public `pacman-repo` repository, and try again. Note: Currently this situation cannot even occur because we're doing the dual deployment both to Azure Blobs as well as to `pacman-repo`, and the former is protected against concurrent deployments via the lease mechanism. Nevertheless, it is a good idea to make the code ready for the day when we no longer deploy to Azure Blobs. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 94dde8c commit 80a77f4

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

pacman-helper.sh

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,62 @@ quick_add () { # <file>...
402402
fi &&
403403
extra_header="http.extraHeader=Authorization: Basic $auth" ||
404404
die "Could not configure auth header for git-for-windows/pacman-repo"
405-
git -C "$dir" -c "$extra_header" push origin $to_push ||
406-
die "Could not push to git-for-windows/pacman-repo"
405+
if ! git -C "$dir" -c "$extra_header" push origin $to_push
406+
then
407+
# We must assume that another deployment happened concurrently.
408+
# No matter, we can easily adjust to that by reverting the
409+
# changes to the database and then trying again
410+
echo "There was a problem with the push; Assuming it was a concurrent update..." >&2
411+
for backoff in 5 10 15 20 -1
412+
do
413+
git -C "$dir" fetch origin $architectures || die "Could not update $dir"
414+
for arch in $to_push
415+
do
416+
# Avoid updating the branch if it is not necessary
417+
test 0 -lt $(git -C "$dir" rev-list --count $arch..origin/$arch) || continue
418+
419+
echo "Rebasing $arch" >&2
420+
(cd "$dir/$arch" &&
421+
git -C "$dir/$arch" checkout HEAD^ -- 'git-for-windows*.db*' 'git-for-windows*.files*' &&
422+
git -C "$dir/$arch" commit --amend --no-edit &&
423+
git -C "$dir/$arch" rebase origin/$arch &&
424+
425+
eval "msys=\$${arch}_msys" &&
426+
eval "mingw=\$${arch}_mingw" &&
427+
printf '%s\n' $msys $mingw |
428+
sed 's/-[^-]*-[^-]*-[^-]*\.pkg\.tar\.\(xz\|zst\)$/-[0-9]*/' |
429+
xargs -r git restore --ignore-skip-worktree-bits -- &&
430+
431+
repo_add $sign_option git-for-windows-$arch.db.tar.xz $msys $mingw &&
432+
{ test ! -h git-for-windows-$arch.db || rm git-for-windows-$arch.db; } &&
433+
cp git-for-windows-$arch.db.tar.xz git-for-windows-$arch.db && {
434+
test -z "$sign_option" || {
435+
{ test ! -h git-for-windows-$arch.db.sig || rm git-for-windows-$arch.db.sig; } &&
436+
cp git-for-windows-$arch.db.tar.xz.sig git-for-windows-$arch.db.sig
437+
}
438+
} &&
439+
if test -n "$db2"
440+
then
441+
repo_add $sign_option git-for-windows-$db2.db.tar.xz $mingw &&
442+
{ test ! -h git-for-windows-$db2.db || rm git-for-windows-$db2.db; } &&
443+
cp git-for-windows-$db2.db.tar.xz git-for-windows-$db2.db && {
444+
test -z "$sign_option" || {
445+
{ test ! -h git-for-windows-$db2.db.sig || rm git-for-windows-$db2.db.sig; } &&
446+
cp git-for-windows-$db2.db.tar.xz.sig git-for-windows-$db2.db.sig
447+
}
448+
}
449+
fi &&
450+
git -C "$dir/$arch" commit --amend --no-edit -- 'git-for-windows*.db*' 'git-for-windows*.files*') ||
451+
die "Could not update $dir/$arch"
452+
done
453+
git -C "$dir" -c "$extra_header" push origin $to_push && break
454+
455+
test -1 != $backoff &&
456+
echo "Waiting $backoff seconds before retrying..." >&2 &&
457+
sleep $backoff ||
458+
die "Could not push to git-for-windows/pacman-repo"
459+
done
460+
fi
407461
fi
408462

409463
# Mirror the deployment to a new GitHub Release

0 commit comments

Comments
 (0)