| 371 | } |
| 372 | |
| 373 | struct commit_graph *parse_commit_graph(struct repository *r, |
| 374 | void *graph_map, size_t graph_size) |
| 375 | { |
| 376 | const unsigned char *data; |
| 377 | struct commit_graph *graph; |
| 378 | uint32_t graph_signature; |
| 379 | unsigned char graph_version, hash_version; |
| 380 | struct chunkfile *cf = NULL; |
| 381 | |
| 382 | if (!graph_map) |
| 383 | return NULL; |
| 384 | |
| 385 | if (graph_size < graph_min_size(r->hash_algo)) |
| 386 | return NULL; |
| 387 | |
| 388 | data = (const unsigned char *)graph_map; |
| 389 | |
| 390 | graph_signature = get_be32(data); |
| 391 | if (graph_signature != GRAPH_SIGNATURE) { |
| 392 | error(_("commit-graph signature %X does not match signature %X"), |
| 393 | graph_signature, GRAPH_SIGNATURE); |
| 394 | return NULL; |
| 395 | } |
| 396 | |
| 397 | graph_version = *(unsigned char*)(data + 4); |
| 398 | if (graph_version != GRAPH_VERSION) { |
| 399 | error(_("commit-graph version %X does not match version %X"), |
| 400 | graph_version, GRAPH_VERSION); |
| 401 | return NULL; |
| 402 | } |
| 403 | |
| 404 | hash_version = *(unsigned char*)(data + 5); |
| 405 | if (hash_version != oid_version(r->hash_algo)) { |
| 406 | error(_("commit-graph hash version %X does not match version %X"), |
| 407 | hash_version, oid_version(r->hash_algo)); |
| 408 | return NULL; |
| 409 | } |
| 410 | |
| 411 | graph = alloc_commit_graph(); |
| 412 | |
| 413 | graph->hash_algo = r->hash_algo; |
| 414 | graph->num_chunks = *(unsigned char*)(data + 6); |
| 415 | graph->data = graph_map; |
| 416 | graph->data_len = graph_size; |
| 417 | |
| 418 | if (graph_size < GRAPH_HEADER_SIZE + |
| 419 | (graph->num_chunks + 1) * CHUNK_TOC_ENTRY_SIZE + |
| 420 | GRAPH_FANOUT_SIZE + r->hash_algo->rawsz) { |
| 421 | error(_("commit-graph file is too small to hold %u chunks"), |
| 422 | graph->num_chunks); |
| 423 | free(graph); |
| 424 | return NULL; |
| 425 | } |
| 426 | |
| 427 | cf = init_chunkfile(NULL); |
| 428 | |
| 429 | if (read_table_of_contents(cf, graph->data, graph_size, |
| 430 | GRAPH_HEADER_SIZE, graph->num_chunks, 1)) |
no test coverage detected