Skip to content

Commit 14aaf5c

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3421cb5 commit 14aaf5c

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

midx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ int prepare_midx_pack(struct multi_pack_index *m,
460460
strbuf_addbuf(&key, &pack_name);
461461
strbuf_strip_suffix(&key, ".idx");
462462
strbuf_addstr(&key, ".pack");
463-
p = hashmap_get_entry_from_hash(&r->objects->pack_map,
463+
p = hashmap_get_entry_from_hash(&r->objects->packfiles->map,
464464
strhash(key.buf), key.buf,
465465
struct packed_git, packmap_ent);
466466
if (!p) {

odb.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,6 @@ struct object_database *odb_new(struct repository *repo)
998998
o->repo = repo;
999999
o->packfiles = packfile_store_new(o);
10001000
INIT_LIST_HEAD(&o->packed_git_mru);
1001-
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
10021001
pthread_mutex_init(&o->replace_mutex, NULL);
10031002
string_list_init_dup(&o->submodule_source_paths);
10041003
return o;
@@ -1041,6 +1040,5 @@ void odb_clear(struct object_database *o)
10411040
packfile_store_free(o->packfiles);
10421041
o->packfiles = NULL;
10431042

1044-
hashmap_clear(&o->pack_map);
10451043
string_list_clear(&o->submodule_source_paths, 0);
10461044
}

odb.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ struct object_database {
135135
/*
136136
* private data
137137
*
138-
* should only be accessed directly by packfile.c
138+
* Should only be accessed directly by packfile.c and midx.c.
139139
*/
140140
struct packfile_store *packfiles;
141141
/* A most-recently-used ordered version of the packed_git list. */
@@ -155,12 +155,6 @@ struct object_database {
155155
struct cached_object_entry *cached_objects;
156156
size_t cached_object_nr, cached_object_alloc;
157157

158-
/*
159-
* A map of packfiles to packed_git structs for tracking which
160-
* packs have been loaded already.
161-
*/
162-
struct hashmap pack_map;
163-
164158
/*
165159
* A fast, rough count of the number of objects in the repository.
166160
* These two fields are not meant for direct access. Use

packfile.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ void install_packed_git(struct repository *r, struct packed_git *pack)
788788
r->objects->packfiles->packs = pack;
789789

790790
hashmap_entry_init(&pack->packmap_ent, strhash(pack->pack_name));
791-
hashmap_add(&r->objects->pack_map, &pack->packmap_ent);
791+
hashmap_add(&r->objects->packfiles->map, &pack->packmap_ent);
792792
}
793793

794794
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,
901901
hashmap_entry_init(&hent, hash);
902902

903903
/* Don't reopen a pack we already have. */
904-
if (!hashmap_get(&data->r->objects->pack_map, &hent, pack_name)) {
904+
if (!hashmap_get(&data->r->objects->packfiles->map, &hent, pack_name)) {
905905
p = add_packed_git(data->r, full_name, full_name_len, data->local);
906906
if (p)
907907
install_packed_git(data->r, p);
@@ -2328,11 +2328,26 @@ int parse_pack_header_option(const char *in, unsigned char *out, unsigned int *l
23282328
return 0;
23292329
}
23302330

2331+
static int pack_map_entry_cmp(const void *cmp_data UNUSED,
2332+
const struct hashmap_entry *entry,
2333+
const struct hashmap_entry *entry2,
2334+
const void *keydata)
2335+
{
2336+
const char *key = keydata;
2337+
const struct packed_git *pg1, *pg2;
2338+
2339+
pg1 = container_of(entry, const struct packed_git, packmap_ent);
2340+
pg2 = container_of(entry2, const struct packed_git, packmap_ent);
2341+
2342+
return strcmp(pg1->pack_name, key ? key : pg2->pack_name);
2343+
}
2344+
23312345
struct packfile_store *packfile_store_new(struct object_database *odb)
23322346
{
23332347
struct packfile_store *store;
23342348
CALLOC_ARRAY(store, 1);
23352349
store->odb = odb;
2350+
hashmap_init(&store->map, pack_map_entry_cmp, NULL, 0);
23362351
return store;
23372352
}
23382353

@@ -2342,6 +2357,7 @@ void packfile_store_free(struct packfile_store *store)
23422357
next = p->next;
23432358
free(p);
23442359
}
2360+
hashmap_clear(&store->map);
23452361
free(store);
23462362
}
23472363

packfile.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ struct packfile_store {
6464
*/
6565
struct packed_git *packs;
6666

67+
/*
68+
* A map of packfile names to packed_git structs for tracking which
69+
* packs have been loaded already.
70+
*/
71+
struct hashmap map;
72+
6773
/*
6874
* Whether packfiles have already been populated with this store's
6975
* packs.
@@ -89,20 +95,6 @@ void packfile_store_free(struct packfile_store *store);
8995
*/
9096
void packfile_store_close(struct packfile_store *store);
9197

92-
static inline int pack_map_entry_cmp(const void *cmp_data UNUSED,
93-
const struct hashmap_entry *entry,
94-
const struct hashmap_entry *entry2,
95-
const void *keydata)
96-
{
97-
const char *key = keydata;
98-
const struct packed_git *pg1, *pg2;
99-
100-
pg1 = container_of(entry, const struct packed_git, packmap_ent);
101-
pg2 = container_of(entry2, const struct packed_git, packmap_ent);
102-
103-
return strcmp(pg1->pack_name, key ? key : pg2->pack_name);
104-
}
105-
10698
struct pack_window {
10799
struct pack_window *next;
108100
unsigned char *base;

0 commit comments

Comments
 (0)