summaryrefslogtreecommitdiff
path: root/midx.c
diff options
context:
space:
mode:
Diffstat (limited to 'midx.c')
-rw-r--r--midx.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/midx.c b/midx.c
index 37ec28623a..9a61d3b37d 100644
--- a/midx.c
+++ b/midx.c
@@ -72,9 +72,9 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
FREE_AND_NULL(midx_name);
midx_map = xmmap(NULL, midx_size, PROT_READ, MAP_PRIVATE, fd, 0);
+ close(fd);
FLEX_ALLOC_STR(m, object_dir, object_dir);
- m->fd = fd;
m->data = midx_map;
m->data_len = midx_size;
m->local = local;
@@ -190,8 +190,6 @@ void close_midx(struct multi_pack_index *m)
return;
munmap((unsigned char *)m->data, m->data_len);
- close(m->fd);
- m->fd = -1;
for (i = 0; i < m->num_packs; i++) {
if (m->packs[i])
@@ -534,7 +532,7 @@ static void fill_pack_entry(uint32_t pack_int_id,
uint32_t cur_object,
struct pack_midx_entry *entry)
{
- if (!nth_packed_object_oid(&entry->oid, p, cur_object))
+ if (nth_packed_object_id(&entry->oid, p, cur_object) < 0)
die(_("failed to locate object %d in packfile"), cur_object);
entry->pack_int_id = pack_int_id;
@@ -923,6 +921,12 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
cur_chunk = 0;
num_chunks = large_offsets_needed ? 5 : 4;
+ if (packs.nr - dropped_packs == 0) {
+ error(_("no pack files to index."));
+ result = 1;
+ goto cleanup;
+ }
+
written = write_midx_header(f, num_chunks, packs.nr - dropped_packs);
chunk_ids[cur_chunk] = MIDX_CHUNKID_PACKNAMES;
@@ -1124,6 +1128,15 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
i, oid_fanout1, oid_fanout2, i + 1);
}
+ if (m->num_objects == 0) {
+ midx_report(_("the midx contains no oid"));
+ /*
+ * Remaining tests assume that we have objects, so we can
+ * return here.
+ */
+ return verify_midx_error;
+ }
+
if (flags & MIDX_PROGRESS)
progress = start_sparse_progress(_("Verifying OID order in multi-pack-index"),
m->num_objects - 1);