#!/usr/bin/env bash
stagebatch () {
        echo $(grep pull_id\" /mnt/flashblade/vehicle_merge_queue/state.json | cut -f2 -d: | cut -f1 -d, | tr "\n" " ")
}
do_serial () {
        PRLIST="$(stagebatch)"
        echo serial merge
        time ./testmerging.sh --serial $PRLIST > $whichfirst-serial-pass-$pass.log 2>&1
}
do_octo () {
        echo octo merge loop
        THIS_PRLIST=""
        for ADDPR in $PRLIST; do
                THIS_PRLIST+="$ADDPR "
                time ./testmerging.sh --octopus $THIS_PRLIST > $whichfirst-octo-pass$pass-PR$ADDPR.log 2>&1
        done
}
for whichfirst in do_serial do_octo; do
        if [[ $whichfirst == do_serial ]]; then second=do_octo; else second=do_serial; fi
        for pass in 1 2 3; do
                echo -----------------
                echo Pass $pass
                echo -----------------
                time git gc
                $whichfirst
                time git gc
                $second
                echo " "
                echo " "
                echo " "
        done
done
