Thread (64 messages) flat view 64 messages, 4 authors, 2024-08-15

Re: [PATCH v2 05/20] path: stop relying on `the_repository` when reporting garbage

From: Calvin Wan <hidden>
Date: 2024-08-14 18:28:54

Patrick Steinhardt [off-list ref] writes:
quoted hunk ↗ jump to hunk
We access `the_repository` in `report_linked_checkout_garbage()` both
directly and indirectly via `get_git_dir()`. Remove this dependency by
instead passing a `struct repository` as parameter.

Signed-off-by: Patrick Steinhardt <redacted>
---
 builtin/count-objects.c | 2 +-
 path.c                  | 6 +++---
 path.h                  | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/path.c b/path.c
index 069db6ff8f..97a07fafc7 100644
--- a/path.c
+++ b/path.c
@@ -365,15 +365,15 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len,
 		strbuf_addstr(buf, LOCK_SUFFIX);
 }
 
-void report_linked_checkout_garbage(void)
+void report_linked_checkout_garbage(struct repository *r)
 {
 	struct strbuf sb = STRBUF_INIT;
 	const struct common_dir *p;
 	int len;
 
-	if (!the_repository->different_commondir)
+	if (!r->different_commondir)
 		return;
-	strbuf_addf(&sb, "%s/", get_git_dir());
+	strbuf_addf(&sb, "%s/", r->gitdir);
 	len = sb.len;
 	for (p = common_list; p->path; p++) {
 		const char *path = p->path;
Callers have two options here for accessing the gitdir: one is including
environment.h and calling get_git_dir(). The other is passing in `struct
repository *r` and accessing r->gitdir. It's not entirely clear which
should be used in what scenario. Sure with the second option the user
has the option of passing something in that isn't `the_repository` but
practically speaking that's not happening here and also in the large
majority of other scenarios.

I'm OK with this patch for the purposes of the series, but do you think
in the future we should introduce get_git_dir(struct repository *r) and
change get_git_dir() into get_env_git_dir() that simply calls
get_git_dir(the_repository)?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help