MCPcopy Create free account
hub / github.com/git/git / load_multi_pack_index_one

Function load_multi_pack_index_one

midx.c:109–235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109static 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

Callers 2

load_midx_chain_fd_stFunction · 0.85
load_multi_pack_indexFunction · 0.85

Calls 13

error_errnoFunction · 0.85
xsize_tFunction · 0.85
errorFunction · 0.85
xmmapFunction · 0.85
get_be32Function · 0.85
oid_versionFunction · 0.85
init_chunkfileFunction · 0.85
read_table_of_contentsFunction · 0.85
pair_chunkFunction · 0.85
read_chunkFunction · 0.85
git_env_boolFunction · 0.85
free_chunkfileFunction · 0.85

Tested by

no test coverage detected