add get_size_from_delta()
... which consists of existing code split out of packed_delta_info() for other callers to use it as well. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Nicolas Pitre committed
Apr 16, 2007 at 12:31 UTC
54dab52ae8518da67e271b5b3a1f91af1fd5e314
2 files changed
+40
-34
cache.h
+1
@@ -436,6 +436,7 @@ extern const unsigned char *nth_packed_object_sha1(const struct packed_git *, ui
436
extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *);
437
extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *);
438
extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
439
+extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
440
extern const char *packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *);
441
442
/* Dumb servers support */
sha1_file.c
+39
-34
@@ -1160,6 +1160,43 @@ static void *unpack_sha1_file(void *map, unsigned long mapsize, enum object_type
1160
return unpack_sha1_rest(&stream, hdr, *size, sha1);
1161
}
1162
1163
+unsigned long get_size_from_delta(struct packed_git *p,
1164
+ struct pack_window **w_curs,
1165
+ off_t curpos)
1166
+{
1167
+ const unsigned char *data;
1168
+ unsigned char delta_head[20], *in;
1169
+ z_stream stream;
1170
+ int st;
1171
+
1172
+ memset(&stream, 0, sizeof(stream));
1173
+ stream.next_out = delta_head;
1174
+ stream.avail_out = sizeof(delta_head);
1175
+
1176
+ inflateInit(&stream);
1177
+ do {
1178
+ in = use_pack(p, w_curs, curpos, &stream.avail_in);
1179
+ stream.next_in = in;
1180
+ st = inflate(&stream, Z_FINISH);
1181
+ curpos += stream.next_in - in;
1182
+ } while ((st == Z_OK || st == Z_BUF_ERROR) &&
1183
+ stream.total_out < sizeof(delta_head));
1184
+ inflateEnd(&stream);
1185
+ if ((st != Z_STREAM_END) && stream.total_out != sizeof(delta_head))
1186
+ die("delta data unpack-initial failed");
1187
+
1188
+ /* Examine the initial part of the delta to figure out
1189
+ * the result size.
1190
+ */
1191
+ data = delta_head;
1192
+
1193
+ /* ignore base size */
1194
+ get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
1195
+
1196
+ /* Read the result size */
1197
+ return get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
1198
+}
1199
+
1200
static off_t get_delta_base(struct packed_git *p,
1201
struct pack_window **w_curs,
1202
off_t *curpos,
@@ -1223,40 +1260,8 @@ static int packed_delta_info(struct packed_git *p,
1260
* based on a base with a wrong size. This saves tons of
1261
* inflate() calls.
1262
*/
1226
- if (sizep) {
1227
- const unsigned char *data;
1228
- unsigned char delta_head[20], *in;
1229
- z_stream stream;
1230
- int st;
1231
-
1232
- memset(&stream, 0, sizeof(stream));
1233
- stream.next_out = delta_head;
1234
- stream.avail_out = sizeof(delta_head);
1235
-
1236
- inflateInit(&stream);
1237
- do {
1238
- in = use_pack(p, w_curs, curpos, &stream.avail_in);
1239
- stream.next_in = in;
1240
- st = inflate(&stream, Z_FINISH);
1241
- curpos += stream.next_in - in;
1242
- } while ((st == Z_OK || st == Z_BUF_ERROR)
1243
- && stream.total_out < sizeof(delta_head));
1244
- inflateEnd(&stream);
1245
- if ((st != Z_STREAM_END) &&
1246
- stream.total_out != sizeof(delta_head))
1247
- die("delta data unpack-initial failed");
1248
-
1249
- /* Examine the initial part of the delta to figure out
1250
- * the result size.
1251
- */
1252
- data = delta_head;
1253
-
1254
- /* ignore base size */
1255
- get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
1256
-
1257
- /* Read the result size */
1258
- *sizep = get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
1259
- }
1263
+ if (sizep)
1264
+ *sizep = get_size_from_delta(p, w_curs, curpos);
1265
1266
return type;
1267
}