Conversion for both files is very similar and in both cases I have added a FIXME where I would have added an additional decompress_free() The corresponding deflateEnd() call is not present in the original code, so I left the line commented out. Signed-off-by: Marco Costalba <mcostalba@xxxxxxxxx> --- http-push.c | 21 +++++++++------------ http-walker.c | 22 +++++++++------------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/http-push.c b/http-push.c index a7997ec..0920640 100644 --- a/http-push.c +++ b/http-push.c @@ -203,12 +203,11 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb, posn += retval; } while (posn < size); - request->stream.avail_in = size; - request->stream.next_in = ptr; + decompress_from(&request->stream, ptr, size); + do { - request->stream.next_out = expn; - request->stream.avail_out = sizeof(expn); - request->zret = inflate(&request->stream, Z_SYNC_FLUSH); + request->zret = decompress_next_into(&request->stream, expn, + sizeof(expn), Z_SYNC_FLUSH); SHA1_Update(&request->c, expn, sizeof(expn) - request->stream.avail_out); } while (request->stream.avail_in && request->zret == Z_OK); @@ -266,9 +265,7 @@ static void start_fetch_loose(struct transfer_request *request) return; } - memset(&request->stream, 0, sizeof(request->stream)); - - inflateInit(&request->stream); + decompress_alloc(&request->stream); SHA1_Init(&request->c); @@ -305,11 +302,11 @@ static void start_fetch_loose(struct transfer_request *request) } unlink(prevfile); - /* Reset inflate/SHA1 if there was an error reading the previous temp + /* Reset decompress/SHA1 if there was an error reading the previous temp file; also rewind to the beginning of the local file. */ if (prev_read == -1) { - memset(&request->stream, 0, sizeof(request->stream)); - inflateInit(&request->stream); + // FIXME should we need decompress_free() here? + decompress_alloc(&request->stream); SHA1_Init(&request->c); if (prev_posn>0) { prev_posn = 0; @@ -735,7 +732,7 @@ static void finish_request(struct transfer_request *request) if (request->http_code == 416) fprintf(stderr, "Warning: requested range invalid; we may already have all the data.\n"); - inflateEnd(&request->stream); + decompress_free(&request->stream); SHA1_Final(request->real_sha1, &request->c); if (request->zret != Z_STREAM_END) { unlink(request->tmpfile); diff --git a/http-walker.c b/http-walker.c index 2c37868..b1d2a28 100644 --- a/http-walker.c +++ b/http-walker.c @@ -1,5 +1,6 @@ #include "cache.h" #include "commit.h" +#include "compress.h" #include "pack.h" #include "walker.h" #include "http.h" @@ -77,12 +78,10 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb, posn += retval; } while (posn < size); - obj_req->stream.avail_in = size; - obj_req->stream.next_in = ptr; + decompress_from(&obj_req->stream, ptr, size); do { - obj_req->stream.next_out = expn; - obj_req->stream.avail_out = sizeof(expn); - obj_req->zret = inflate(&obj_req->stream, Z_SYNC_FLUSH); + obj_req->zret = decompress_next_into(&obj_req->stream, expn, + sizeof(expn), Z_SYNC_FLUSH); SHA1_Update(&obj_req->c, expn, sizeof(expn) - obj_req->stream.avail_out); } while (obj_req->stream.avail_in && obj_req->zret == Z_OK); @@ -140,10 +139,7 @@ static void start_object_request(struct walker *walker, return; } - memset(&obj_req->stream, 0, sizeof(obj_req->stream)); - - inflateInit(&obj_req->stream); - + decompress_alloc(&obj_req->stream); SHA1_Init(&obj_req->c); url = xmalloc(strlen(obj_req->repo->base) + 51); @@ -179,11 +175,11 @@ static void start_object_request(struct walker *walker, } unlink(prevfile); - /* Reset inflate/SHA1 if there was an error reading the previous temp + /* Reset decompress/SHA1 if there was an error reading the previous temp file; also rewind to the beginning of the local file. */ if (prev_read == -1) { - memset(&obj_req->stream, 0, sizeof(obj_req->stream)); - inflateInit(&obj_req->stream); + // FIXME should we need decompress_free() here? + decompress_alloc(&obj_req->stream); SHA1_Init(&obj_req->c); if (prev_posn>0) { prev_posn = 0; @@ -243,7 +239,7 @@ static void finish_object_request(struct object_request *obj_req) return; } - inflateEnd(&obj_req->stream); + decompress_free(&obj_req->stream); SHA1_Final(obj_req->real_sha1, &obj_req->c); if (obj_req->zret != Z_STREAM_END) { unlink(obj_req->tmpfile); -- 1.5.4.rc4.39.g524a - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html