From: Marco Costalba <mcostalba@gmail.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, Marco Costalba <mcostalba@gmail.com>
Subject: [PATCH 09/11] Convert http-push.c and http-walker.c
Date: Sat, 2 Feb 2008 12:35:54 +0100 [thread overview]
Message-ID: <1201952156-6764-9-git-send-email-mcostalba@gmail.com> (raw)
In-Reply-To: <1201952156-6764-8-git-send-email-mcostalba@gmail.com>
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@gmail.com>
---
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
next prev parent reply other threads:[~2008-02-02 11:38 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-02 11:35 [PATCH 01/11] Introduce stream compress helpers Marco Costalba
2008-02-02 11:35 ` [PATCH 02/11] Use new compress helpers in git files Marco Costalba
2008-02-02 11:35 ` [PATCH 03/11] Use new compress helpers in fast-import Marco Costalba
2008-02-02 11:35 ` [PATCH 04/11] Use new compress helpers in http-push.c Marco Costalba
2008-02-02 11:35 ` [PATCH 05/11] Use new compress helpers in sha1_file.c Marco Costalba
2008-02-02 11:35 ` [PATCH 06/11] Better error handling in compress_all() Marco Costalba
2008-02-02 11:35 ` [PATCH 07/11] Introduce stream decompress helpers Marco Costalba
2008-02-02 11:35 ` [PATCH 08/11] Use new decompress_all() helper in git Marco Costalba
2008-02-02 11:35 ` Marco Costalba [this message]
2008-02-02 11:35 ` [PATCH 10/11] Convert builtin-pack/unpack Marco Costalba
2008-02-02 11:35 ` [PATCH 11/11] Convert sha1_file.c to use decompress helpers Marco Costalba
2008-02-04 2:08 ` [PATCH 10/11] Convert builtin-pack/unpack Junio C Hamano
2008-02-04 2:07 ` [PATCH 08/11] Use new decompress_all() helper in git Junio C Hamano
2008-02-04 2:07 ` [PATCH 07/11] Introduce stream decompress helpers Junio C Hamano
2008-02-03 22:54 ` [PATCH 06/11] Better error handling in compress_all() Junio C Hamano
2008-02-03 22:53 ` [PATCH 04/11] Use new compress helpers in http-push.c Junio C Hamano
2008-02-03 22:53 ` [PATCH 03/11] Use new compress helpers in fast-import Junio C Hamano
2008-02-04 1:48 ` Shawn O. Pearce
2008-02-04 1:41 ` Shawn O. Pearce
2008-02-03 22:54 ` [PATCH 02/11] Use new compress helpers in git files Junio C Hamano
2008-02-03 22:53 ` [PATCH 01/11] Introduce stream compress helpers Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1201952156-6764-9-git-send-email-mcostalba@gmail.com \
--to=mcostalba@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).