Skip to content

Commit e6b7153

Browse files
chriscoolgitster
authored andcommitted
perf/run: add get_var_from_env_or_config()
Add get_var_from_env_or_config() to easily set variables from a config file if they are defined there and not already set. This can also set them to a default value if one is provided. As an example, use this function to set GIT_PERF_REPEAT_COUNT from the perf.repeatCount config option or from the default value. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e3d5e12 commit e6b7153

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

t/perf/perf-lib.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ perf_results_dir=$TEST_OUTPUT_DIRECTORY/test-results
5959
mkdir -p "$perf_results_dir"
6060
rm -f "$perf_results_dir"/$(basename "$0" .sh).subtests
6161

62-
if test -z "$GIT_PERF_REPEAT_COUNT"; then
63-
GIT_PERF_REPEAT_COUNT=3
64-
fi
6562
die_if_build_dir_not_repo () {
6663
if ! ( cd "$TEST_DIRECTORY/.." &&
6764
git rev-parse --build-dir >/dev/null 2>&1 ); then

t/perf/run

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ unpack_git_rev () {
3434
(cd "$(git rev-parse --show-cdup)" && git archive --format=tar $rev) |
3535
(cd build/$rev && tar x)
3636
}
37+
3738
build_git_rev () {
3839
rev=$1
3940
for config in config.mak config.mak.autogen config.status
@@ -92,6 +93,26 @@ run_dirs () {
9293
done
9394
}
9495

96+
get_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+
113+
get_var_from_env_or_config "GIT_PERF_REPEAT_COUNT" "perf.repeatCount" 3
114+
export GIT_PERF_REPEAT_COUNT
115+
95116
GIT_PERF_AGGREGATING_LATER=t
96117
export GIT_PERF_AGGREGATING_LATER
97118

0 commit comments

Comments
 (0)