object-file.c: use "enum" return type for unpack_loose_header()
In a preceding commit we changed and documented unpack_loose_header() from its previous behavior of returning any negative value or zero, to only -1 or 0. Let's add an "enum unpack_loose_header_result" type and use it for these return values, and have the compiler assert that we're exhaustively covering all of them. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
01cab97679
commit
3b6a8db3b0
@ -1210,10 +1210,12 @@ void *map_loose_object(struct repository *r,
|
||||
return map_loose_object_1(r, NULL, oid, size);
|
||||
}
|
||||
|
||||
int unpack_loose_header(git_zstream *stream,
|
||||
unsigned char *map, unsigned long mapsize,
|
||||
void *buffer, unsigned long bufsiz,
|
||||
struct strbuf *header)
|
||||
enum unpack_loose_header_result unpack_loose_header(git_zstream *stream,
|
||||
unsigned char *map,
|
||||
unsigned long mapsize,
|
||||
void *buffer,
|
||||
unsigned long bufsiz,
|
||||
struct strbuf *header)
|
||||
{
|
||||
int status;
|
||||
|
||||
@ -1229,13 +1231,13 @@ int unpack_loose_header(git_zstream *stream,
|
||||
status = git_inflate(stream, 0);
|
||||
obj_read_lock();
|
||||
if (status < Z_OK)
|
||||
return -1;
|
||||
return ULHR_BAD;
|
||||
|
||||
/*
|
||||
* Check if entire header is unpacked in the first iteration.
|
||||
*/
|
||||
if (memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer))
|
||||
return 0;
|
||||
return ULHR_OK;
|
||||
|
||||
/*
|
||||
* We have a header longer than MAX_HEADER_LEN. The "header"
|
||||
@ -1243,7 +1245,7 @@ int unpack_loose_header(git_zstream *stream,
|
||||
* --allow-unknown-type".
|
||||
*/
|
||||
if (!header)
|
||||
return -1;
|
||||
return ULHR_BAD;
|
||||
|
||||
/*
|
||||
* buffer[0..bufsiz] was not large enough. Copy the partial
|
||||
@ -1264,7 +1266,7 @@ int unpack_loose_header(git_zstream *stream,
|
||||
stream->next_out = buffer;
|
||||
stream->avail_out = bufsiz;
|
||||
} while (status != Z_STREAM_END);
|
||||
return -1;
|
||||
return ULHR_BAD;
|
||||
}
|
||||
|
||||
static void *unpack_loose_rest(git_zstream *stream,
|
||||
@ -1429,13 +1431,19 @@ static int loose_object_info(struct repository *r,
|
||||
if (oi->disk_sizep)
|
||||
*oi->disk_sizep = mapsize;
|
||||
|
||||
if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr),
|
||||
allow_unknown ? &hdrbuf : NULL) < 0)
|
||||
switch (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr),
|
||||
allow_unknown ? &hdrbuf : NULL)) {
|
||||
case ULHR_OK:
|
||||
break;
|
||||
case ULHR_BAD:
|
||||
status = error(_("unable to unpack %s header"),
|
||||
oid_to_hex(oid));
|
||||
if (status < 0)
|
||||
; /* Do nothing */
|
||||
else if (hdrbuf.len) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (status < 0) {
|
||||
/* Do nothing */
|
||||
} else if (hdrbuf.len) {
|
||||
if ((status = parse_loose_header(hdrbuf.buf, oi, flags)) < 0)
|
||||
status = error(_("unable to parse %s header with --allow-unknown-type"),
|
||||
oid_to_hex(oid));
|
||||
|
Reference in New Issue
Block a user