@matheusbsbs / matheus-bagliano / commits / de530aaa4b
Fork 0

Reorganize/rename unpack_non_delta_entry to unpack_compressed_entry.

This function was moved above unpack_delta_entry so we can call it from within unpack_delta_entry without a forward declaration. This change looks worse than it is. Its really just a relocation of unpack_non_delta_entry to earlier in the file and renaming the function to unpack_compressed_entry. No other changes were made. 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:10 UTC de530aaa4b57b1edd9b973d814d7df8354752ccc
1 file changed +28 -28
sha1_file.c
+28 -28
@@ -1057,6 +1057,33 @@ static int packed_object_info(struct pack_entry *entry,
1057 return 0;
1058 }
1059
1060 +static void *unpack_compressed_entry(unsigned char *data,
1061 + unsigned long size,
1062 + unsigned long left)
1063 +{
1064 + int st;
1065 + z_stream stream;
1066 + unsigned char *buffer;
1067 +
1068 + buffer = xmalloc(size + 1);
1069 + buffer[size] = 0;
1070 + memset(&stream, 0, sizeof(stream));
1071 + stream.next_in = data;
1072 + stream.avail_in = left;
1073 + stream.next_out = buffer;
1074 + stream.avail_out = size;
1075 +
1076 + inflateInit(&stream);
1077 + st = inflate(&stream, Z_FINISH);
1078 + inflateEnd(&stream);
1079 + if ((st != Z_STREAM_END) || stream.total_out != size) {
1080 + free(buffer);
1081 + return NULL;
1082 + }
1083 +
1084 + return buffer;
1085 +}
1086 +
1087 static void *unpack_delta_entry(unsigned char *base_sha1,
1088 unsigned long delta_size,
1089 unsigned long left,
@@ -1110,33 +1137,6 @@ static void *unpack_delta_entry(unsigned char *base_sha1,
1137 return result;
1138 }
1139
1113 -static void *unpack_non_delta_entry(unsigned char *data,
1114 - unsigned long size,
1115 - unsigned long left)
1116 -{
1117 - int st;
1118 - z_stream stream;
1119 - unsigned char *buffer;
1120 -
1121 - buffer = xmalloc(size + 1);
1122 - buffer[size] = 0;
1123 - memset(&stream, 0, sizeof(stream));
1124 - stream.next_in = data;
1125 - stream.avail_in = left;
1126 - stream.next_out = buffer;
1127 - stream.avail_out = size;
1128 -
1129 - inflateInit(&stream);
1130 - st = inflate(&stream, Z_FINISH);
1131 - inflateEnd(&stream);
1132 - if ((st != Z_STREAM_END) || stream.total_out != size) {
1133 - free(buffer);
1134 - return NULL;
1135 - }
1136 -
1137 - return buffer;
1138 -}
1139 -
1140 static void *unpack_entry(struct pack_entry *entry,
1141 char *type, unsigned long *sizep)
1142 {
@@ -1185,7 +1185,7 @@ void *unpack_entry_gently(struct pack_entry *entry,
1185 return NULL;
1186 }
1187 *sizep = size;
1188 - retval = unpack_non_delta_entry(pack, size, left);
1188 + retval = unpack_compressed_entry(pack, size, left);
1189 return retval;
1190 }
1191