loose: load loose object map for the correct source

When loading the loose object map via `load_one_loose_object_map()` we pass in both a repository and the corresponding source. We ultimately don't really respect the passed-in source though as we instead always load the map via the common directory. This doesn't make any sense though, as the function is called in a loop through all sources, and as such the expectation is that we'll load the map that belongs to the given source. Fix this bug by instead loading the map via the loose source's path. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 24, 2026 at 05:48 UTC 5c0bc1d8889f21964bfb213f06baa91ba74ef964
1 file changed +10 -8
loose.c
+10 -8
@@ -61,9 +61,11 @@ static int insert_loose_map(struct odb_source_loose *loose,
61 return inserted;
62 }
63
64 -static int load_one_loose_object_map(struct repository *repo, struct odb_source_loose *loose)
64 +static int load_one_loose_object_map(struct odb_source_loose *loose)
65 {
66 - struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
66 + struct repository *repo = loose->base.odb->repo;
67 + struct strbuf buf = STRBUF_INIT;
68 + char *path;
69 FILE *fp;
70 int ret = -1;
71
@@ -78,10 +80,10 @@ static int load_one_loose_object_map(struct repository *repo, struct odb_source_
80 insert_loose_map(loose, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
81 insert_loose_map(loose, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
82
81 - repo_common_path_replace(repo, &path, "objects/loose-object-idx");
82 - fp = fopen(path.buf, "rb");
83 + path = xstrfmt("%s/loose-object-idx", loose->base.path);
84 + fp = fopen(path, "rb");
85 if (!fp) {
84 - strbuf_release(&path);
86 + free(path);
87 return 0;
88 }
89
@@ -102,7 +104,7 @@ static int load_one_loose_object_map(struct repository *repo, struct odb_source_
104 err:
105 fclose(fp);
106 strbuf_release(&buf);
105 - strbuf_release(&path);
107 + free(path);
108 return ret;
109 }
110
@@ -117,10 +119,10 @@ int repo_read_loose_object_map(struct repository *repo)
119
120 for (source = repo->objects->sources; source; source = source->next) {
121 struct odb_source_files *files = odb_source_files_downcast(source);
120 - if (load_one_loose_object_map(repo, files->loose) < 0) {
122 + if (load_one_loose_object_map(files->loose) < 0)
123 return -1;
122 - }
124 }
125 +
126 return 0;
127 }
128