Skip to content

Commit 9ba95ed

Browse files
chriscoolgitster
authored andcommitted
perf/run: update get_var_from_env_or_config() for subsections
As we will set some config options in subsections, let's teach get_var_from_env_or_config() to get the config options from the subsections if they are set there. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2638441 commit 9ba95ed

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

t/perf/run

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,37 @@ get_subsections () {
102102

103103
get_var_from_env_or_config () {
104104
env_var="$1"
105-
conf_var="$2"
106-
# $3 can be set to a default value
105+
conf_sec="$2"
106+
conf_var="$3"
107+
# $4 can be set to a default value
107108

108109
# Do nothing if the env variable is already set
109110
eval "test -z \"\${$env_var+x}\"" || return
110111

112+
test -z "$GIT_PERF_CONFIG_FILE" && return
113+
111114
# Check if the variable is in the config file
112-
test -n "$GIT_PERF_CONFIG_FILE" &&
113-
conf_value=$(git config -f "$GIT_PERF_CONFIG_FILE" "$conf_var") &&
114-
eval "$env_var=\"$conf_value\"" || {
115-
test -n "${3+x}" &&
116-
eval "$env_var=\"$3\""
117-
}
115+
if test -n "$GIT_PERF_SUBSECTION"
116+
then
117+
var="$conf_sec.$GIT_PERF_SUBSECTION.$conf_var"
118+
conf_value=$(git config -f "$GIT_PERF_CONFIG_FILE" "$var") &&
119+
eval "$env_var=\"$conf_value\"" && return
120+
fi
121+
var="$conf_sec.$conf_var"
122+
conf_value=$(git config -f "$GIT_PERF_CONFIG_FILE" "$var") &&
123+
eval "$env_var=\"$conf_value\"" && return
124+
125+
test -n "${4+x}" && eval "$env_var=\"$4\""
118126
}
119127

120-
get_var_from_env_or_config "GIT_PERF_REPEAT_COUNT" "perf.repeatCount" 3
128+
get_var_from_env_or_config "GIT_PERF_REPEAT_COUNT" "perf" "repeatCount" 3
121129
export GIT_PERF_REPEAT_COUNT
122130

123-
get_var_from_env_or_config "GIT_PERF_DIRS_OR_REVS" "perf.dirsOrRevs"
131+
get_var_from_env_or_config "GIT_PERF_DIRS_OR_REVS" "perf" "dirsOrRevs"
124132
set -- $GIT_PERF_DIRS_OR_REVS "$@"
125133

126-
get_var_from_env_or_config "GIT_PERF_MAKE_COMMAND" "perf.makeCommand"
127-
get_var_from_env_or_config "GIT_PERF_MAKE_OPTS" "perf.makeOpts"
134+
get_var_from_env_or_config "GIT_PERF_MAKE_COMMAND" "perf" "makeCommand"
135+
get_var_from_env_or_config "GIT_PERF_MAKE_OPTS" "perf" "makeOpts"
128136

129137
GIT_PERF_AGGREGATING_LATER=t
130138
export GIT_PERF_AGGREGATING_LATER

0 commit comments

Comments
 (0)