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

Function write_loose_object

object-file.c:750–808  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

748}
749
750int write_loose_object(struct odb_source_loose *loose,
751 const struct object_id *oid, char *hdr,
752 int hdrlen, const void *buf, unsigned long len,
753 time_t mtime, unsigned flags)
754{
755 int fd, ret;
756 unsigned char compressed[4096];
757 git_zstream stream;
758 struct git_hash_ctx c;
759 struct object_id parano_oid;
760 static struct strbuf tmp_file = STRBUF_INIT;
761 static struct strbuf filename = STRBUF_INIT;
762
763 if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
764 prepare_loose_object_transaction(loose->base.odb->transaction);
765
766 odb_loose_path(loose, &filename, oid);
767
768 fd = start_loose_object_common(loose, &tmp_file, filename.buf, flags,
769 &stream, compressed, sizeof(compressed),
770 &c, NULL, hdr, hdrlen);
771 if (fd < 0)
772 return -1;
773
774 /* Then the data itself.. */
775 stream.next_in = (void *)buf;
776 stream.avail_in = len;
777 do {
778 unsigned char *in0 = stream.next_in;
779
780 ret = write_loose_object_common(loose, &c, NULL, &stream, 1, in0, fd,
781 compressed, sizeof(compressed));
782 } while (ret == Z_OK);
783
784 if (ret != Z_STREAM_END)
785 die(_("unable to deflate new object %s (%d)"), oid_to_hex(oid),
786 ret);
787 ret = end_loose_object_common(loose, &c, NULL, &stream, &parano_oid, NULL);
788 if (ret != Z_OK)
789 die(_("deflateEnd on object %s failed (%d)"), oid_to_hex(oid),
790 ret);
791 if (!oideq(oid, &parano_oid))
792 die(_("confused by unstable object source data for %s"),
793 oid_to_hex(oid));
794
795 close_loose_object(loose, fd, tmp_file.buf);
796
797 if (mtime) {
798 struct utimbuf utb;
799 utb.actime = mtime;
800 utb.modtime = mtime;
801 if (utime(tmp_file.buf, &utb) < 0 &&
802 !(flags & ODB_WRITE_OBJECT_SILENT))
803 warning_errno(_("failed utime() on %s"), tmp_file.buf);
804 }
805
806 return finalize_object_file_flags(loose->base.odb->repo, tmp_file.buf, filename.buf,
807 FOF_SKIP_COLLISION_CHECK);

Callers 2

force_object_looseFunction · 0.85

Calls 12

batch_fsync_enabledFunction · 0.85
odb_loose_pathFunction · 0.85
oid_to_hexFunction · 0.85
end_loose_object_commonFunction · 0.85
oideqFunction · 0.85
close_loose_objectFunction · 0.85
warning_errnoFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected