@matheusbsbs / matheus-bagliano / commits / 7c3e8be307
Fork 0

Reuse compression code in unpack_compressed_entry.

[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> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn Pearce committed Aug 26, 2006 at 04:11 UTC 7c3e8be30718f9866f330044fe2a0a7c5b2c3461
1 file changed +4 -21
sha1_file.c
+4 -21
@@ -1092,10 +1092,8 @@ static void *unpack_delta_entry(unsigned char *base_sha1,
1092 struct packed_git *p)
1093 {
1094 struct pack_entry base_ent;
1095 - void *data, *delta_data, *result, *base;
1096 - unsigned long data_size, result_size, base_size;
1097 - z_stream stream;
1098 - int st;
1095 + void *delta_data, *result, *base;
1096 + unsigned long result_size, base_size;
1097
1098 if (left < 20)
1099 die("truncated pack file");
@@ -1109,23 +1107,8 @@ static void *unpack_delta_entry(unsigned char *base_sha1,
1107 die("failed to read delta-pack base object %s",
1108 sha1_to_hex(base_sha1));
1109
1112 - data = base_sha1 + 20;
1113 - data_size = left - 20;
1114 - delta_data = xmalloc(delta_size);
1115 -
1116 - memset(&stream, 0, sizeof(stream));
1117 -
1118 - stream.next_in = data;
1119 - stream.avail_in = data_size;
1120 - stream.next_out = delta_data;
1121 - stream.avail_out = delta_size;
1122 -
1123 - inflateInit(&stream);
1124 - st = inflate(&stream, Z_FINISH);
1125 - inflateEnd(&stream);
1126 - if ((st != Z_STREAM_END) || stream.total_out != delta_size)
1127 - die("delta data unpack failed");
1128 -
1110 + delta_data = unpack_compressed_entry(base_sha1 + 20,
1111 + delta_size, left - 20);
1112 result = patch_delta(base, base_size,
1113 delta_data, delta_size,
1114 &result_size);