Skip to content

Instantly share code, notes, and snippets.

@barrbrain
Created March 13, 2012 00:24
Show Gist options
  • Save barrbrain/2025636 to your computer and use it in GitHub Desktop.
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.
#!/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