Created
March 13, 2012 00:24
-
-
Save barrbrain/2025636 to your computer and use it in GitHub Desktop.
A script to calculate a push strategy for a ref, given a pack size limit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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