crates/storage-git-gix/parked-gix/.nornir/bench/transfer-ceiling.sh
#!/usr/bin/env bash
# What is the prize? Bound it before building anything.
#
# For each repository and each client depth, three packs over the SAME object
# set, all produced by stock git from the source repository:
#
# whole `pack-objects` over the fetch set with no thin bases at all -- the
# best a SELF-CONTAINED transfer-shaped pack can ever be, which is the
# ceiling for a repacker that chooses in-set bases.
# thin the same with `--thin` -- the ceiling once a voucher is also perfect.
# all `pack-objects` over the whole history, for the clone column.
#
# The gap between `whole` and what gunnar actually ships is this lane's prize.
# The gap between `thin` and `whole` is what only the read side can reach.
set -u -o pipefail
X=${XFER_DIR:-/home/rickard/scratch/xfer}
SRC=${SRC:-/home/rickard/git}
DEPTHS=${DEPTHS:-"50 200"}
REPOS=${REPOS:-"nornir modgunn funnel-core holger facett edda skade znippy znippy-zoomies knut korp korp-collectors ordning Skidbladnir tunnr draupnir dwarves bifrost workspace_nordisk"}
# THE HEAD IS FROZEN, from $X/heads.tsv, for the same reason the arm's is:
# `$SRC` is a live checkout other agents push to, and a ceiling computed over a
# different object set than the arms served is not a ceiling, it is a second
# measurement wearing the first one's units.
[ -s "$X/heads.tsv" ] || { echo "FATAL: no $X/heads.tsv" >&2; exit 1; }
echo -e "repo\tdepth\tobjects\twhole_b\tthin_b"
for r in $REPOS; do
head=$(awk -F'\t' -v r="$r" '$1==r{print $2}' "$X/heads.tsv")
[ -n "$head" ] || { echo "FATAL: $r has no frozen head" >&2; exit 1; }
for D in $DEPTHS; do
old=$(git -C "$SRC/$r" rev-parse "$head~$D" 2>/dev/null) || continue
n=$(git -C "$SRC/$r" rev-list --objects "$head" "^$old" | wc -l)
# `pack-objects --stdout` writes the pack on stdout; `wc -c` counts it. A
# pipe hides the producer's exit status, so the object count is asserted
# separately above and a zero-byte pack is caught by the size itself.
whole=$(printf '%s\n^%s\n' "$head" "$old" \
| git -C "$SRC/$r" pack-objects --stdout --revs --delta-base-offset -q 2>/dev/null | wc -c)
thin=$(printf '%s\n^%s\n' "$head" "$old" \
| git -C "$SRC/$r" pack-objects --stdout --revs --thin --delta-base-offset -q 2>/dev/null | wc -c)
[ "$whole" -gt 32 ] || { echo "FATAL: $r@$D produced a $whole-byte pack" >&2; exit 1; }
echo -e "$r\t$D\t$n\t$whole\t$thin"
done
done