aboutsummaryrefslogtreecommitdiff
path: root/packfile.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-09-23 12:17:03 +0200
committerJunio C Hamano <gitster@pobox.com>2025-09-24 11:53:49 -0700
commit14aaf5c9d889a4988ffc64b39fe38bd19b930a50 (patch)
treec89d06e15bbda04c6f1573389d3bc2aeb3e2f43a /packfile.c
parent3421cb56a8b37425f2a47695adfa4a29a06a9d2e (diff)
downloadgit-14aaf5c9d889a4988ffc64b39fe38bd19b930a50.tar.xz
odb: move packfile map into `struct packfile_store`
The object database tracks a map of packfiles by their respective paths, which is used to figure out whether a given packfile has already been loaded. With the introduction of the `struct packfile_store` we have a better place to host this list though. Move the map accordingly. `pack_map_entry_cmp()` isn't used anywhere but in "packfile.c" anymore after this change, so we convert it to a static function, as well. Note that we also drop the `inline` hint: the function is used as a callback function exclusively, and callbacks cannot be inlined. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'packfile.c')
-rw-r--r--packfile.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/packfile.c b/packfile.c
index f37557eac5..17e0b8ab27 100644
--- a/packfile.c
+++ b/packfile.c
@@ -788,7 +788,7 @@ void install_packed_git(struct repository *r, struct packed_git *pack)
r->objects->packfiles->packs = pack;
hashmap_entry_init(&pack->packmap_ent, strhash(pack->pack_name));
- hashmap_add(&r->objects->pack_map, &pack->packmap_ent);
+ hashmap_add(&r->objects->packfiles->map, &pack->packmap_ent);
}
void (*report_garbage)(unsigned seen_bits, const char *path);
@@ -901,7 +901,7 @@ static void prepare_pack(const char *full_name, size_t full_name_len,
hashmap_entry_init(&hent, hash);
/* Don't reopen a pack we already have. */
- if (!hashmap_get(&data->r->objects->pack_map, &hent, pack_name)) {
+ if (!hashmap_get(&data->r->objects->packfiles->map, &hent, pack_name)) {
p = add_packed_git(data->r, full_name, full_name_len, data->local);
if (p)
install_packed_git(data->r, p);
@@ -2328,11 +2328,26 @@ int parse_pack_header_option(const char *in, unsigned char *out, unsigned int *l
return 0;
}
+static int pack_map_entry_cmp(const void *cmp_data UNUSED,
+ const struct hashmap_entry *entry,
+ const struct hashmap_entry *entry2,
+ const void *keydata)
+{
+ const char *key = keydata;
+ const struct packed_git *pg1, *pg2;
+
+ pg1 = container_of(entry, const struct packed_git, packmap_ent);
+ pg2 = container_of(entry2, const struct packed_git, packmap_ent);
+
+ return strcmp(pg1->pack_name, key ? key : pg2->pack_name);
+}
+
struct packfile_store *packfile_store_new(struct object_database *odb)
{
struct packfile_store *store;
CALLOC_ARRAY(store, 1);
store->odb = odb;
+ hashmap_init(&store->map, pack_map_entry_cmp, NULL, 0);
return store;
}
@@ -2342,6 +2357,7 @@ void packfile_store_free(struct packfile_store *store)
next = p->next;
free(p);
}
+ hashmap_clear(&store->map);
free(store);
}