Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A script to calculate a push strategy for a ref, given a pack size limit.
#!/bin/bash
LIMIT=$1
TIP=$2
BS=$(( 64 * 1024 ))
COUNT=$(( ( $LIMIT ) / $BS ))
packsize() {
COMMITS=$1
ENDPOINT=$TOP
STARTPOINT=`git rev-parse $ENDPOINT~$COMMITS 2>/dev/null` || return 1
echo $STARTPOINT..$ENDPOINT |
git pack-objects -q --stdout --revs |
dd bs=$BS skip=$COUNT count=0 2>/dev/null &&
return 1 || return 0
}
parents=`git rev-list $TIP --first-parent --count` || exit 128
acc=0
TOP=$TIP
i=1
while [ $(( $acc )) -lt $parents ]
do
n=0
while packsize $i
do
printf .
n=$i
NEWTOP=$STARTPOINT
let i=i*2
done
[ $n -eq 0 ] &&
while [ $i -gt 1 ]
do
printf ,
let i=i/2
packsize $i &&
{
n=$i
NEWTOP=$STARTPOINT
break
}
done
[ $n -eq 0 ] && break
acc=$acc+$n
TOP=$NEWTOP
i=$n
printf $n
done
echo
[ $(( $acc )) -lt $parents ] && acc=$acc+$(( $parents - ( $acc ) ))
echo $TIP'~$(('$acc'))'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.