]> git.ipfire.org Git - thirdparty/git.git/commitdiff
path: stop relying on `the_repository` when reporting garbage
authorPatrick Steinhardt <ps@pks.im>
Tue, 13 Aug 2024 09:13:31 +0000 (11:13 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Aug 2024 17:01:01 +0000 (10:01 -0700)
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>
builtin/count-objects.c
path.c
path.h

index 2d4bb5e8d0a8dfce1290760f7cd99dac7ba39a3e..ec6098a149d0e82be59f113935b61dfe55b4fc6c 100644 (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(),
diff --git a/path.c b/path.c
index 069db6ff8f2c501bdfa4166859c4694d2c98190a..97a07fafc73d66374b666e6fbcfbfab756d7afe6 100644 (file)
--- 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;
diff --git a/path.h b/path.h
index 05aff5f4c3b2ef58361b2a3471e314274aad98fe..9a4a4a8fb3f724d0494f28511d75a23a3db365ab 100644 (file)
--- a/path.h
+++ b/path.h
@@ -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: