Skip to content

Commit ae24b03

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f227fc7 commit ae24b03

File tree

4 files changed

+10
-49
lines changed

4 files changed

+10
-49
lines changed

object-file.c

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,7 @@ enum unpack_loose_header_result unpack_loose_header(git_zstream *stream,
299299
unsigned char *map,
300300
unsigned long mapsize,
301301
void *buffer,
302-
unsigned long bufsiz,
303-
struct strbuf *header)
302+
unsigned long bufsiz)
304303
{
305304
int status;
306305

@@ -325,32 +324,9 @@ enum unpack_loose_header_result unpack_loose_header(git_zstream *stream,
325324
return ULHR_OK;
326325

327326
/*
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.
331328
*/
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;
354330
}
355331

356332
static void *unpack_loose_rest(git_zstream *stream,
@@ -476,10 +452,8 @@ int loose_object_info(struct repository *r,
476452
void *map;
477453
git_zstream stream;
478454
char hdr[MAX_HEADER_LEN];
479-
struct strbuf hdrbuf = STRBUF_INIT;
480455
unsigned long size_scratch;
481456
enum object_type type_scratch;
482-
int allow_unknown = flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
483457

484458
if (oi->delta_base_oid)
485459
oidclr(oi->delta_base_oid, the_repository->hash_algo);
@@ -521,18 +495,15 @@ int loose_object_info(struct repository *r,
521495
if (oi->disk_sizep)
522496
*oi->disk_sizep = mapsize;
523497

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))) {
526499
case ULHR_OK:
527-
if (parse_loose_header(hdrbuf.len ? hdrbuf.buf : hdr, oi) < 0)
500+
if (parse_loose_header(hdr, oi) < 0)
528501
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)
530503
die(_("invalid object type"));
531504

532505
if (!oi->contentp)
533506
break;
534-
if (hdrbuf.len)
535-
BUG("unpacking content with unknown types not yet supported");
536507
*oi->contentp = unpack_loose_rest(&stream, hdr, *oi->sizep, oid);
537508
if (*oi->contentp)
538509
goto cleanup;
@@ -558,7 +529,6 @@ int loose_object_info(struct repository *r,
558529
munmap(map, mapsize);
559530
if (oi->sizep == &size_scratch)
560531
oi->sizep = NULL;
561-
strbuf_release(&hdrbuf);
562532
if (oi->typep == &type_scratch)
563533
oi->typep = NULL;
564534
oi->whence = OI_LOOSE;
@@ -1682,8 +1652,7 @@ int read_loose_object(const char *path,
16821652
goto out;
16831653
}
16841654

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) {
16871656
error(_("unable to unpack header of %s"), path);
16881657
goto out_inflate;
16891658
}

object-file.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,7 @@ int format_object_header(char *str, size_t size, enum object_type type,
133133
* - ULHR_BAD on error
134134
* - ULHR_TOO_LONG if the header was too long
135135
*
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.
142137
*/
143138
enum unpack_loose_header_result {
144139
ULHR_OK,
@@ -149,8 +144,7 @@ enum unpack_loose_header_result unpack_loose_header(git_zstream *stream,
149144
unsigned char *map,
150145
unsigned long mapsize,
151146
void *buffer,
152-
unsigned long bufsiz,
153-
struct strbuf *hdrbuf);
147+
unsigned long bufsiz);
154148

155149
/**
156150
* parse_loose_header() parses the starting "<type> <len>\0" of an

object-store.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,6 @@ struct object_info {
240240

241241
/* Invoke lookup_replace_object() on the given hash */
242242
#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
245243
/* Do not retry packed storage after checking packed and loose storage */
246244
#define OBJECT_INFO_QUICK 8
247245
/*

streaming.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static int open_istream_loose(struct git_istream *st, struct repository *r,
238238
return -1;
239239
switch (unpack_loose_header(&st->z, st->u.loose.mapped,
240240
st->u.loose.mapsize, st->u.loose.hdr,
241-
sizeof(st->u.loose.hdr), NULL)) {
241+
sizeof(st->u.loose.hdr))) {
242242
case ULHR_OK:
243243
break;
244244
case ULHR_BAD:

0 commit comments

Comments
 (0)