1#!/bin/bash
2
3# Run command on every commit within the range specified. If no command is
4# provided, use the default one to clean and build the whole tree.
5#
6# The default rune is rather simple. To do a cross-build, please put your usual
7# build rune in a shell script and invoke it with this script.
8#
9# Set NON_SYMBOLIC_REF=1 if you want to use this script in detached HEAD state.
10# This is currently used by automated test system.
11
12if test $# -lt 2 ; then
13    echo "Usage:"
14    echo " $0 <BASE> <TIP> [CMD]"
15    echo " If [CMD] is not specified, run the default command"
16    echo "     git clean -fdx && ./configure && make -j4"
17    exit 1
18fi
19
20pushd `git rev-parse --show-toplevel`
21
22status=`git status -s`
23if test -n "$status"; then
24    echo "Tree is dirty, aborted"
25    exit 1
26fi
27
28BASE=$1; shift
29TIP=$1; shift
30
31if [[ "_${NON_SYMBOLIC_REF}" != "_1" ]]; then
32    ORIG=`git symbolic-ref -q --short HEAD`
33    if test $? -ne 0; then
34        echo "Detached HEAD, aborted"
35        exit 1
36    fi
37else
38    ORIG=`git rev-parse HEAD`
39fi
40
41ret=1
42while read num rev; do
43    echo "Testing $num $rev"
44
45    git checkout $rev
46    ret=$?
47    if test $ret -ne 0; then
48        echo "Failed to checkout $num $rev with $ret"
49        break
50    fi
51
52    if test $# -eq 0 ; then
53        git clean -fdx && ./configure && make -j4
54    else
55        "$@"
56    fi
57    ret=$?
58    if test $ret -ne 0; then
59        echo "Failed at $num $rev with $ret"
60        break
61    fi
62    echo
63done < <(git rev-list $BASE..$TIP | nl -ba | tac)
64
65echo "Restoring original HEAD"
66git checkout $ORIG
67gco_ret=$?
68if test $gco_ret -ne 0; then
69    echo "Failed to restore orignal HEAD. Check tree status before doing anything else!"
70    exit $gco_ret
71fi
72
73if test $ret -eq 0; then
74    echo "ok."
75fi
76exit $ret
77