git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/5] Reuse compression code in unpack_compressed_entry.
@ 2006-08-26  8:11 Shawn Pearce
  0 siblings, 0 replies; only message in thread
From: Shawn Pearce @ 2006-08-26  8:11 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

[PATCH 2/5] Reuse compression code in unpack_compressed_entry.

This cleans up the code by reusing a perfectly good decompression
implementation at the expense of 1 extra byte of memory allocated in
temporary memory while the delta is being decompressed and applied
to the base.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 sha1_file.c |   25 ++++---------------------
 1 files changed, 4 insertions(+), 21 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 024b605..fd3e01b 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1092,10 +1092,8 @@ static void *unpack_delta_entry(unsigned
 				struct packed_git *p)
 {
 	struct pack_entry base_ent;
-	void *data, *delta_data, *result, *base;
-	unsigned long data_size, result_size, base_size;
-	z_stream stream;
-	int st;
+	void *delta_data, *result, *base;
+	unsigned long result_size, base_size;
 
 	if (left < 20)
 		die("truncated pack file");
@@ -1109,23 +1107,8 @@ static void *unpack_delta_entry(unsigned
 		die("failed to read delta-pack base object %s",
 		    sha1_to_hex(base_sha1));
 
-	data = base_sha1 + 20;
-	data_size = left - 20;
-	delta_data = xmalloc(delta_size);
-
-	memset(&stream, 0, sizeof(stream));
-
-	stream.next_in = data;
-	stream.avail_in = data_size;
-	stream.next_out = delta_data;
-	stream.avail_out = delta_size;
-
-	inflateInit(&stream);
-	st = inflate(&stream, Z_FINISH);
-	inflateEnd(&stream);
-	if ((st != Z_STREAM_END) || stream.total_out != delta_size)
-		die("delta data unpack failed");
-
+	delta_data = unpack_compressed_entry(base_sha1 + 20,
+			     delta_size, left - 20);
 	result = patch_delta(base, base_size,
 			     delta_data, delta_size,
 			     &result_size);
-- 
1.4.2.g6580

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2006-08-26  8:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-26  8:11 [PATCH 2/5] Reuse compression code in unpack_compressed_entry Shawn Pearce

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).