Skip to content

Commit b7983ad

Browse files
pks-tgitster
authored andcommitted
packfile: introduce a new struct packfile_store
Information about an object database's packfiles is currently distributed across two different structures: - `struct packed_git` contains the `next` pointer as well as the `mru_head`, both of which serve to store the list of packfiles. - `struct object_database` contains several fields that relate to the packfiles. So we don't really have a central data structure that tracks our packfiles, and consequently responsibilities aren't always clear cut. A consequence for the upcoming pluggable object databases is that this makes it very hard to move management of packfiles from the object database level down into the object database source. Introduce a new `struct packfile_store` which is about to become the single source of truth for managing packfiles. Right now this data structure doesn't yet contain anything, but in subsequent patches we will move all data structures that relate to packfiles and that are currently contained in `struct object_database` into this new home. Note that this is only a first step: most importantly, we won't (yet) move the `struct packed_git::next` pointer around. This will happen in a subsequent patch series though so that `struct packed_git` will really only host information about the specific packfile it represents. Further note that the new structure still sits at the wrong level at the end of this patch series: as mentioned, it should eventually sit at the level of the object database source, not at the object database level. But introducing the packfile store now already makes it way easier to eventually push down the now-selfcontained data structure by one level. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0b71555 commit b7983ad

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

odb.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ struct object_database *odb_new(struct repository *repo)
996996

997997
memset(o, 0, sizeof(*o));
998998
o->repo = repo;
999+
o->packfiles = packfile_store_new(o);
9991000
INIT_LIST_HEAD(&o->packed_git_mru);
10001001
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
10011002
pthread_mutex_init(&o->replace_mutex, NULL);

odb.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct odb_source {
9191
};
9292

9393
struct packed_git;
94+
struct packfile_store;
9495
struct cached_object_entry;
9596

9697
/*
@@ -136,7 +137,7 @@ struct object_database {
136137
*
137138
* should only be accessed directly by packfile.c
138139
*/
139-
140+
struct packfile_store *packfiles;
140141
struct packed_git *packed_git;
141142
/* A most-recently-used ordered version of the packed_git list. */
142143
struct list_head packed_git_mru;

packfile.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,3 +2332,16 @@ int parse_pack_header_option(const char *in, unsigned char *out, unsigned int *l
23322332
*len = hdr - out;
23332333
return 0;
23342334
}
2335+
2336+
struct packfile_store *packfile_store_new(struct object_database *odb)
2337+
{
2338+
struct packfile_store *store;
2339+
CALLOC_ARRAY(store, 1);
2340+
store->odb = odb;
2341+
return store;
2342+
}
2343+
2344+
void packfile_store_free(struct packfile_store *store)
2345+
{
2346+
free(store);
2347+
}

packfile.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ struct packed_git {
5252
char pack_name[FLEX_ARRAY]; /* more */
5353
};
5454

55+
/*
56+
* A store that manages packfiles for a given object database.
57+
*/
58+
struct packfile_store {
59+
struct object_database *odb;
60+
};
61+
62+
/*
63+
* Allocate and initialize a new empty packfile store for the given object
64+
* database.
65+
*/
66+
struct packfile_store *packfile_store_new(struct object_database *odb);
67+
68+
/*
69+
* Free the packfile store and all its associated state.
70+
*/
71+
void packfile_store_free(struct packfile_store *store);
72+
5573
static inline int pack_map_entry_cmp(const void *cmp_data UNUSED,
5674
const struct hashmap_entry *entry,
5775
const struct hashmap_entry *entry2,

0 commit comments

Comments
 (0)