git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 09/11] Convert http-push.c and http-walker.c

From
MCMarco Costalba <mcostalba@gmail.com>
Date
Feb 2, 2008, 11:35 UTC
Message-ID
<1201952156-6764-9-git-send-email-mcostalba@gmail.com>
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
Previous: Marco CostalbaNext: Marco Costalba
Message 9 of 21 in “Introduce stream compress helpers”
  1. 01/11 Introduce stream compress helpersMarco Costalba, Feb 2, 2008
  2. 02/11 Use new compress helpers in git filesMarco Costalba, Feb 2, 2008
  3. 03/11 Use new compress helpers in fast-importMarco Costalba, Feb 2, 2008
  4. 04/11 Use new compress helpers in http-push.cMarco Costalba, Feb 2, 2008
  5. 05/11 Use new compress helpers in sha1_file.cMarco Costalba, Feb 2, 2008
  6. 06/11 Better error handling in compress_all()Marco Costalba, Feb 2, 2008
  7. 07/11 Introduce stream decompress helpersMarco Costalba, Feb 2, 2008
  8. 08/11 Use new decompress_all() helper in gitMarco Costalba, Feb 2, 2008
  9. 09/11 Convert http-push.c and http-walker.cMarco Costalba, Feb 2, 2008
  10. 10/11 Convert builtin-pack/unpackMarco Costalba, Feb 2, 2008
  11. 11/11 Convert sha1_file.c to use decompress helpersMarco Costalba, Feb 2, 2008
  12. Junio C HamanoFeb 4, 2008
  13. Junio C HamanoFeb 4, 2008
  14. Junio C HamanoFeb 4, 2008
  15. Junio C HamanoFeb 3, 2008
  16. Junio C HamanoFeb 3, 2008
  17. Junio C HamanoFeb 3, 2008
  18. Shawn O. PearceFeb 4, 2008
  19. Shawn O. PearceFeb 4, 2008
  20. Junio C HamanoFeb 3, 2008
  21. Junio C HamanoFeb 3, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.