object-file: drop OBJECT_INFO_ALLOW_UNKNOWN_TYPE flag
Since cat-file dropped its "--allow-unknown-type" option in the previous commit, there are no more uses of the internal flag that implemented it. Let's drop it. That in turn lets us drop the strbuf parameter of unpack_loose_header(), which now is always NULL. And without that, we can drop all of the additional code to inflate larger headers into the strbuf. Arguably we could drop ULHR_TOO_LONG, as no callers really care about the distinction from ULHR_BAD. But it's easy enough to retain, and it does let us produce a slightly more specific message in one instance. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
May 16, 2025 at 00:49 UTC
ae24b032a04ccd1565cb1ce13317b56daa77ce7f
4 files changed
+10
-49
object-file.c
+7
-38
@@ -299,8 +299,7 @@ enum unpack_loose_header_result unpack_loose_header(git_zstream *stream,
299
unsigned char *map,
300
unsigned long mapsize,
301
void *buffer,
302
- unsigned long bufsiz,
303
- struct strbuf *header)
302
+ unsigned long bufsiz)
303
{
304
int status;
305
@@ -325,32 +324,9 @@ enum unpack_loose_header_result unpack_loose_header(git_zstream *stream,
324
return ULHR_OK;
325
326
/*
328
- * We have a header longer than MAX_HEADER_LEN. The "header"
329
- * here is only non-NULL when we run "cat-file
330
- * --allow-unknown-type".
327
+ * We have a header longer than MAX_HEADER_LEN.
328
*/
332
- if (!header)
333
- return ULHR_TOO_LONG;
334
-
335
- /*
336
- * buffer[0..bufsiz] was not large enough. Copy the partial
337
- * result out to header, and then append the result of further
338
- * reading the stream.
339
- */
340
- strbuf_add(header, buffer, stream->next_out - (unsigned char *)buffer);
341
-
342
- do {
343
- stream->next_out = buffer;
344
- stream->avail_out = bufsiz;
345
-
346
- obj_read_unlock();
347
- status = git_inflate(stream, 0);
348
- obj_read_lock();
349
- strbuf_add(header, buffer, stream->next_out - (unsigned char *)buffer);
350
- if (memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer))
351
- return 0;
352
- } while (status == Z_OK);
353
- return ULHR_BAD;
329
+ return ULHR_TOO_LONG;
330
}
331
332
static void *unpack_loose_rest(git_zstream *stream,
@@ -476,10 +452,8 @@ int loose_object_info(struct repository *r,
452
void *map;
453
git_zstream stream;
454
char hdr[MAX_HEADER_LEN];
479
- struct strbuf hdrbuf = STRBUF_INIT;
455
unsigned long size_scratch;
456
enum object_type type_scratch;
482
- int allow_unknown = flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
457
458
if (oi->delta_base_oid)
459
oidclr(oi->delta_base_oid, the_repository->hash_algo);
@@ -521,18 +495,15 @@ int loose_object_info(struct repository *r,
495
if (oi->disk_sizep)
496
*oi->disk_sizep = mapsize;
497
524
- switch (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr),
525
- allow_unknown ? &hdrbuf : NULL)) {
498
+ switch (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr))) {
499
case ULHR_OK:
527
- if (parse_loose_header(hdrbuf.len ? hdrbuf.buf : hdr, oi) < 0)
500
+ if (parse_loose_header(hdr, oi) < 0)
501
status = error(_("unable to parse %s header"), oid_to_hex(oid));
529
- else if (!allow_unknown && *oi->typep < 0)
502
+ else if (*oi->typep < 0)
503
die(_("invalid object type"));
504
505
if (!oi->contentp)
506
break;
534
- if (hdrbuf.len)
535
- BUG("unpacking content with unknown types not yet supported");
507
*oi->contentp = unpack_loose_rest(&stream, hdr, *oi->sizep, oid);
508
if (*oi->contentp)
509
goto cleanup;
@@ -558,7 +529,6 @@ cleanup:
529
munmap(map, mapsize);
530
if (oi->sizep == &size_scratch)
531
oi->sizep = NULL;
561
- strbuf_release(&hdrbuf);
532
if (oi->typep == &type_scratch)
533
oi->typep = NULL;
534
oi->whence = OI_LOOSE;
@@ -1682,8 +1652,7 @@ int read_loose_object(const char *path,
1652
goto out;
1653
}
1654
1685
- if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr),
1686
- NULL) != ULHR_OK) {
1655
+ if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr)) != ULHR_OK) {
1656
error(_("unable to unpack header of %s"), path);
1657
goto out_inflate;
1658
}
object-file.h
+2
-8
@@ -133,12 +133,7 @@ int format_object_header(char *str, size_t size, enum object_type type,
133
* - ULHR_BAD on error
134
* - ULHR_TOO_LONG if the header was too long
135
*
136
- * It will only parse up to MAX_HEADER_LEN bytes unless an optional
137
- * "hdrbuf" argument is non-NULL. This is intended for use with
138
- * OBJECT_INFO_ALLOW_UNKNOWN_TYPE to extract the bad type for (error)
139
- * reporting. The full header will be extracted to "hdrbuf" for use
140
- * with parse_loose_header(), ULHR_TOO_LONG will still be returned
141
- * from this function to indicate that the header was too long.
136
+ * It will only parse up to MAX_HEADER_LEN bytes.
137
*/
138
enum unpack_loose_header_result {
139
ULHR_OK,
@@ -149,8 +144,7 @@ enum unpack_loose_header_result unpack_loose_header(git_zstream *stream,
144
unsigned char *map,
145
unsigned long mapsize,
146
void *buffer,
152
- unsigned long bufsiz,
153
- struct strbuf *hdrbuf);
147
+ unsigned long bufsiz);
148
149
/**
150
* parse_loose_header() parses the starting "<type> <len>\0" of an
object-store.h
-2
@@ -240,8 +240,6 @@ struct object_info {
240
241
/* Invoke lookup_replace_object() on the given hash */
242
#define OBJECT_INFO_LOOKUP_REPLACE 1
243
-/* Allow reading from a loose object file of unknown/bogus type */
244
-#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
243
/* Do not retry packed storage after checking packed and loose storage */
244
#define OBJECT_INFO_QUICK 8
245
/*
streaming.c
+1
-1
@@ -238,7 +238,7 @@ static int open_istream_loose(struct git_istream *st, struct repository *r,
238
return -1;
239
switch (unpack_loose_header(&st->z, st->u.loose.mapped,
240
st->u.loose.mapsize, st->u.loose.hdr,
241
- sizeof(st->u.loose.hdr), NULL)) {
241
+ sizeof(st->u.loose.hdr))) {
242
case ULHR_OK:
243
break;
244
case ULHR_BAD: