int prepare_packs)
{
for (uint32_t i = 0; i < m->num_packs; i++) {
- /*
- * If generating a reverse index, need to have
- * packed_git's loaded to compare their
- * mtimes and object count.
- */
+ struct packed_git *p = NULL;
+
+ ALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc);
if (prepare_packs) {
- if (prepare_midx_pack(ctx->repo, m,
- m->num_packs_in_base + i)) {
+ p = prepare_midx_pack(ctx->repo, m,
+ m->num_packs_in_base + i);
+ if (!p) {
error(_("could not load pack"));
return 1;
}
- if (open_pack_index(m->packs[i]))
+ if (open_pack_index(p))
die(_("could not open index for %s"),
- m->packs[i]->pack_name);
+ p->pack_name);
}
- fill_pack_info(&ctx->info[ctx->nr++], m->packs[i],
- m->pack_names[i],
+ fill_pack_info(&ctx->info[ctx->nr++], p, m->pack_names[i],
m->num_packs_in_base + i);
}
_("Finding and deleting unreferenced packfiles"),
m->num_packs);
for (i = 0; i < m->num_packs; i++) {
+ struct packed_git *p;
char *pack_name;
display_progress(progress, i + 1);
if (count[i])
continue;
- if (prepare_midx_pack(r, m, i))
- continue;
-
- if (m->packs[i]->pack_keep || m->packs[i]->is_cruft)
+ p = prepare_midx_pack(r, m, i);
+ if (!p || p->pack_keep || p->is_cruft)
continue;
- pack_name = xstrdup(m->packs[i]->pack_name);
- close_pack(m->packs[i]);
+ pack_name = xstrdup(p->pack_name);
+ close_pack(p);
string_list_insert(&packs_to_drop, m->pack_names[i]);
unlink_pack_path(pack_name, 0);
ASSERT(m && !m->base_midx);
- if (prepare_midx_pack(r, m, pack_int_id))
+ p = prepare_midx_pack(r, m, pack_int_id);
+ if (!p)
return 0;
- p = m->packs[pack_int_id];
if (!pack_kept_objects && p->pack_keep)
return 0;
if (p->is_cruft)
repo_config_get_bool(r, "repack.packkeptobjects", &pack_kept_objects);
for (i = 0; i < m->num_packs; i++) {
- pack_info[i].pack_int_id = i;
+ struct packed_git *p = prepare_midx_pack(r, m, i);
- if (prepare_midx_pack(r, m, i))
- continue;
-
- pack_info[i].mtime = m->packs[i]->mtime;
+ pack_info[i].pack_int_id = i;
+ if (p)
+ pack_info[i].mtime = p->mtime;
}
for (i = 0; i < m->num_objects; i++) {
return pack_int_id - m->num_packs_in_base;
}
-int prepare_midx_pack(struct repository *r, struct multi_pack_index *m,
- uint32_t pack_int_id)
+struct packed_git *prepare_midx_pack(struct repository *r,
+ struct multi_pack_index *m,
+ uint32_t pack_int_id)
{
- struct strbuf pack_name = STRBUF_INIT;
- struct strbuf key = STRBUF_INIT;
- struct packed_git *p;
-
- pack_int_id = midx_for_pack(&m, pack_int_id);
-
- if (m->packs[pack_int_id] == MIDX_PACK_ERROR)
- return 1;
- if (m->packs[pack_int_id])
- return 0;
-
- strbuf_addf(&pack_name, "%s/pack/%s", m->object_dir,
- m->pack_names[pack_int_id]);
-
- /* pack_map holds the ".pack" name, but we have the .idx */
- strbuf_addbuf(&key, &pack_name);
- strbuf_strip_suffix(&key, ".idx");
- strbuf_addstr(&key, ".pack");
- p = hashmap_get_entry_from_hash(&r->objects->pack_map,
- strhash(key.buf), key.buf,
- struct packed_git, packmap_ent);
- if (!p) {
- p = add_packed_git(r, pack_name.buf, pack_name.len, m->local);
- if (p) {
- install_packed_git(r, p);
- list_add_tail(&p->mru, &r->objects->packed_git_mru);
+ uint32_t pack_pos = midx_for_pack(&m, pack_int_id);
+
+ if (!m->packs[pack_pos]) {
+ struct strbuf pack_name = STRBUF_INIT;
+ struct strbuf key = STRBUF_INIT;
+ struct packed_git *p;
+
+ strbuf_addf(&pack_name, "%s/pack/%s", m->object_dir,
+ m->pack_names[pack_pos]);
+
+ /* pack_map holds the ".pack" name, but we have the .idx */
+ strbuf_addbuf(&key, &pack_name);
+ strbuf_strip_suffix(&key, ".idx");
+ strbuf_addstr(&key, ".pack");
+ p = hashmap_get_entry_from_hash(&r->objects->pack_map,
+ strhash(key.buf), key.buf,
+ struct packed_git, packmap_ent);
+ if (!p) {
+ p = add_packed_git(r, pack_name.buf, pack_name.len,
+ m->local);
+ if (p) {
+ install_packed_git(r, p);
+ list_add_tail(&p->mru,
+ &r->objects->packed_git_mru);
+ }
}
- }
- strbuf_release(&pack_name);
- strbuf_release(&key);
+ strbuf_release(&pack_name);
+ strbuf_release(&key);
- if (!p) {
- m->packs[pack_int_id] = MIDX_PACK_ERROR;
- return 1;
+ m->packs[pack_pos] = p ? p : MIDX_PACK_ERROR;
+ if (p)
+ p->multi_pack_index = 1;
}
- p->multi_pack_index = 1;
- m->packs[pack_int_id] = p;
-
- return 0;
+ if (m->packs[pack_pos] == MIDX_PACK_ERROR)
+ return NULL;
+ return m->packs[pack_pos];
}
struct packed_git *nth_midxed_pack(struct multi_pack_index *m,
if (!m->chunk_bitmapped_packs)
return error(_("MIDX does not contain the BTMP chunk"));
- if (prepare_midx_pack(r, m, pack_int_id))
- return error(_("could not load bitmapped pack %"PRIu32), pack_int_id);
+ bp->p = prepare_midx_pack(r, m, pack_int_id);
+ if (!bp->p)
+ return error(_("could not load bitmapped pack %"PRIu32),
+ pack_int_id);
- bp->p = m->packs[local_pack_int_id];
bp->bitmap_pos = get_be32((char *)m->chunk_bitmapped_packs +
MIDX_CHUNK_BITMAPPED_PACKS_WIDTH * local_pack_int_id);
bp->bitmap_nr = get_be32((char *)m->chunk_bitmapped_packs +
midx_for_object(&m, pos);
pack_int_id = nth_midxed_pack_int_id(m, pos);
- if (prepare_midx_pack(r, m, pack_int_id))
+ p = prepare_midx_pack(r, m, pack_int_id);
+ if (!p)
return 0;
- p = m->packs[pack_int_id - m->num_packs_in_base];
/*
* We are about to tell the caller where they can locate the
_("Looking for referenced packfiles"),
m->num_packs + m->num_packs_in_base);
for (i = 0; i < m->num_packs + m->num_packs_in_base; i++) {
- if (prepare_midx_pack(r, m, i))
+ if (!prepare_midx_pack(r, m, i))
midx_report("failed to load pack in position %d", i);
display_progress(progress, i + 1);