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

Function write_object_record

reftable/writer.c:614–671  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

612};
613
614static void write_object_record(void *void_arg, void *key)
615{
616 struct write_record_arg *arg = void_arg;
617 struct obj_index_tree_node *entry = key;
618 struct reftable_record
619 rec = { .type = REFTABLE_BLOCK_TYPE_OBJ,
620 .u.obj = {
621 .hash_prefix = (uint8_t *)entry->hash.buf,
622 .hash_prefix_len = arg->w->stats.object_id_len,
623 .offsets = entry->offsets,
624 .offset_len = entry->offset_len,
625 } };
626 if (arg->err < 0)
627 goto done;
628
629 /*
630 * Try to add the record to the writer. If this succeeds then we're
631 * done. Otherwise the block writer may have hit the block size limit
632 * and needs to be flushed.
633 */
634 arg->err = block_writer_add(arg->w->block_writer, &rec);
635 if (arg->err == 0)
636 goto done;
637
638 if (arg->err != REFTABLE_ENTRY_TOO_BIG_ERROR)
639 goto done;
640
641 /*
642 * The current block is full, so we need to flush and reinitialize the
643 * writer to start writing the next block.
644 */
645 arg->err = writer_flush_block(arg->w);
646 if (arg->err < 0)
647 goto done;
648
649 arg->err = writer_reinit_block_writer(arg->w, REFTABLE_BLOCK_TYPE_OBJ);
650 if (arg->err < 0)
651 goto done;
652
653 /*
654 * If this still fails then we may need to reset record's offset
655 * length to reduce the data size to be written.
656 */
657 arg->err = block_writer_add(arg->w->block_writer, &rec);
658 if (arg->err == 0)
659 goto done;
660
661 if (arg->err != REFTABLE_ENTRY_TOO_BIG_ERROR)
662 goto done;
663
664 rec.u.obj.offset_len = 0;
665 arg->err = block_writer_add(arg->w->block_writer, &rec);
666
667 /* Should be able to write into a fresh block. */
668 assert(arg->err == 0);
669
670done:;
671}

Callers

nothing calls this directly

Calls 3

block_writer_addFunction · 0.85
writer_flush_blockFunction · 0.85

Tested by

no test coverage detected