Skip to content

Commit 3100a1e

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b46ec25 commit 3100a1e

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

object-file.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,28 @@ static int start_loose_object_common(struct strbuf *tmp_file,
20002000
return fd;
20012001
}
20022002

2003+
/**
2004+
* Common steps for the inner git_deflate() loop for writing loose
2005+
* objects. Returns what git_deflate() returns.
2006+
*/
2007+
static int write_loose_object_common(git_hash_ctx *c,
2008+
git_zstream *stream, const int flush,
2009+
unsigned char *in0, const int fd,
2010+
unsigned char *compressed,
2011+
const size_t compressed_len)
2012+
{
2013+
int ret;
2014+
2015+
ret = git_deflate(stream, flush ? Z_FINISH : 0);
2016+
the_hash_algo->update_fn(c, in0, stream->next_in - in0);
2017+
if (write_buffer(fd, compressed, stream->next_out - compressed) < 0)
2018+
die(_("unable to write loose object file"));
2019+
stream->next_out = compressed;
2020+
stream->avail_out = compressed_len;
2021+
2022+
return ret;
2023+
}
2024+
20032025
/**
20042026
* Common steps for loose object writers to end writing loose objects:
20052027
*
@@ -2048,12 +2070,9 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
20482070
stream.avail_in = len;
20492071
do {
20502072
unsigned char *in0 = stream.next_in;
2051-
ret = git_deflate(&stream, Z_FINISH);
2052-
the_hash_algo->update_fn(&c, in0, stream.next_in - in0);
2053-
if (write_buffer(fd, compressed, stream.next_out - compressed) < 0)
2054-
die(_("unable to write loose object file"));
2055-
stream.next_out = compressed;
2056-
stream.avail_out = sizeof(compressed);
2073+
2074+
ret = write_loose_object_common(&c, &stream, 1, in0, fd,
2075+
compressed, sizeof(compressed));
20572076
} while (ret == Z_OK);
20582077

20592078
if (ret != Z_STREAM_END)

0 commit comments

Comments
 (0)