| 1363 | } |
| 1364 | |
| 1365 | void bitmap_writer_finish(struct bitmap_writer *writer, |
| 1366 | struct pack_idx_entry **index, |
| 1367 | const char *filename, |
| 1368 | uint16_t options) |
| 1369 | { |
| 1370 | static uint16_t default_version = 1; |
| 1371 | static uint16_t flags = BITMAP_OPT_FULL_DAG; |
| 1372 | struct strbuf tmp_file = STRBUF_INIT; |
| 1373 | struct hashfile *f; |
| 1374 | off_t *offsets = NULL; |
| 1375 | uint32_t i, base_objects; |
| 1376 | |
| 1377 | struct bitmap_disk_header header; |
| 1378 | |
| 1379 | int fd = odb_mkstemp(writer->repo->objects, &tmp_file, |
| 1380 | "pack/tmp_bitmap_XXXXXX"); |
| 1381 | |
| 1382 | if (writer->pseudo_merges_nr) |
| 1383 | options |= BITMAP_OPT_PSEUDO_MERGES; |
| 1384 | |
| 1385 | f = hashfd(writer->repo->hash_algo, fd, tmp_file.buf); |
| 1386 | |
| 1387 | memcpy(header.magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE)); |
| 1388 | header.version = htons(default_version); |
| 1389 | header.options = htons(flags | options); |
| 1390 | header.entry_count = htonl(bitmap_writer_nr_selected_commits(writer)); |
| 1391 | hashcpy(header.checksum, writer->pack_checksum, writer->repo->hash_algo); |
| 1392 | |
| 1393 | hashwrite(f, &header, sizeof(header) - GIT_MAX_RAWSZ + writer->repo->hash_algo->rawsz); |
| 1394 | dump_bitmap(f, writer->commits); |
| 1395 | dump_bitmap(f, writer->trees); |
| 1396 | dump_bitmap(f, writer->blobs); |
| 1397 | dump_bitmap(f, writer->tags); |
| 1398 | |
| 1399 | if (options & BITMAP_OPT_LOOKUP_TABLE) |
| 1400 | CALLOC_ARRAY(offsets, writer->to_pack->nr_objects); |
| 1401 | |
| 1402 | if (writer->midx) |
| 1403 | base_objects = writer->midx->num_objects + |
| 1404 | writer->midx->num_objects_in_base; |
| 1405 | else |
| 1406 | base_objects = 0; |
| 1407 | |
| 1408 | for (i = 0; i < bitmap_writer_nr_selected_commits(writer); i++) { |
| 1409 | struct bitmapped_commit *stored = &writer->selected[i]; |
| 1410 | int commit_pos = oid_pos(&stored->commit->object.oid, index, |
| 1411 | writer->to_pack->nr_objects, |
| 1412 | oid_access); |
| 1413 | |
| 1414 | if (commit_pos < 0) |
| 1415 | BUG("trying to write commit not in index"); |
| 1416 | stored->commit_pos = commit_pos + base_objects; |
| 1417 | } |
| 1418 | |
| 1419 | write_selected_commits_v1(writer, f, offsets); |
| 1420 | |
| 1421 | if (options & BITMAP_OPT_PSEUDO_MERGES) |
| 1422 | write_pseudo_merges(writer, f); |