summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9e7e5ca)
raw | patch | inline | side by side (parent: 9e7e5ca)
author | Junio C Hamano <gitster@pobox.com> | |
Fri, 10 Jun 2011 17:45:29 +0000 (10:45 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 10 Jun 2011 17:51:02 +0000 (10:51 -0700) |
http-backend.c uses inflateInit2() to tell the library that it wants to
accept only gzip format. Wrap it in a helper function so that readers do
not have to wonder what the magic numbers 15 and 16 are for.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
accept only gzip format. Wrap it in a helper function so that readers do
not have to wonder what the magic numbers 15 and 16 are for.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h | patch | blob | history | |
http-backend.c | patch | blob | history | |
zlib.c | patch | blob | history |
index ce73e1f09d7fc4f4196e32c2cfdd16e343ad9653..50f09d05d4596ec62179444c0b8165254ebee5c5 100644 (file)
--- a/cache.h
+++ b/cache.h
#endif
void git_inflate_init(z_streamp strm);
+void git_inflate_init_gzip_only(z_streamp strm);
void git_inflate_end(z_streamp strm);
int git_inflate(z_streamp strm, int flush);
diff --git a/http-backend.c b/http-backend.c
index c74cb03a705f4e61c46c7cdb29f507ff12bab27e..ab5015d9d90cdbc5ac6126090e7b5a1cbf0bd626 100644 (file)
--- a/http-backend.c
+++ b/http-backend.c
unsigned char in_buf[8192];
unsigned char out_buf[8192];
unsigned long cnt = 0;
- int ret;
memset(&stream, 0, sizeof(stream));
- ret = inflateInit2(&stream, (15 + 16));
- if (ret != Z_OK)
- die("cannot start zlib inflater, zlib err %d", ret);
+ git_inflate_init_gzip_only(&stream);
while (1) {
ssize_t n = xread(0, in_buf, sizeof(in_buf));
index be9d7e963b88ac20cf4639de9dd4ddaaf3ff7a80..b613cbd75085384df2ec87fcf2475f7d154f55ff 100644 (file)
--- a/zlib.c
+++ b/zlib.c
strm->msg ? strm->msg : "no message");
}
+void git_inflate_init_gzip_only(z_streamp strm)
+{
+ /*
+ * Use default 15 bits, +16 is to accept only gzip and to
+ * yield Z_DATA_ERROR when fed zlib format.
+ */
+ const int windowBits = 15 + 16;
+ int status = inflateInit2(strm, windowBits);
+
+ if (status == Z_OK)
+ return;
+ die("inflateInit2: %s (%s)", zerr_to_string(status),
+ strm->msg ? strm->msg : "no message");
+}
+
void git_inflate_end(z_streamp strm)
{
int status = inflateEnd(strm);