1#!/bin/sh
2
3case "$1" in
4 --help)
5 echo "usage: $0 [--config file] [other_git_tree...] [--] [test_scripts]"
6 exit 0
7 ;;
8 --config)
9 shift
10 GIT_PERF_CONFIG_FILE=$(cd "$(dirname "$1")"; pwd)/$(basename "$1")
11 export GIT_PERF_CONFIG_FILE
12 shift ;;
13esac
14
15die () {
16 echo >&2 "error: $*"
17 exit 1
18}
19
20run_one_dir () {
21 if test $# -eq 0; then
22 set -- p????-*.sh
23 fi
24 echo "=== Running $# tests in ${GIT_TEST_INSTALLED:-this tree} ==="
25 for t in "$@"; do
26 ./$t $GIT_TEST_OPTS
27 done
28}
29
30unpack_git_rev () {
31 rev=$1
32 echo "=== Unpacking $rev in build/$rev ==="
33 mkdir -p build/$rev
34 (cd "$(git rev-parse --show-cdup)" && git archive --format=tar $rev) |
35 (cd build/$rev && tar x)
36}
37
38build_git_rev () {
39 rev=$1
40 for config in config.mak config.mak.autogen config.status
41 do
42 if test -e "../../$config"
43 then
44 cp "../../$config" "build/$rev/"
45 fi
46 done
47 echo "=== Building $rev ==="
48 (
49 cd build/$rev &&
50 if test -n "$GIT_PERF_MAKE_COMMAND"
51 then
52 sh -c "$GIT_PERF_MAKE_COMMAND"
53 else
54 make $GIT_PERF_MAKE_OPTS
55 fi
56 ) || die "failed to build revision '$mydir'"
57}
58
59run_dirs_helper () {
60 mydir=${1%/}
61 shift
62 while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
63 shift
64 done
65 if test $# -gt 0 -a "$1" = --; then
66 shift
67 fi
68 if [ ! -d "$mydir" ]; then
69 rev=$(git rev-parse --verify "$mydir" 2>/dev/null) ||
70 die "'$mydir' is neither a directory nor a valid revision"
71 if [ ! -d build/$rev ]; then
72 unpack_git_rev $rev
73 fi
74 build_git_rev $rev
75 mydir=build/$rev
76 fi
77 if test "$mydir" = .; then
78 unset GIT_TEST_INSTALLED
79 else
80 GIT_TEST_INSTALLED="$mydir/bin-wrappers"
81 # Older versions of git lacked bin-wrappers; fallback to the
82 # files in the root.
83 test -d "$GIT_TEST_INSTALLED" || GIT_TEST_INSTALLED=$mydir
84 export GIT_TEST_INSTALLED
85 fi
86 run_one_dir "$@"
87}
88
89run_dirs () {
90 while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
91 run_dirs_helper "$@"
92 shift
93 done
94}
95
96get_var_from_env_or_config () {
97 env_var="$1"
98 conf_var="$2"
99 # $3 can be set to a default value
100
101 # Do nothing if the env variable is already set
102 eval "test -z \"\${$env_var+x}\"" || return
103
104 # Check if the variable is in the config file
105 test -n "$GIT_PERF_CONFIG_FILE" &&
106 conf_value=$(git config -f "$GIT_PERF_CONFIG_FILE" "$conf_var") &&
107 eval "$env_var=\"$conf_value\"" || {
108 test -n "${3+x}" &&
109 eval "$env_var=\"$3\""
110 }
111}
112
113get_var_from_env_or_config "GIT_PERF_REPEAT_COUNT" "perf.repeatCount" 3
114export GIT_PERF_REPEAT_COUNT
115
116get_var_from_env_or_config "GIT_PERF_DIRS_OR_REVS" "perf.dirsOrRevs"
117set -- $GIT_PERF_DIRS_OR_REVS "$@"
118
119GIT_PERF_AGGREGATING_LATER=t
120export GIT_PERF_AGGREGATING_LATER
121
122cd "$(dirname $0)"
123. ../../GIT-BUILD-OPTIONS
124
125if test $# = 0 -o "$1" = -- -o -f "$1"; then
126 set -- . "$@"
127fi
128run_dirs "$@"
129./aggregate.perl "$@"