* Common steps for loose object writers to start writing loose * objects: * * - Create tmpfile for the loose object. * - Setup zlib stream for compression. * - Start to feed header to zlib stream. * * Returns a "fd", which should later be provided to * end_loose_object_common(). */
| 652 | * end_loose_object_common(). |
| 653 | */ |
| 654 | static int start_loose_object_common(struct odb_source_loose *loose, |
| 655 | struct strbuf *tmp_file, |
| 656 | const char *filename, unsigned flags, |
| 657 | git_zstream *stream, |
| 658 | unsigned char *buf, size_t buflen, |
| 659 | struct git_hash_ctx *c, struct git_hash_ctx *compat_c, |
| 660 | char *hdr, int hdrlen) |
| 661 | { |
| 662 | const struct git_hash_algo *algo = loose->base.odb->repo->hash_algo; |
| 663 | const struct git_hash_algo *compat = loose->base.odb->repo->compat_hash_algo; |
| 664 | int fd; |
| 665 | struct repo_config_values *cfg = repo_config_values(the_repository); |
| 666 | |
| 667 | fd = create_tmpfile(loose->base.odb->repo, tmp_file, filename); |
| 668 | if (fd < 0) { |
| 669 | if (flags & ODB_WRITE_OBJECT_SILENT) |
| 670 | return -1; |
| 671 | else if (errno == EACCES) |
| 672 | return error(_("insufficient permission for adding " |
| 673 | "an object to repository database %s"), |
| 674 | loose->base.path); |
| 675 | else |
| 676 | return error_errno( |
| 677 | _("unable to create temporary file")); |
| 678 | } |
| 679 | |
| 680 | /* Setup zlib stream for compression */ |
| 681 | git_deflate_init(stream, cfg->zlib_compression_level); |
| 682 | stream->next_out = buf; |
| 683 | stream->avail_out = buflen; |
| 684 | algo->init_fn(c); |
| 685 | if (compat && compat_c) |
| 686 | compat->init_fn(compat_c); |
| 687 | |
| 688 | /* Start to feed header to zlib stream */ |
| 689 | stream->next_in = (unsigned char *)hdr; |
| 690 | stream->avail_in = hdrlen; |
| 691 | while (git_deflate(stream, 0) == Z_OK) |
| 692 | ; /* nothing */ |
| 693 | git_hash_update(c, hdr, hdrlen); |
| 694 | if (compat && compat_c) |
| 695 | git_hash_update(compat_c, hdr, hdrlen); |
| 696 | |
| 697 | return fd; |
| 698 | } |
| 699 | |
| 700 | /** |
| 701 | * Common steps for the inner git_deflate() loop for writing loose |
no test coverage detected