From 55bb5c9147a209eba44c3e9866704ece424c3d31 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 10 Jun 2011 10:55:10 -0700 Subject: zlib: wrap deflate side of the API Wrap deflateInit, deflate, and deflateEnd for everybody, and the sole use of deflateInit2 in remote-curl.c to tell the library to use gzip header and trailer in git_deflate_init_gzip(). There is only one caller that cares about the status from deflateEnd(). Introduce git_deflate_end_gently() to let that sole caller retrieve the status and act on it (i.e. die) for now, but we would probably want to make inflate_end/deflate_end die when they ran out of memory and get rid of the _gently() kind. Signed-off-by: Junio C Hamano --- remote-curl.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'remote-curl.c') diff --git a/remote-curl.c b/remote-curl.c index 775d614303..3c7621aa06 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -475,11 +475,7 @@ static int post_rpc(struct rpc_state *rpc) int ret; memset(&stream, 0, sizeof(stream)); - ret = deflateInit2(&stream, Z_BEST_COMPRESSION, - Z_DEFLATED, (15 + 16), - 8, Z_DEFAULT_STRATEGY); - if (ret != Z_OK) - die("cannot deflate request; zlib init error %d", ret); + git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION); size = deflateBound(&stream, rpc->len); gzip_body = xmalloc(size); @@ -488,11 +484,11 @@ static int post_rpc(struct rpc_state *rpc) stream.next_out = (unsigned char *)gzip_body; stream.avail_out = size; - ret = deflate(&stream, Z_FINISH); + ret = git_deflate(&stream, Z_FINISH); if (ret != Z_STREAM_END) die("cannot deflate request; zlib deflate error %d", ret); - ret = deflateEnd(&stream); + ret = git_deflate_end_gently(&stream); if (ret != Z_OK) die("cannot deflate request; zlib end error %d", ret); -- cgit v1.2.1 From 225a6f1068f71723a910e8565db4e252b3ca21fa Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 10 Jun 2011 11:18:17 -0700 Subject: zlib: wrap deflateBound() too Signed-off-by: Junio C Hamano --- remote-curl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'remote-curl.c') diff --git a/remote-curl.c b/remote-curl.c index 3c7621aa06..13d8ceede3 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -476,7 +476,7 @@ static int post_rpc(struct rpc_state *rpc) memset(&stream, 0, sizeof(stream)); git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION); - size = deflateBound(&stream, rpc->len); + size = git_deflate_bound(&stream, rpc->len); gzip_body = xmalloc(size); stream.next_in = (unsigned char *)rpc->buf; -- cgit v1.2.1 From ef49a7a0126d64359c974b4b3b71d7ad42ee3bca Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 10 Jun 2011 11:52:15 -0700 Subject: zlib: zlib can only process 4GB at a time The size of objects we read from the repository and data we try to put into the repository are represented in "unsigned long", so that on larger architectures we can handle objects that weigh more than 4GB. But the interface defined in zlib.h to communicate with inflate/deflate limits avail_in (how many bytes of input are we calling zlib with) and avail_out (how many bytes of output from zlib are we ready to accept) fields effectively to 4GB by defining their type to be uInt. In many places in our code, we allocate a large buffer (e.g. mmap'ing a large loose object file) and tell zlib its size by assigning the size to avail_in field of the stream, but that will truncate the high octets of the real size. The worst part of this story is that we often pass around z_stream (the state object used by zlib) to keep track of the number of used bytes in input/output buffer by inspecting these two fields, which practically limits our callchain to the same 4GB limit. Wrap z_stream in another structure git_zstream that can express avail_in and avail_out in unsigned long. For now, just die() when the caller gives a size that cannot be given to a single zlib call. In later patches in the series, we would make git_inflate() and git_deflate() internally loop to give callers an illusion that our "improved" version of zlib interface can operate on a buffer larger than 4GB in one go. Signed-off-by: Junio C Hamano --- remote-curl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'remote-curl.c') diff --git a/remote-curl.c b/remote-curl.c index 13d8ceede3..bc48a36ef5 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -471,7 +471,7 @@ static int post_rpc(struct rpc_state *rpc) * the transfer time. */ size_t size; - z_stream stream; + git_zstream stream; int ret; memset(&stream, 0, sizeof(stream)); -- cgit v1.2.1