Skip to content

Instantly share code, notes, and snippets.

@ajlake
Created December 6, 2019 20:04
Show Gist options
  • Save ajlake/a547bed6bb193f2dceb593b8a4aa966f to your computer and use it in GitHub Desktop.
Save ajlake/a547bed6bb193f2dceb593b8a4aa966f to your computer and use it in GitHub Desktop.
git bundle tricks
#!/bin/bash
set -eux
# Normally, we would just create a vanilla git bundle
# --> git bundle create ../REPO.bundle --all HEAD
#
# However, unbundling a large complex repository will perform
# expensive reachability / index creation computations.
# Normally git packfiles are optimized for over-the-wire data
# transfer at the cost of computational effort on the receiving
# side. Since the computational effort is the bottleneck, we will
# instead perform some hacks to create a "bundle" that can be used
# to seed a REPO clone without reachability / index creation computations.
# First, run 'git gc' to ensure the repository is fully packed.
# After this point, all relevant data is in three files:
# packed-refs, and two files under objects/pack/
git gc
# Create a "bundle"
tar cf ../REPO.bundle packed-refs objects/pack
#!/bin/bash
set -eux
# This is what we would normally do with a _regular_ bundle
# ---> git clone --bare "${BUNDLE_PATH}" "${BARE_CLONE_PATH}"
# We instead do the following...
# This is the receiving side of our bundle hacks
rm -rf "${BARE_CLONE_PATH}"
mkdir "${BARE_CLONE_PATH}"
cd "${BARE_CLONE_PATH}"
git init
TRIES_REMAINING=10
until aws s3 cp --quiet s3://path/to/REPO.bundle - | tar xf - -C .git; do
rm -rf .git && git init
(( TRIES_REMAINING-- ))
if [[ "${TRIES_REMAINING}" -le "0" ]]; then
echo "Failed restoring REPO git bundle"
exit 1
fi
sleep 3
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment