Skip to content

Commit 733b640

Browse files
committed
Merge branch 'ps/object-store-midx'
Redefine where the multi-pack-index sits in the object subsystem, which recently was restructured to allow multiple backends that support a single object source that belongs to one repository. A midx does span mulitple "object sources". * ps/object-store-midx: midx: remove now-unused linked list of multi-pack indices packfile: stop using linked MIDX list in `get_all_packs()` packfile: stop using linked MIDX list in `find_pack_entry()` packfile: refactor `get_multi_pack_index()` to work on sources midx: stop using linked list when closing MIDX packfile: refactor `prepare_packed_git_one()` to work on sources midx: start tracking per object database source
2 parents 8d9f536 + ec865d9 commit 733b640

File tree

10 files changed

+107
-124
lines changed

10 files changed

+107
-124
lines changed

builtin/pack-objects.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,8 +1706,8 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
17061706
uint32_t found_mtime)
17071707
{
17081708
int want;
1709+
struct odb_source *source;
17091710
struct list_head *pos;
1710-
struct multi_pack_index *m;
17111711

17121712
if (!exclude && local && has_loose_object_nonlocal(oid))
17131713
return 0;
@@ -1727,9 +1727,13 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
17271727
*found_offset = 0;
17281728
}
17291729

1730-
for (m = get_multi_pack_index(the_repository); m; m = m->next) {
1730+
odb_prepare_alternates(the_repository->objects);
1731+
1732+
for (source = the_repository->objects->sources; source; source = source->next) {
1733+
struct multi_pack_index *m = get_multi_pack_index(source);
17311734
struct pack_entry e;
1732-
if (fill_midx_entry(the_repository, oid, &e, m)) {
1735+
1736+
if (m && fill_midx_entry(the_repository, oid, &e, m)) {
17331737
want = want_object_in_pack_one(e.p, oid, exclude, found_pack, found_offset, found_mtime);
17341738
if (want != -1)
17351739
return want;

builtin/repack.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ static void mark_packs_for_deletion(struct existing_packs *existing,
223223
static void remove_redundant_pack(const char *dir_name, const char *base_name)
224224
{
225225
struct strbuf buf = STRBUF_INIT;
226-
struct multi_pack_index *m = get_local_multi_pack_index(the_repository);
226+
struct multi_pack_index *m = get_multi_pack_index(the_repository->objects->sources);
227227
strbuf_addf(&buf, "%s.pack", base_name);
228-
if (m && midx_contains_pack(m, buf.buf))
228+
if (m && m->local && midx_contains_pack(m, buf.buf))
229229
clear_midx_file(the_repository);
230230
strbuf_insertf(&buf, 0, "%s/", dir_name);
231231
unlink_pack_path(buf.buf, 1);
@@ -1531,7 +1531,7 @@ int cmd_repack(int argc,
15311531
* midx_has_unknown_packs() will make the decision for
15321532
* us.
15331533
*/
1534-
if (!get_local_multi_pack_index(the_repository))
1534+
if (!get_multi_pack_index(the_repository->objects->sources))
15351535
midx_must_contain_cruft = 1;
15361536
}
15371537

@@ -1614,9 +1614,9 @@ int cmd_repack(int argc,
16141614

16151615
string_list_sort(&names);
16161616

1617-
if (get_local_multi_pack_index(the_repository)) {
1617+
if (get_multi_pack_index(the_repository->objects->sources)) {
16181618
struct multi_pack_index *m =
1619-
get_local_multi_pack_index(the_repository);
1619+
get_multi_pack_index(the_repository->objects->sources);
16201620

16211621
ALLOC_ARRAY(midx_pack_names,
16221622
m->num_packs + m->num_packs_in_base);

midx-write.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -916,26 +916,8 @@ static int write_midx_bitmap(struct write_midx_context *ctx,
916916
static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
917917
const char *object_dir)
918918
{
919-
struct multi_pack_index *result = NULL;
920-
struct multi_pack_index *cur;
921-
char *obj_dir_real = real_pathdup(object_dir, 1);
922-
struct strbuf cur_path_real = STRBUF_INIT;
923-
924-
/* Ensure the given object_dir is local, or a known alternate. */
925-
odb_find_source(r->objects, obj_dir_real);
926-
927-
for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
928-
strbuf_realpath(&cur_path_real, cur->object_dir, 1);
929-
if (!strcmp(obj_dir_real, cur_path_real.buf)) {
930-
result = cur;
931-
goto cleanup;
932-
}
933-
}
934-
935-
cleanup:
936-
free(obj_dir_real);
937-
strbuf_release(&cur_path_real);
938-
return result;
919+
struct odb_source *source = odb_find_source(r->objects, object_dir);
920+
return get_multi_pack_index(source);
939921
}
940922

941923
static int fill_packs_from_midx(struct write_midx_context *ctx,

midx.c

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ void close_midx(struct multi_pack_index *m)
401401
if (!m)
402402
return;
403403

404-
close_midx(m->next);
405404
close_midx(m->base_midx);
406405

407406
munmap((unsigned char *)m->data, m->data_len);
@@ -724,32 +723,20 @@ int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id)
724723
return 0;
725724
}
726725

727-
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local)
726+
int prepare_multi_pack_index_one(struct odb_source *source, int local)
728727
{
729-
struct multi_pack_index *m;
730-
struct multi_pack_index *m_search;
728+
struct repository *r = source->odb->repo;
731729

732730
prepare_repo_settings(r);
733731
if (!r->settings.core_multi_pack_index)
734732
return 0;
735733

736-
for (m_search = r->objects->multi_pack_index; m_search; m_search = m_search->next)
737-
if (!strcmp(object_dir, m_search->object_dir))
738-
return 1;
739-
740-
m = load_multi_pack_index(r, object_dir, local);
741-
742-
if (m) {
743-
struct multi_pack_index *mp = r->objects->multi_pack_index;
744-
if (mp) {
745-
m->next = mp->next;
746-
mp->next = m;
747-
} else
748-
r->objects->multi_pack_index = m;
734+
if (source->midx)
749735
return 1;
750-
}
751736

752-
return 0;
737+
source->midx = load_multi_pack_index(r, source->path, local);
738+
739+
return !!source->midx;
753740
}
754741

755742
int midx_checksum_valid(struct multi_pack_index *m)
@@ -834,9 +821,14 @@ void clear_midx_file(struct repository *r)
834821

835822
get_midx_filename(r->hash_algo, &midx, r->objects->sources->path);
836823

837-
if (r->objects && r->objects->multi_pack_index) {
838-
close_midx(r->objects->multi_pack_index);
839-
r->objects->multi_pack_index = NULL;
824+
if (r->objects) {
825+
struct odb_source *source;
826+
827+
for (source = r->objects->sources; source; source = source->next) {
828+
if (source->midx)
829+
close_midx(source->midx);
830+
source->midx = NULL;
831+
}
840832
}
841833

842834
if (remove_path(midx.buf))

midx.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ struct pack_entry;
88
struct repository;
99
struct bitmapped_pack;
1010
struct git_hash_algo;
11+
struct odb_source;
1112

1213
#define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */
1314
#define MIDX_VERSION 1
@@ -34,8 +35,6 @@ struct git_hash_algo;
3435
"GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL"
3536

3637
struct multi_pack_index {
37-
struct multi_pack_index *next;
38-
3938
const unsigned char *data;
4039
size_t data_len;
4140

@@ -123,7 +122,7 @@ int fill_midx_entry(struct repository *r, const struct object_id *oid, struct pa
123122
int midx_contains_pack(struct multi_pack_index *m,
124123
const char *idx_or_pack_name);
125124
int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id);
126-
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local);
125+
int prepare_multi_pack_index_one(struct odb_source *source, int local);
127126

128127
/*
129128
* Variant of write_midx_file which writes a MIDX containing only the packs

object-name.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,20 @@ static void unique_in_pack(struct packed_git *p,
199199

200200
static void find_short_packed_object(struct disambiguate_state *ds)
201201
{
202-
struct multi_pack_index *m;
202+
struct odb_source *source;
203203
struct packed_git *p;
204204

205205
/* Skip, unless oids from the storage hash algorithm are wanted */
206206
if (ds->bin_pfx.algo && (&hash_algos[ds->bin_pfx.algo] != ds->repo->hash_algo))
207207
return;
208208

209-
for (m = get_multi_pack_index(ds->repo); m && !ds->ambiguous;
210-
m = m->next)
211-
unique_in_midx(m, ds);
209+
odb_prepare_alternates(ds->repo->objects);
210+
for (source = ds->repo->objects->sources; source && !ds->ambiguous; source = source->next) {
211+
struct multi_pack_index *m = get_multi_pack_index(source);
212+
if (m)
213+
unique_in_midx(m, ds);
214+
}
215+
212216
for (p = get_packed_git(ds->repo); p && !ds->ambiguous;
213217
p = p->next)
214218
unique_in_pack(p, ds);
@@ -793,11 +797,15 @@ static void find_abbrev_len_for_pack(struct packed_git *p,
793797

794798
static void find_abbrev_len_packed(struct min_abbrev_data *mad)
795799
{
796-
struct multi_pack_index *m;
797800
struct packed_git *p;
798801

799-
for (m = get_multi_pack_index(mad->repo); m; m = m->next)
800-
find_abbrev_len_for_midx(m, mad);
802+
odb_prepare_alternates(mad->repo->objects);
803+
for (struct odb_source *source = mad->repo->objects->sources; source; source = source->next) {
804+
struct multi_pack_index *m = get_multi_pack_index(source);
805+
if (m)
806+
find_abbrev_len_for_midx(m, mad);
807+
}
808+
801809
for (p = get_packed_git(mad->repo); p; p = p->next)
802810
find_abbrev_len_for_pack(p, mad);
803811
}

odb.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct oidmap;
1313
struct oidtree;
1414
struct strbuf;
1515
struct repository;
16+
struct multi_pack_index;
1617

1718
/*
1819
* Compute the exact path an alternate is at and returns it. In case of
@@ -55,6 +56,13 @@ struct odb_source {
5556
/* Map between object IDs for loose objects. */
5657
struct loose_object_map *loose_map;
5758

59+
/*
60+
* private data
61+
*
62+
* should only be accessed directly by packfile.c and midx.c
63+
*/
64+
struct multi_pack_index *midx;
65+
5866
/*
5967
* This is a temporary object store created by the tmp_objdir
6068
* facility. Disable ref updates since the objects in the store
@@ -75,7 +83,6 @@ struct odb_source {
7583
};
7684

7785
struct packed_git;
78-
struct multi_pack_index;
7986
struct cached_object_entry;
8087

8188
/*
@@ -116,13 +123,6 @@ struct object_database {
116123
struct commit_graph *commit_graph;
117124
unsigned commit_graph_attempted : 1; /* if loading has been attempted */
118125

119-
/*
120-
* private data
121-
*
122-
* should only be accessed directly by packfile.c and midx.c
123-
*/
124-
struct multi_pack_index *multi_pack_index;
125-
126126
/*
127127
* private data
128128
*

pack-bitmap.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -683,13 +683,15 @@ static int open_pack_bitmap(struct repository *r,
683683
static int open_midx_bitmap(struct repository *r,
684684
struct bitmap_index *bitmap_git)
685685
{
686+
struct odb_source *source;
686687
int ret = -1;
687-
struct multi_pack_index *midx;
688688

689689
assert(!bitmap_git->map);
690690

691-
for (midx = get_multi_pack_index(r); midx; midx = midx->next) {
692-
if (!open_midx_bitmap_1(bitmap_git, midx))
691+
odb_prepare_alternates(r->objects);
692+
for (source = r->objects->sources; source; source = source->next) {
693+
struct multi_pack_index *midx = get_multi_pack_index(source);
694+
if (midx && !open_midx_bitmap_1(bitmap_git, midx))
693695
ret = 0;
694696
}
695697
return ret;
@@ -3345,11 +3347,18 @@ static int verify_bitmap_file(const struct git_hash_algo *algop,
33453347

33463348
int verify_bitmap_files(struct repository *r)
33473349
{
3350+
struct odb_source *source;
33483351
int res = 0;
33493352

3350-
for (struct multi_pack_index *m = get_multi_pack_index(r);
3351-
m; m = m->next) {
3352-
char *midx_bitmap_name = midx_bitmap_filename(m);
3353+
odb_prepare_alternates(r->objects);
3354+
for (source = r->objects->sources; source; source = source->next) {
3355+
struct multi_pack_index *m = get_multi_pack_index(source);
3356+
char *midx_bitmap_name;
3357+
3358+
if (!m)
3359+
continue;
3360+
3361+
midx_bitmap_name = midx_bitmap_filename(m);
33533362
res |= verify_bitmap_file(r->hash_algo, midx_bitmap_name);
33543363
free(midx_bitmap_name);
33553364
}

0 commit comments

Comments
 (0)