setup: drop static `cwd` variable
The current working directory is stored as part of a static strbuf variable. This variable had to have a lifetime longer than its containing function because the value we return typically points into that buffer. In the preceding commit we have moved the prefix into the repository though. Consequently, we can now return the repository's prefix instead of the local one and thus properly manage the lifecycle of this local variable. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jul 7, 2026 at 09:21 UTC
28f38f35a00f8f9de6358b1e5b32fc4f17de2f81
1 file changed
+3
-2
setup.c
+3
-2
@@ -1933,7 +1933,7 @@ void set_git_work_tree(struct repository *repo, const char *new_work_tree)
1933
1934
const char *setup_git_directory_gently(struct repository *repo, int *nongit_ok)
1935
{
1936
- static struct strbuf cwd = STRBUF_INIT;
1936
+ struct strbuf cwd = STRBUF_INIT;
1937
struct strbuf dir = STRBUF_INIT, gitdir = STRBUF_INIT, report = STRBUF_INIT;
1938
struct repo_discovery discovery = REPO_DISCOVERY_INIT;
1939
const char *prefix = NULL;
@@ -2116,9 +2116,10 @@ const char *setup_git_directory_gently(struct repository *repo, int *nongit_ok)
2116
2117
repo_discovery_release(&discovery);
2118
strbuf_release(&dir);
2119
+ strbuf_release(&cwd);
2120
strbuf_release(&gitdir);
2121
strbuf_release(&report);
2121
- return prefix;
2122
+ return repo->prefix;
2123
}
2124
2125
int git_config_perm(const char *var, const char *value)