Skip to content

Commit

Permalink
google-repo: try with geometric repacking
Browse files Browse the repository at this point in the history
  • Loading branch information
taoky committed Sep 16, 2023
1 parent 3663a40 commit 875d58e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ A script for syncing projects (especially AOSP) using Google's `repo` tool.
| Parameter | Description |
| ---------- | ---------------------------------------------------------------------------- |
| `UPSTREAM` | Upstream URL. Defaults to `https://android.googlesource.com/mirror/manifest` |
| `GEOMETRIC_REPACK` | Use geometric repacking to speed up repacking (requires `git >= 2.34` on server). See [GitHub Blog: Scaling monorepo maintenance](https://github.blog/2021-04-29-scaling-monorepo-maintenance/). Defaults to false. |

### gsutil-rsync

Expand Down
32 changes: 21 additions & 11 deletions google-repo/sync.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/bin/bash

## Env
#UPSTREAM=
#GEOMETRIC_REPACK=

set -e
[[ -n $DEBUG ]] && set -x

UPSTREAM="${UPSTREAM:-https://android.googlesource.com/mirror/manifest}"
GEOMETRIC_REPACK="${GEOMETRIC_REPACK:-false}"

PATH=/usr/local/bin:$PATH

Expand Down Expand Up @@ -35,19 +40,24 @@ echo "start repacking git objects"
# to make AOSP sync faster.
gc() {
pushd "$1"
object_num=$(find objects/ -name '*.pack' | wc -l)
if [[ $object_num -gt 4 ]]; then
object_size=$(du -sk objects/pack/ | awk '{print $1}')
if [[ $object_size -gt 100000 || $object_num -gt 20 ]]; then
# only pack when we have more than 4 packs and
# the size of pack dir is larger than 100MB, or we have more than 20 packs
echo "repacking $1: $object_num packs, $object_size KB"
git repack -abd
if [[ $GEOMETRIC_REPACK == true ]]; then
echo "repacking $1"
git repack --write-midx --write-bitmap-index -d --geometric=2
else
object_num=$(find objects/ -type f -not -path '*/pack/*' -not -path '*/info/*' | wc)
if [[ $object_num -gt 4 ]]; then
object_size=$(du -sk --exclude=pack/* --exclude=info/* objects/ | awk '{print $1}')
if [[ $object_size -gt 100000 || $object_num -gt 20 ]]; then
# only pack when we have more than 4 packs and
# the size of pack dir is larger than 100MB, or we have more than 20 packs
echo "repacking $1: $object_num packs, $object_size KB"
git repack -abd
else
echo "skipping $1: $object_num packs, $object_size KB"
fi
else
echo "skipping $1: $object_num packs, $object_size KB"
echo "skipping $1: $object_num packs"
fi
else
echo "skipping $1: $object_num packs"
fi
};

Expand Down

0 comments on commit 875d58e

Please sign in to comment.