environment.c: remove test-specific "ignore_untracked..." variable

Instead of the global ignore_untracked_cache_config variable added in dae6c322fa1 (test-dump-untracked-cache: don't modify the untracked cache, 2016-01-27) we can make use of the new facility to set config via environment variables added in d8d77153eaf (config: allow specifying config entries via envvar pairs, 2021-01-12). It's arguably a bit hacky to use setenv() and getenv() to pass messages between the same program, but since the test helpers are not the main intended audience of repo-settings.c I think it's better than hardcoding the test-only special-case in prepare_repo_settings(). This uses the xsetenv() wrapper added in the preceding commit, if we don't set these in the environment we'll fail in t7063-status-untracked-cache.sh, but let's fail earlier anyway if that were to happen. This breaks any parent process that's potentially using the GIT_CONFIG_* and GIT_CONFIG_PARAMETERS mechanism to pass one-shot config setting down to a git subprocess, but in this case we don't care about the general case of such potential parents. This process neither spawns other "git" processes, nor is it interested in other configuration. We might want to pick up other test modes here, but those will be passed via GIT_TEST_* environment variables. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Sep 21, 2021 at 15:13 UTC c6b4888b3fb077e6d617511496adae06f14bcf4d
4 files changed +5 -22
cache.h
-7
@@ -1719,13 +1719,6 @@ int update_server_info(int);
1719 const char *get_log_output_encoding(void);
1720 const char *get_commit_output_encoding(void);
1721
1722 -/*
1723 - * This is a hack for test programs like test-dump-untracked-cache to
1724 - * ensure that they do not modify the untracked cache when reading it.
1725 - * Do not use it otherwise!
1726 - */
1727 -extern int ignore_untracked_cache_config;
1728 -
1722 int committer_ident_sufficiently_given(void);
1723 int author_ident_sufficiently_given(void);
1724
environment.c
-7
@@ -96,13 +96,6 @@ int auto_comment_line_char;
96 /* Parallel index stat data preload? */
97 int core_preload_index = 1;
98
99 -/*
100 - * This is a hack for test programs like test-dump-untracked-cache to
101 - * ensure that they do not modify the untracked cache when reading it.
102 - * Do not use it otherwise!
103 - */
104 -int ignore_untracked_cache_config;
105 -
99 /* This is set by setup_git_dir_gently() and/or git_default_config() */
100 char *git_work_tree_cfg;
101
repo-settings.c
+1 -6
@@ -70,12 +70,7 @@ void prepare_repo_settings(struct repository *r)
70 if (!repo_config_get_bool(r, "feature.experimental", &value) && value)
71 UPDATE_DEFAULT_BOOL(r->settings.fetch_negotiation_algorithm, FETCH_NEGOTIATION_SKIPPING);
72
73 - /* Hack for test programs like test-dump-untracked-cache */
74 - if (ignore_untracked_cache_config)
75 - r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
76 - else
77 - UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_KEEP);
78 -
73 + UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_KEEP);
74 UPDATE_DEFAULT_BOOL(r->settings.fetch_negotiation_algorithm, FETCH_NEGOTIATION_DEFAULT);
75
76 /*
t/helper/test-dump-untracked-cache.c
+4 -2
@@ -45,8 +45,10 @@ int cmd__dump_untracked_cache(int ac, const char **av)
45 struct untracked_cache *uc;
46 struct strbuf base = STRBUF_INIT;
47
48 - /* Hack to avoid modifying the untracked cache when we read it */
49 - ignore_untracked_cache_config = 1;
48 + /* Set core.untrackedCache=keep before setup_git_directory() */
49 + xsetenv("GIT_CONFIG_COUNT", "1", 1);
50 + xsetenv("GIT_CONFIG_KEY_0", "core.untrackedCache", 1);
51 + xsetenv("GIT_CONFIG_VALUE_0", "keep", 1);
52
53 setup_git_directory();
54 if (read_cache() < 0)