summaryrefslogtreecommitdiff
path: root/object-file.c
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-06-11 02:44:18 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-06-13 17:22:35 (GMT)
commit21e7d8814063d8c5ada74464e30bf0c5188f1f80 (patch)
tree0f88f351bdacb75e17c715ce35d619248f5d1bad /object-file.c
parent97a9db6ffb13a49dfe0565b65275b935f4e4d620 (diff)
downloadgit-21e7d8814063d8c5ada74464e30bf0c5188f1f80.zip
git-21e7d8814063d8c5ada74464e30bf0c5188f1f80.tar.gz
git-21e7d8814063d8c5ada74464e30bf0c5188f1f80.tar.bz2
object-file.c: factor out deflate part of write_loose_object()
Split out the part of write_loose_object() that deals with calling git_deflate() into a utility function, a subsequent commit will introduce another function that'll make use of it. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object-file.c')
-rw-r--r--object-file.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/object-file.c b/object-file.c
index b5bce03..18dbf2a 100644
--- a/object-file.c
+++ b/object-file.c
@@ -2001,6 +2001,28 @@ static int start_loose_object_common(struct strbuf *tmp_file,
}
/**
+ * Common steps for the inner git_deflate() loop for writing loose
+ * objects. Returns what git_deflate() returns.
+ */
+static int write_loose_object_common(git_hash_ctx *c,
+ git_zstream *stream, const int flush,
+ unsigned char *in0, const int fd,
+ unsigned char *compressed,
+ const size_t compressed_len)
+{
+ int ret;
+
+ ret = git_deflate(stream, flush ? Z_FINISH : 0);
+ the_hash_algo->update_fn(c, in0, stream->next_in - in0);
+ if (write_buffer(fd, compressed, stream->next_out - compressed) < 0)
+ die(_("unable to write loose object file"));
+ stream->next_out = compressed;
+ stream->avail_out = compressed_len;
+
+ return ret;
+}
+
+/**
* Common steps for loose object writers to end writing loose objects:
*
* - End the compression of zlib stream.
@@ -2047,12 +2069,9 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
stream.avail_in = len;
do {
unsigned char *in0 = stream.next_in;
- ret = git_deflate(&stream, Z_FINISH);
- the_hash_algo->update_fn(&c, in0, stream.next_in - in0);
- if (write_buffer(fd, compressed, stream.next_out - compressed) < 0)
- die(_("unable to write loose object file"));
- stream.next_out = compressed;
- stream.avail_out = sizeof(compressed);
+
+ ret = write_loose_object_common(&c, &stream, 1, in0, fd,
+ compressed, sizeof(compressed));
} while (ret == Z_OK);
if (ret != Z_STREAM_END)