Skip to content

Commit 0bff526

Browse files
derrickstoleegitster
authored andcommitted
packfile: add all_packs list
If a repo contains a multi-pack-index, then the packed_git list does not contain the packfiles that are covered by the multi-pack-index. This is important for doing object lookups, abbreviations, and approximating object count. However, there are many operations that really want to iterate over all packfiles. Create a new 'all_packs' linked list that contains this list, starting with the packfiles in the multi-pack-index and then continuing along the packed_git linked list. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 29e2016 commit 0bff526

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

midx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static void close_midx(struct multi_pack_index *m)
197197
FREE_AND_NULL(m->pack_names);
198198
}
199199

200-
static int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
200+
int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
201201
{
202202
struct strbuf pack_name = STRBUF_INIT;
203203

midx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct multi_pack_index {
3232
};
3333

3434
struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
35+
int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id);
3536
int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result);
3637
struct object_id *nth_midxed_object_oid(struct object_id *oid,
3738
struct multi_pack_index *m,

object-store.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ struct raw_object_store {
129129
/* A most-recently-used ordered version of the packed_git list. */
130130
struct list_head packed_git_mru;
131131

132+
/*
133+
* A linked list containing all packfiles, starting with those
134+
* contained in the multi_pack_index.
135+
*/
136+
struct packed_git *all_packs;
137+
132138
/*
133139
* A fast, rough count of the number of objects in the repository.
134140
* These two fields are not meant for direct access. Use

packfile.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,9 @@ static void prepare_packed_git(struct repository *r)
972972
prepare_packed_git_one(r, alt->path, 0);
973973
}
974974
rearrange_packed_git(r);
975+
976+
r->objects->all_packs = NULL;
977+
975978
prepare_packed_git_mru(r);
976979
r->objects->packed_git_initialized = 1;
977980
}
@@ -995,6 +998,30 @@ struct multi_pack_index *get_multi_pack_index(struct repository *r)
995998
return r->objects->multi_pack_index;
996999
}
9971000

1001+
struct packed_git *get_all_packs(struct repository *r)
1002+
{
1003+
prepare_packed_git(r);
1004+
1005+
if (!r->objects->all_packs) {
1006+
struct packed_git *p = r->objects->packed_git;
1007+
struct multi_pack_index *m;
1008+
1009+
for (m = r->objects->multi_pack_index; m; m = m->next) {
1010+
uint32_t i;
1011+
for (i = 0; i < m->num_packs; i++) {
1012+
if (!prepare_midx_pack(m, i)) {
1013+
m->packs[i]->next = p;
1014+
p = m->packs[i];
1015+
}
1016+
}
1017+
}
1018+
1019+
r->objects->all_packs = p;
1020+
}
1021+
1022+
return r->objects->all_packs;
1023+
}
1024+
9981025
struct list_head *get_packed_git_mru(struct repository *r)
9991026
{
10001027
prepare_packed_git(r);

packfile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ extern void install_packed_git(struct repository *r, struct packed_git *pack);
5151
struct packed_git *get_packed_git(struct repository *r);
5252
struct list_head *get_packed_git_mru(struct repository *r);
5353
struct multi_pack_index *get_multi_pack_index(struct repository *r);
54+
struct packed_git *get_all_packs(struct repository *r);
5455

5556
/*
5657
* Give a rough count of objects in the repository. This sacrifices accuracy

0 commit comments

Comments
 (0)