| 107 | } |
| 108 | |
| 109 | static struct multi_pack_index *load_multi_pack_index_one(struct odb_source *source, |
| 110 | const char *midx_name) |
| 111 | { |
| 112 | struct repository *r = source->odb->repo; |
| 113 | struct multi_pack_index *m = NULL; |
| 114 | int fd; |
| 115 | struct stat st; |
| 116 | size_t midx_size; |
| 117 | void *midx_map = NULL; |
| 118 | uint32_t hash_version; |
| 119 | uint32_t i; |
| 120 | const char *cur_pack_name; |
| 121 | struct chunkfile *cf = NULL; |
| 122 | |
| 123 | fd = git_open(midx_name); |
| 124 | |
| 125 | if (fd < 0) |
| 126 | goto cleanup_fail; |
| 127 | if (fstat(fd, &st)) { |
| 128 | error_errno(_("failed to read %s"), midx_name); |
| 129 | goto cleanup_fail; |
| 130 | } |
| 131 | |
| 132 | midx_size = xsize_t(st.st_size); |
| 133 | |
| 134 | if (midx_size < (MIDX_HEADER_SIZE + r->hash_algo->rawsz)) { |
| 135 | error(_("multi-pack-index file %s is too small"), midx_name); |
| 136 | goto cleanup_fail; |
| 137 | } |
| 138 | |
| 139 | midx_map = xmmap(NULL, midx_size, PROT_READ, MAP_PRIVATE, fd, 0); |
| 140 | close(fd); |
| 141 | |
| 142 | CALLOC_ARRAY(m, 1); |
| 143 | m->data = midx_map; |
| 144 | m->data_len = midx_size; |
| 145 | m->source = source; |
| 146 | |
| 147 | m->signature = get_be32(m->data); |
| 148 | if (m->signature != MIDX_SIGNATURE) |
| 149 | die(_("multi-pack-index signature 0x%08x does not match signature 0x%08x"), |
| 150 | m->signature, MIDX_SIGNATURE); |
| 151 | |
| 152 | m->version = m->data[MIDX_BYTE_FILE_VERSION]; |
| 153 | if (m->version != MIDX_VERSION_V1 && m->version != MIDX_VERSION_V2) |
| 154 | die(_("multi-pack-index version %d not recognized"), |
| 155 | m->version); |
| 156 | |
| 157 | hash_version = m->data[MIDX_BYTE_HASH_VERSION]; |
| 158 | if (hash_version != oid_version(r->hash_algo)) { |
| 159 | error(_("multi-pack-index hash version %u does not match version %u"), |
| 160 | hash_version, oid_version(r->hash_algo)); |
| 161 | goto cleanup_fail; |
| 162 | } |
| 163 | m->hash_len = r->hash_algo->rawsz; |
| 164 | |
| 165 | m->num_chunks = m->data[MIDX_BYTE_NUM_CHUNKS]; |
| 166 |
no test coverage detected