return xstrfmt("%s/pack/multi-pack-index", object_dir);
}
-struct multi_pack_index *load_multi_pack_index(const char *object_dir)
+struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local)
{
struct multi_pack_index *m = NULL;
int fd;
m->fd = fd;
m->data = midx_map;
m->data_len = midx_size;
+ m->local = local;
m->signature = get_be32(m->data);
if (m->signature != MIDX_SIGNATURE) {
for (i = 0; i < m->num_packs; i++) {
if (m->packs[i]) {
close_pack(m->packs[i]);
- free(m->packs);
+ free(m->packs[i]);
}
}
FREE_AND_NULL(m->packs);
FREE_AND_NULL(m->pack_names);
}
-static int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
+int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
{
struct strbuf pack_name = STRBUF_INIT;
strbuf_addf(&pack_name, "%s/pack/%s", m->object_dir,
m->pack_names[pack_int_id]);
- m->packs[pack_int_id] = add_packed_git(pack_name.buf, pack_name.len, 1);
+ m->packs[pack_int_id] = add_packed_git(pack_name.buf, pack_name.len, m->local);
strbuf_release(&pack_name);
return !m->packs[pack_int_id];
}
if (!is_pack_valid(p))
return 0;
+ if (p->num_bad_objects) {
+ uint32_t i;
+ struct object_id oid;
+ nth_midxed_object_oid(&oid, m, pos);
+ for (i = 0; i < p->num_bad_objects; i++)
+ if (!hashcmp(oid.hash,
+ p->bad_object_sha1 + the_hash_algo->rawsz * i))
+ return 0;
+ }
+
e->offset = nth_midxed_offset(m, pos);
e->p = p;
return 0;
}
-int prepare_multi_pack_index_one(struct repository *r, const char *object_dir)
+int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local)
{
- struct multi_pack_index *m = r->objects->multi_pack_index;
+ struct multi_pack_index *m;
struct multi_pack_index *m_search;
int config_value;
!config_value)
return 0;
- for (m_search = m; m_search; m_search = m_search->next)
+ for (m_search = r->objects->multi_pack_index; m_search; m_search = m_search->next)
if (!strcmp(object_dir, m_search->object_dir))
return 1;
- r->objects->multi_pack_index = load_multi_pack_index(object_dir);
+ m = load_multi_pack_index(object_dir, local);
- if (r->objects->multi_pack_index) {
- r->objects->multi_pack_index->next = m;
+ if (m) {
+ m->next = r->objects->multi_pack_index;
+ r->objects->multi_pack_index = m;
return 1;
}
midx_name);
}
- packs.m = load_multi_pack_index(object_dir);
+ packs.m = load_multi_pack_index(object_dir, 1);
packs.nr = 0;
packs.alloc_list = packs.m ? packs.m->num_packs : 16;
free(midx_name);
return 0;
}
+
+void clear_midx_file(const char *object_dir)
+{
+ char *midx = get_midx_filename(object_dir);
+
+ if (remove_path(midx)) {
+ UNLEAK(midx);
+ die(_("failed to clear multi-pack-index at %s"), midx);
+ }
+
+ free(midx);
+}