git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/9] perf/run: add get_var_from_env_or_config()

From
Christian Couder <chriscool@tuxfamily.org>
Date
Sep 23, 2017, 19:55 UTC
Message-ID
<0102015eb04f89d7-11cb1e45-a3d5-49f4-9593-518411971e80-000000@eu-west-1.amazonses.com>
In-Reply-To
<0102015eb04f8927-439213ae-a464-4638-affa-f0d6484086c0-000000@eu-west-1.amazonses.com>

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>
---
 t/perf/perf-lib.sh |  3 ---
 t/perf/run         | 21 +++++++++++++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh
index b50211b2591d1..2f88fc12a9b5c 100644
--- a/t/perf/perf-lib.sh
+++ b/t/perf/perf-lib.sh
@@ -59,9 +59,6 @@ perf_results_dir=$TEST_OUTPUT_DIRECTORY/test-results
 mkdir -p "$perf_results_dir"
 rm -f "$perf_results_dir"/$(basename "$0" .sh).subtests
 
-if test -z "$GIT_PERF_REPEAT_COUNT"; then
-	GIT_PERF_REPEAT_COUNT=3
-fi
 die_if_build_dir_not_repo () {
 	if ! ( cd "$TEST_DIRECTORY/.." &&
 		    git rev-parse --build-dir >/dev/null 2>&1 ); then
diff --git a/t/perf/run b/t/perf/run
index 1e7c2a59e45dc..41580ac6df44a 100755
--- a/t/perf/run
+++ b/t/perf/run
@@ -34,6 +34,7 @@ unpack_git_rev () {
 	(cd "$(git rev-parse --show-cdup)" && git archive --format=tar $rev) |
 	(cd build/$rev && tar x)
 }
+
 build_git_rev () {
 	rev=$1
 	for config in config.mak config.mak.autogen config.status
@@ -92,6 +93,26 @@ run_dirs () {
 	done
 }
 
+get_var_from_env_or_config () {
+	env_var="$1"
+	conf_var="$2"
+	# $3 can be set to a default value
+
+	# Do nothing if the env variable is already set
+	eval "test -z \"\${$env_var+x}\"" || return
+
+	# Check if the variable is in the config file
+	test -n "$GIT_PERF_CONFIG_FILE" &&
+	conf_value=$(git config -f "$GIT_PERF_CONFIG_FILE" "$conf_var") &&
+	eval "$env_var=\"$conf_value\"" || {
+		test -n "${3+x}" &&
+		eval "$env_var=\"$3\""
+	}
+}
+
+get_var_from_env_or_config "GIT_PERF_REPEAT_COUNT" "perf.repeatCount" 3
+export GIT_PERF_REPEAT_COUNT
+
 GIT_PERF_AGGREGATING_LATER=t
 export GIT_PERF_AGGREGATING_LATER
 

--
https://github.com/git/git/pull/408
Previous: Christian CouderNext: Christian Couder
Message 5 of 14 in “perf/run: add '--config' option to the 'run' script”
  1. 1/9 perf/run: add '--config' option to the 'run' scriptChristian Couder, Sep 23, 2017
  2. 4/9 perf/run: add calls to get_var_from_env_or_config()Christian Couder, Sep 23, 2017
  3. 8/9 perf/run: show name of rev being builtChristian Couder, Sep 23, 2017
  4. 9/9 perf: store subsection results in "test-results/$GIT_PERF_SUBSECTION/"Christian Couder, Sep 23, 2017
  5. 2/9 perf/run: add get_var_from_env_or_config()Christian Couder, Sep 23, 2017
  6. 5/9 perf/run: add get_subsections()Christian Couder, Sep 23, 2017
  7. 6/9 perf/run: update get_var_from_env_or_config() for subsectionsChristian Couder, Sep 23, 2017
  8. 3/9 perf/run: add GIT_PERF_DIRS_OR_REVSChristian Couder, Sep 23, 2017
  9. 7/9 perf/run: add run_subsection()Christian Couder, Sep 23, 2017
  10. Junio C HamanoOct 16, 2017
  11. Christian CouderNov 17, 2017
  12. Ævar Arnfjörð BjarmasonNov 24, 2017
  13. Kevin DaudtOct 18, 2017
  14. Christian CouderOct 18, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.