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 <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Sep 23, 2017 at 19:55 UTC 9ba95ed23cec1787d1fc2d42ef48137987807ca8
1 file changed +20 -12
t/perf/run
+20 -12
@@ -102,29 +102,37 @@ get_subsections () {
102
103 get_var_from_env_or_config () {
104 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
108
109 # Do nothing if the env variable is already set
110 eval "test -z \"\${$env_var+x}\"" || return
111
112 + test -z "$GIT_PERF_CONFIG_FILE" && return
113 +
114 # 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\""
126 }
127
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
129 export GIT_PERF_REPEAT_COUNT
130
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"
132 set -- $GIT_PERF_DIRS_OR_REVS "$@"
133
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"
136
137 GIT_PERF_AGGREGATING_LATER=t
138 export GIT_PERF_AGGREGATING_LATER