Skip to content

Commit d48929e

Browse files
committed
Merge branch 'jc/legacy-loose-object' into maint
* jc/legacy-loose-object: sha1_file.c: "legacy" is really the current format
2 parents 3e8cd96 + cc5c54e commit d48929e

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed

sha1_file.c

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,20 +1205,29 @@ static void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
12051205
return map;
12061206
}
12071207

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)
12091216
{
12101217
unsigned int word;
12111218

12121219
/*
12131220
* Is it a zlib-compressed buffer? If so, the first byte
12141221
* 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.
12161225
*/
12171226
word = (map[0] << 8) + map[1];
12181227
if (map[0] == 0x78 && !(word % 31))
1219-
return 1;
1220-
else
12211228
return 0;
1229+
else
1230+
return 1;
12221231
}
12231232

12241233
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
12621271
stream->next_out = buffer;
12631272
stream->avail_out = bufsiz;
12641273

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;
12701284

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);
12831289

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+
}
12871295
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);
12931297
}
12941298

12951299
static void *unpack_sha1_rest(z_stream *stream, void *buffer, unsigned long size, const unsigned char *sha1)

0 commit comments

Comments
 (0)