@@ -1205,20 +1205,29 @@ static void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
1205
1205
return map ;
1206
1206
}
1207
1207
1208
- static int legacy_loose_object (unsigned char * map )
1208
+ /*
1209
+ * There used to be a second loose object header format which
1210
+ * was meant to mimic the in-pack format, allowing for direct
1211
+ * copy of the object data. This format turned up not to be
1212
+ * really worth it and we no longer write loose objects in that
1213
+ * format.
1214
+ */
1215
+ static int experimental_loose_object (unsigned char * map )
1209
1216
{
1210
1217
unsigned int word ;
1211
1218
1212
1219
/*
1213
1220
* Is it a zlib-compressed buffer? If so, the first byte
1214
1221
* must be 0x78 (15-bit window size, deflated), and the
1215
- * first 16-bit word is evenly divisible by 31
1222
+ * first 16-bit word is evenly divisible by 31. If so,
1223
+ * we are looking at the official format, not the experimental
1224
+ * one.
1216
1225
*/
1217
1226
word = (map [0 ] << 8 ) + map [1 ];
1218
1227
if (map [0 ] == 0x78 && !(word % 31 ))
1219
- return 1 ;
1220
- else
1221
1228
return 0 ;
1229
+ else
1230
+ return 1 ;
1222
1231
}
1223
1232
1224
1233
unsigned long unpack_object_header_buffer (const unsigned char * buf ,
@@ -1262,34 +1271,29 @@ static int unpack_sha1_header(z_stream *stream, unsigned char *map, unsigned lon
1262
1271
stream -> next_out = buffer ;
1263
1272
stream -> avail_out = bufsiz ;
1264
1273
1265
- if (legacy_loose_object (map )) {
1266
- git_inflate_init (stream );
1267
- return git_inflate (stream , 0 );
1268
- }
1269
-
1274
+ if (experimental_loose_object (map )) {
1275
+ /*
1276
+ * The old experimental format we no longer produce;
1277
+ * we can still read it.
1278
+ */
1279
+ used = unpack_object_header_buffer (map , mapsize , & type , & size );
1280
+ if (!used || !valid_loose_object_type [type ])
1281
+ return -1 ;
1282
+ map += used ;
1283
+ mapsize -= used ;
1270
1284
1271
- /*
1272
- * There used to be a second loose object header format which
1273
- * was meant to mimic the in-pack format, allowing for direct
1274
- * copy of the object data. This format turned up not to be
1275
- * really worth it and we don't write it any longer. But we
1276
- * can still read it.
1277
- */
1278
- used = unpack_object_header_buffer (map , mapsize , & type , & size );
1279
- if (!used || !valid_loose_object_type [type ])
1280
- return -1 ;
1281
- map += used ;
1282
- mapsize -= used ;
1285
+ /* Set up the stream for the rest.. */
1286
+ stream -> next_in = map ;
1287
+ stream -> avail_in = mapsize ;
1288
+ git_inflate_init (stream );
1283
1289
1284
- /* Set up the stream for the rest.. */
1285
- stream -> next_in = map ;
1286
- stream -> avail_in = mapsize ;
1290
+ /* And generate the fake traditional header */
1291
+ stream -> total_out = 1 + snprintf (buffer , bufsiz , "%s %lu" ,
1292
+ typename (type ), size );
1293
+ return 0 ;
1294
+ }
1287
1295
git_inflate_init (stream );
1288
-
1289
- /* And generate the fake traditional header */
1290
- stream -> total_out = 1 + snprintf (buffer , bufsiz , "%s %lu" ,
1291
- typename (type ), size );
1292
- return 0 ;
1296
+ return git_inflate (stream , 0 );
1293
1297
}
1294
1298
1295
1299
static void * unpack_sha1_rest (z_stream * stream , void * buffer , unsigned long size , const unsigned char * sha1 )
0 commit comments