From: Tian Yuchen Date: Sun, 17 May 2026 16:18:36 GMT Subject: Re: [PATCH 02/18] setup: stop using `the_repository` in `is_inside_worktree()` Message-ID: <4d9604e2-036b-485e-aa93-53c35d539bed@malon.dev> In-Reply-To: <20260420-pks-setup-wo-the-repository-v1-2-f4a81c4988e8@pks.im> On 4/20/26 16:22, Patrick Steinhardt wrote: I've noticed something that does not entirely convince me: > @@ -477,11 +476,13 @@ int is_inside_git_dir(void) > return inside_git_dir; > } > > -int is_inside_work_tree(void) > +int is_inside_work_tree(struct repository *repo) > { > - if (inside_work_tree < 0) > - inside_work_tree = is_inside_dir(repo_get_work_tree(the_repository)); > - return inside_work_tree; > + static struct strbuf buf = STRBUF_INIT; > + const char *worktree = repo_get_work_tree(repo); > + if (!worktree) > + return 0; > + return is_inside_dir(strbuf_realpath(&buf, worktree, 1)); > } > Is it correct to statically allocate memory for the cache here? Could this lead to memory overwriting issues in a multi-threaded environment? p.s. I'm not sure if this one is better: > > int is_inside_work_tree(struct repository *repo) > { > struct strbuf buf = STRBUF_INIT; > const char *worktree = repo_get_work_tree(repo); > int ret; > > if (!worktree) > return 0; > > ret = is_inside_dir(strbuf_realpath(&buf, worktree, 1)); > strbuf_release(&buf); > return ret; > } Thanks! yuchen