{"thread":{"id":"11589","subject":"[PATCH 4/6] Convert http-push.c and http-walker.c","startedAt":"2008-01-11T18:57:32Z","lastAt":"2008-01-11T18:57:32Z","messageCount":1,"participants":["Marco Costalba"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"65047","messageId":"e5bfff550801111057m449a19eaxec2d2f1ee748e687@mail.gmail.com","threadId":"11589","inReplyTo":null,"subject":"[PATCH 4/6] Convert http-push.c and http-walker.c","fromName":"Marco Costalba","fromEmail":"mcostalba@gmail.com","sentAt":"2008-01-11T18:57:32Z","receivedAt":"2008-01-11T18:57:32Z","isPatch":true,"sender":{"key":"mcostalba@gmail.com","avatar":null},"body":"Conversion for both files is very similar\nand in both cases I have added a FIXME where\nI would have added an additional decompress_free()\n\nThe corresponding deflateEnd() call is not present in\nthe original code, so I left the line commented out.\n\nSigned-off-by: Marco Costalba <mcostalba@gmail.com>\n---\n http-push.c   |   21 +++++++++------------\n http-walker.c |   22 +++++++++-------------\n 2 files changed, 18 insertions(+), 25 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex b7fe57f..ec0568c 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -203,12 +203,11 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize,\n \t\tposn += retval;\n \t} while (posn < size);\n\n-\trequest->stream.avail_in = size;\n-\trequest->stream.next_in = ptr;\n+\tdecompress_from(&request->stream, ptr, size);\n+\n \tdo {\n-\t\trequest->stream.next_out = expn;\n-\t\trequest->stream.avail_out = sizeof(expn);\n-\t\trequest->zret = inflate(&request->stream, Z_SYNC_FLUSH);\n+\t\trequest->zret = decompress_next_into(&request->stream, expn,\n+\t\t                                     sizeof(expn), Z_SYNC_FLUSH);\n \t\tSHA1_Update(&request->c, expn,\n \t\t\t    sizeof(expn) - request->stream.avail_out);\n \t} while (request->stream.avail_in && request->zret == Z_OK);\n@@ -266,9 +265,7 @@ static void start_fetch_loose(struct transfer_request\n \t\treturn;\n \t}\n\n-\tmemset(&request->stream, 0, sizeof(request->stream));\n-\n-\tinflateInit(&request->stream);\n+\tdecompress_alloc(&request->stream);\n\n \tSHA1_Init(&request->c);\n\n@@ -305,11 +302,11 @@ static void start_fetch_loose(struct transfer_request\n \t}\n \tunlink(prevfile);\n\n-\t/* Reset inflate/SHA1 if there was an error reading the previous temp\n+\t/* Reset decompress/SHA1 if there was an error reading the previous temp\n \t   file; also rewind to the beginning of the local file. */\n \tif (prev_read == -1) {\n-\t\tmemset(&request->stream, 0, sizeof(request->stream));\n-\t\tinflateInit(&request->stream);\n+\t\t// FIXME should we need decompress_free() here?\n+\t\tdecompress_alloc(&request->stream);\n \t\tSHA1_Init(&request->c);\n \t\tif (prev_posn>0) {\n \t\t\tprev_posn = 0;\n@@ -735,7 +732,7 @@ static void finish_request(struct transfer_request *request)\n \t\t\tif (request->http_code == 416)\n \t\t\t\tfprintf(stderr, \"Warning: requested range invalid; we may already\nhave all the data.\\n\");\n\n-\t\t\tinflateEnd(&request->stream);\n+\t\t\tdecompress_free(&request->stream);\n \t\t\tSHA1_Final(request->real_sha1, &request->c);\n \t\t\tif (request->zret != Z_STREAM_END) {\n \t\t\t\tunlink(request->tmpfile);\ndiff --git a/http-walker.c b/http-walker.c\nindex 2c37868..b1d2a28 100644\n--- a/http-walker.c\n+++ b/http-walker.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"commit.h\"\n+#include \"compress.h\"\n #include \"pack.h\"\n #include \"walker.h\"\n #include \"http.h\"\n@@ -77,12 +78,10 @@ static size_t fwrite_sha1_file(void *ptr, size_t\neltsize, size_t\n \t\tposn += retval;\n \t} while (posn < size);\n\n-\tobj_req->stream.avail_in = size;\n-\tobj_req->stream.next_in = ptr;\n+\tdecompress_from(&obj_req->stream, ptr, size);\n \tdo {\n-\t\tobj_req->stream.next_out = expn;\n-\t\tobj_req->stream.avail_out = sizeof(expn);\n-\t\tobj_req->zret = inflate(&obj_req->stream, Z_SYNC_FLUSH);\n+\t\tobj_req->zret = decompress_next_into(&obj_req->stream, expn,\n+                                             sizeof(expn), Z_SYNC_FLUSH);\n \t\tSHA1_Update(&obj_req->c, expn,\n \t\t\t    sizeof(expn) - obj_req->stream.avail_out);\n \t} while (obj_req->stream.avail_in && obj_req->zret == Z_OK);\n@@ -140,10 +139,7 @@ static void start_object_request(struct walker *walker,\n \t\treturn;\n \t}\n\n-\tmemset(&obj_req->stream, 0, sizeof(obj_req->stream));\n-\n-\tinflateInit(&obj_req->stream);\n-\n+\tdecompress_alloc(&obj_req->stream);\n \tSHA1_Init(&obj_req->c);\n\n \turl = xmalloc(strlen(obj_req->repo->base) + 51);\n@@ -179,11 +175,11 @@ static void start_object_request(struct walker *walker,\n \t}\n \tunlink(prevfile);\n\n-\t/* Reset inflate/SHA1 if there was an error reading the previous temp\n+\t/* Reset decompress/SHA1 if there was an error reading the previous temp\n \t   file; also rewind to the beginning of the local file. */\n \tif (prev_read == -1) {\n-\t\tmemset(&obj_req->stream, 0, sizeof(obj_req->stream));\n-\t\tinflateInit(&obj_req->stream);\n+\t\t// FIXME should we need decompress_free() here?\n+\t\tdecompress_alloc(&obj_req->stream);\n \t\tSHA1_Init(&obj_req->c);\n \t\tif (prev_posn>0) {\n \t\t\tprev_posn = 0;\n@@ -243,7 +239,7 @@ static void finish_object_request(struct object_request\n \t\treturn;\n \t}\n\n-\tinflateEnd(&obj_req->stream);\n+\tdecompress_free(&obj_req->stream);\n \tSHA1_Final(obj_req->real_sha1, &obj_req->c);\n \tif (obj_req->zret != Z_STREAM_END) {\n \t\tunlink(obj_req->tmpfile);\n-- \n1.5.4.rc2.90.gf158-dirty\n"}]}