path: stop relying on the_repository when reporting garbage

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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2024-08-13 11:13:31 +02:00
committed by Junio C Hamano
parent 169c979771
commit 78f2210b3c
3 changed files with 5 additions and 5 deletions

View File

@ -113,7 +113,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
usage_with_options(count_objects_usage, opts);
if (verbose) {
report_garbage = real_report_garbage;
report_linked_checkout_garbage();
report_linked_checkout_garbage(the_repository);
}
for_each_loose_file_in_objdir(get_object_directory(),

6
path.c
View File

@ -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;

2
path.h
View File

@ -158,7 +158,7 @@ int strbuf_git_path_submodule(struct strbuf *sb, const char *path,
const char *fmt, ...)
__attribute__((format (printf, 3, 4)));
void report_linked_checkout_garbage(void);
void report_linked_checkout_garbage(struct repository *r);
/*
* You can define a static memoized git path like: