packfile: refactor `get_multi_pack_index()` to work on sources
The function `get_multi_pack_index()` loads multi-pack indices via `prepare_packed_git()` and then returns the linked list of multi-pack indices that is stored in `struct object_database`. That list is in the process of being removed though in favor of storing the MIDX as part of the object database source it belongs to. Refactor `get_multi_pack_index()` so that it returns the multi-pack index for a single object source. Callers are now expected to call this function for each source they are interested in. This requires them to iterate through alternates, so we have to prepare alternate object sources before doing so. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
6567432ab4
commit
736bb725eb
|
@ -1706,8 +1706,8 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
|
||||||
uint32_t found_mtime)
|
uint32_t found_mtime)
|
||||||
{
|
{
|
||||||
int want;
|
int want;
|
||||||
|
struct odb_source *source;
|
||||||
struct list_head *pos;
|
struct list_head *pos;
|
||||||
struct multi_pack_index *m;
|
|
||||||
|
|
||||||
if (!exclude && local && has_loose_object_nonlocal(oid))
|
if (!exclude && local && has_loose_object_nonlocal(oid))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1727,9 +1727,13 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
|
||||||
*found_offset = 0;
|
*found_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (m = get_multi_pack_index(the_repository); m; m = m->next) {
|
odb_prepare_alternates(the_repository->objects);
|
||||||
|
|
||||||
|
for (source = the_repository->objects->sources; source; source = source->next) {
|
||||||
|
struct multi_pack_index *m = get_multi_pack_index(source);
|
||||||
struct pack_entry e;
|
struct pack_entry e;
|
||||||
if (fill_midx_entry(the_repository, oid, &e, m)) {
|
|
||||||
|
if (m && fill_midx_entry(the_repository, oid, &e, m)) {
|
||||||
want = want_object_in_pack_one(e.p, oid, exclude, found_pack, found_offset, found_mtime);
|
want = want_object_in_pack_one(e.p, oid, exclude, found_pack, found_offset, found_mtime);
|
||||||
if (want != -1)
|
if (want != -1)
|
||||||
return want;
|
return want;
|
||||||
|
|
|
@ -223,9 +223,9 @@ static void mark_packs_for_deletion(struct existing_packs *existing,
|
||||||
static void remove_redundant_pack(const char *dir_name, const char *base_name)
|
static void remove_redundant_pack(const char *dir_name, const char *base_name)
|
||||||
{
|
{
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
struct multi_pack_index *m = get_local_multi_pack_index(the_repository);
|
struct multi_pack_index *m = get_multi_pack_index(the_repository->objects->sources);
|
||||||
strbuf_addf(&buf, "%s.pack", base_name);
|
strbuf_addf(&buf, "%s.pack", base_name);
|
||||||
if (m && midx_contains_pack(m, buf.buf))
|
if (m && m->local && midx_contains_pack(m, buf.buf))
|
||||||
clear_midx_file(the_repository);
|
clear_midx_file(the_repository);
|
||||||
strbuf_insertf(&buf, 0, "%s/", dir_name);
|
strbuf_insertf(&buf, 0, "%s/", dir_name);
|
||||||
unlink_pack_path(buf.buf, 1);
|
unlink_pack_path(buf.buf, 1);
|
||||||
|
@ -1531,7 +1531,7 @@ int cmd_repack(int argc,
|
||||||
* midx_has_unknown_packs() will make the decision for
|
* midx_has_unknown_packs() will make the decision for
|
||||||
* us.
|
* us.
|
||||||
*/
|
*/
|
||||||
if (!get_local_multi_pack_index(the_repository))
|
if (!get_multi_pack_index(the_repository->objects->sources))
|
||||||
midx_must_contain_cruft = 1;
|
midx_must_contain_cruft = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1614,9 +1614,9 @@ int cmd_repack(int argc,
|
||||||
|
|
||||||
string_list_sort(&names);
|
string_list_sort(&names);
|
||||||
|
|
||||||
if (get_local_multi_pack_index(the_repository)) {
|
if (get_multi_pack_index(the_repository->objects->sources)) {
|
||||||
struct multi_pack_index *m =
|
struct multi_pack_index *m =
|
||||||
get_local_multi_pack_index(the_repository);
|
get_multi_pack_index(the_repository->objects->sources);
|
||||||
|
|
||||||
ALLOC_ARRAY(midx_pack_names,
|
ALLOC_ARRAY(midx_pack_names,
|
||||||
m->num_packs + m->num_packs_in_base);
|
m->num_packs + m->num_packs_in_base);
|
||||||
|
|
22
midx-write.c
22
midx-write.c
|
@ -916,26 +916,8 @@ cleanup:
|
||||||
static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
|
static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
|
||||||
const char *object_dir)
|
const char *object_dir)
|
||||||
{
|
{
|
||||||
struct multi_pack_index *result = NULL;
|
struct odb_source *source = odb_find_source(r->objects, object_dir);
|
||||||
struct multi_pack_index *cur;
|
return get_multi_pack_index(source);
|
||||||
char *obj_dir_real = real_pathdup(object_dir, 1);
|
|
||||||
struct strbuf cur_path_real = STRBUF_INIT;
|
|
||||||
|
|
||||||
/* Ensure the given object_dir is local, or a known alternate. */
|
|
||||||
odb_find_source(r->objects, obj_dir_real);
|
|
||||||
|
|
||||||
for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
|
|
||||||
strbuf_realpath(&cur_path_real, cur->object_dir, 1);
|
|
||||||
if (!strcmp(obj_dir_real, cur_path_real.buf)) {
|
|
||||||
result = cur;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
free(obj_dir_real);
|
|
||||||
strbuf_release(&cur_path_real);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fill_packs_from_midx(struct write_midx_context *ctx,
|
static int fill_packs_from_midx(struct write_midx_context *ctx,
|
||||||
|
|
|
@ -198,16 +198,20 @@ static void unique_in_pack(struct packed_git *p,
|
||||||
|
|
||||||
static void find_short_packed_object(struct disambiguate_state *ds)
|
static void find_short_packed_object(struct disambiguate_state *ds)
|
||||||
{
|
{
|
||||||
struct multi_pack_index *m;
|
struct odb_source *source;
|
||||||
struct packed_git *p;
|
struct packed_git *p;
|
||||||
|
|
||||||
/* Skip, unless oids from the storage hash algorithm are wanted */
|
/* Skip, unless oids from the storage hash algorithm are wanted */
|
||||||
if (ds->bin_pfx.algo && (&hash_algos[ds->bin_pfx.algo] != ds->repo->hash_algo))
|
if (ds->bin_pfx.algo && (&hash_algos[ds->bin_pfx.algo] != ds->repo->hash_algo))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (m = get_multi_pack_index(ds->repo); m && !ds->ambiguous;
|
odb_prepare_alternates(ds->repo->objects);
|
||||||
m = m->next)
|
for (source = ds->repo->objects->sources; source && !ds->ambiguous; source = source->next) {
|
||||||
unique_in_midx(m, ds);
|
struct multi_pack_index *m = get_multi_pack_index(source);
|
||||||
|
if (m)
|
||||||
|
unique_in_midx(m, ds);
|
||||||
|
}
|
||||||
|
|
||||||
for (p = get_packed_git(ds->repo); p && !ds->ambiguous;
|
for (p = get_packed_git(ds->repo); p && !ds->ambiguous;
|
||||||
p = p->next)
|
p = p->next)
|
||||||
unique_in_pack(p, ds);
|
unique_in_pack(p, ds);
|
||||||
|
@ -792,11 +796,15 @@ static void find_abbrev_len_for_pack(struct packed_git *p,
|
||||||
|
|
||||||
static void find_abbrev_len_packed(struct min_abbrev_data *mad)
|
static void find_abbrev_len_packed(struct min_abbrev_data *mad)
|
||||||
{
|
{
|
||||||
struct multi_pack_index *m;
|
|
||||||
struct packed_git *p;
|
struct packed_git *p;
|
||||||
|
|
||||||
for (m = get_multi_pack_index(mad->repo); m; m = m->next)
|
odb_prepare_alternates(mad->repo->objects);
|
||||||
find_abbrev_len_for_midx(m, mad);
|
for (struct odb_source *source = mad->repo->objects->sources; source; source = source->next) {
|
||||||
|
struct multi_pack_index *m = get_multi_pack_index(source);
|
||||||
|
if (m)
|
||||||
|
find_abbrev_len_for_midx(m, mad);
|
||||||
|
}
|
||||||
|
|
||||||
for (p = get_packed_git(mad->repo); p; p = p->next)
|
for (p = get_packed_git(mad->repo); p; p = p->next)
|
||||||
find_abbrev_len_for_pack(p, mad);
|
find_abbrev_len_for_pack(p, mad);
|
||||||
}
|
}
|
||||||
|
|
|
@ -691,13 +691,15 @@ static int open_pack_bitmap(struct repository *r,
|
||||||
static int open_midx_bitmap(struct repository *r,
|
static int open_midx_bitmap(struct repository *r,
|
||||||
struct bitmap_index *bitmap_git)
|
struct bitmap_index *bitmap_git)
|
||||||
{
|
{
|
||||||
|
struct odb_source *source;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
struct multi_pack_index *midx;
|
|
||||||
|
|
||||||
assert(!bitmap_git->map);
|
assert(!bitmap_git->map);
|
||||||
|
|
||||||
for (midx = get_multi_pack_index(r); midx; midx = midx->next) {
|
odb_prepare_alternates(r->objects);
|
||||||
if (!open_midx_bitmap_1(bitmap_git, midx))
|
for (source = r->objects->sources; source; source = source->next) {
|
||||||
|
struct multi_pack_index *midx = get_multi_pack_index(source);
|
||||||
|
if (midx && !open_midx_bitmap_1(bitmap_git, midx))
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -3305,11 +3307,18 @@ static int verify_bitmap_file(const struct git_hash_algo *algop,
|
||||||
|
|
||||||
int verify_bitmap_files(struct repository *r)
|
int verify_bitmap_files(struct repository *r)
|
||||||
{
|
{
|
||||||
|
struct odb_source *source;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
for (struct multi_pack_index *m = get_multi_pack_index(r);
|
odb_prepare_alternates(r->objects);
|
||||||
m; m = m->next) {
|
for (source = r->objects->sources; source; source = source->next) {
|
||||||
char *midx_bitmap_name = midx_bitmap_filename(m);
|
struct multi_pack_index *m = get_multi_pack_index(source);
|
||||||
|
char *midx_bitmap_name;
|
||||||
|
|
||||||
|
if (!m)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
midx_bitmap_name = midx_bitmap_filename(m);
|
||||||
res |= verify_bitmap_file(r->hash_algo, midx_bitmap_name);
|
res |= verify_bitmap_file(r->hash_algo, midx_bitmap_name);
|
||||||
free(midx_bitmap_name);
|
free(midx_bitmap_name);
|
||||||
}
|
}
|
||||||
|
|
31
packfile.c
31
packfile.c
|
@ -963,14 +963,18 @@ static void prepare_packed_git(struct repository *r);
|
||||||
unsigned long repo_approximate_object_count(struct repository *r)
|
unsigned long repo_approximate_object_count(struct repository *r)
|
||||||
{
|
{
|
||||||
if (!r->objects->approximate_object_count_valid) {
|
if (!r->objects->approximate_object_count_valid) {
|
||||||
unsigned long count;
|
struct odb_source *source;
|
||||||
struct multi_pack_index *m;
|
unsigned long count = 0;
|
||||||
struct packed_git *p;
|
struct packed_git *p;
|
||||||
|
|
||||||
prepare_packed_git(r);
|
prepare_packed_git(r);
|
||||||
count = 0;
|
|
||||||
for (m = get_multi_pack_index(r); m; m = m->next)
|
for (source = r->objects->sources; source; source = source->next) {
|
||||||
count += m->num_objects;
|
struct multi_pack_index *m = get_multi_pack_index(source);
|
||||||
|
if (m)
|
||||||
|
count += m->num_objects;
|
||||||
|
}
|
||||||
|
|
||||||
for (p = r->objects->packed_git; p; p = p->next) {
|
for (p = r->objects->packed_git; p; p = p->next) {
|
||||||
if (open_pack_index(p))
|
if (open_pack_index(p))
|
||||||
continue;
|
continue;
|
||||||
|
@ -1074,21 +1078,10 @@ struct packed_git *get_packed_git(struct repository *r)
|
||||||
return r->objects->packed_git;
|
return r->objects->packed_git;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct multi_pack_index *get_multi_pack_index(struct repository *r)
|
struct multi_pack_index *get_multi_pack_index(struct odb_source *source)
|
||||||
{
|
{
|
||||||
prepare_packed_git(r);
|
prepare_packed_git(source->odb->repo);
|
||||||
return r->objects->multi_pack_index;
|
return source->midx;
|
||||||
}
|
|
||||||
|
|
||||||
struct multi_pack_index *get_local_multi_pack_index(struct repository *r)
|
|
||||||
{
|
|
||||||
struct multi_pack_index *m = get_multi_pack_index(r);
|
|
||||||
|
|
||||||
/* no need to iterate; we always put the local one first (if any) */
|
|
||||||
if (m && m->local)
|
|
||||||
return m;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct packed_git *get_all_packs(struct repository *r)
|
struct packed_git *get_all_packs(struct repository *r)
|
||||||
|
|
|
@ -147,8 +147,7 @@ void install_packed_git(struct repository *r, struct packed_git *pack);
|
||||||
|
|
||||||
struct packed_git *get_packed_git(struct repository *r);
|
struct packed_git *get_packed_git(struct repository *r);
|
||||||
struct list_head *get_packed_git_mru(struct repository *r);
|
struct list_head *get_packed_git_mru(struct repository *r);
|
||||||
struct multi_pack_index *get_multi_pack_index(struct repository *r);
|
struct multi_pack_index *get_multi_pack_index(struct odb_source *source);
|
||||||
struct multi_pack_index *get_local_multi_pack_index(struct repository *r);
|
|
||||||
struct packed_git *get_all_packs(struct repository *r);
|
struct packed_git *get_all_packs(struct repository *r);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue