MCPcopy Index your code
hub / github.com/git/git / odb_source_loose_write_stream

Function odb_source_loose_write_stream

object-file.c:810–927  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

808}
809
810int odb_source_loose_write_stream(struct odb_source_loose *loose,
811 struct odb_write_stream *in_stream, size_t len,
812 struct object_id *oid)
813{
814 const struct git_hash_algo *compat = loose->base.odb->repo->compat_hash_algo;
815 struct object_id compat_oid;
816 int fd, ret, err = 0, flush = 0;
817 unsigned char compressed[4096];
818 git_zstream stream;
819 struct git_hash_ctx c, compat_c;
820 struct strbuf tmp_file = STRBUF_INIT;
821 struct strbuf filename = STRBUF_INIT;
822 unsigned char buf[8192];
823 int dirlen;
824 char hdr[MAX_HEADER_LEN];
825 int hdrlen;
826
827 if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
828 prepare_loose_object_transaction(loose->base.odb->transaction);
829
830 /* Since oid is not determined, save tmp file to odb path. */
831 strbuf_addf(&filename, "%s/", loose->base.path);
832 hdrlen = format_object_header(hdr, sizeof(hdr), OBJ_BLOB, len);
833
834 /*
835 * Common steps for write_loose_object and stream_loose_object to
836 * start writing loose objects:
837 *
838 * - Create tmpfile for the loose object.
839 * - Setup zlib stream for compression.
840 * - Start to feed header to zlib stream.
841 */
842 fd = start_loose_object_common(loose, &tmp_file, filename.buf, 0,
843 &stream, compressed, sizeof(compressed),
844 &c, &compat_c, hdr, hdrlen);
845 if (fd < 0) {
846 err = -1;
847 goto cleanup;
848 }
849
850 /* Then the data itself.. */
851 do {
852 unsigned char *in0 = stream.next_in;
853
854 if (!stream.avail_in && !in_stream->is_finished) {
855 ssize_t read_len = odb_write_stream_read(in_stream, buf,
856 sizeof(buf));
857 if (read_len < 0) {
858 close(fd);
859 err = -1;
860 goto cleanup;
861 }
862
863 stream.avail_in = read_len;
864 stream.next_in = buf;
865 in0 = buf;
866 /* All data has been read. */
867 if (in_stream->is_finished)

Callers 1

Calls 15

batch_fsync_enabledFunction · 0.85
strbuf_addfFunction · 0.85
format_object_headerFunction · 0.85
odb_write_stream_readFunction · 0.85
end_loose_object_commonFunction · 0.85
close_loose_objectFunction · 0.85
odb_freshen_objectFunction · 0.85
unlink_or_warnFunction · 0.85
odb_loose_pathFunction · 0.85

Tested by

no test coverage detected