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
23
streaming.c
23
streaming.c
@ -229,17 +229,16 @@ static int open_istream_loose(struct git_istream *st, struct repository *r,
|
||||
st->u.loose.mapped = map_loose_object(r, oid, &st->u.loose.mapsize);
|
||||
if (!st->u.loose.mapped)
|
||||
return -1;
|
||||
if ((unpack_loose_header(&st->z,
|
||||
st->u.loose.mapped,
|
||||
st->u.loose.mapsize,
|
||||
st->u.loose.hdr,
|
||||
sizeof(st->u.loose.hdr),
|
||||
NULL) < 0) ||
|
||||
(parse_loose_header(st->u.loose.hdr, &oi, 0) < 0)) {
|
||||
git_inflate_end(&st->z);
|
||||
munmap(st->u.loose.mapped, st->u.loose.mapsize);
|
||||
return -1;
|
||||
switch (unpack_loose_header(&st->z, st->u.loose.mapped,
|
||||
st->u.loose.mapsize, st->u.loose.hdr,
|
||||
sizeof(st->u.loose.hdr), NULL)) {
|
||||
case ULHR_OK:
|
||||
break;
|
||||
case ULHR_BAD:
|
||||
goto error;
|
||||
}
|
||||
if (parse_loose_header(st->u.loose.hdr, &oi, 0) < 0)
|
||||
goto error;
|
||||
|
||||
st->u.loose.hdr_used = strlen(st->u.loose.hdr) + 1;
|
||||
st->u.loose.hdr_avail = st->z.total_out;
|
||||
@ -248,6 +247,10 @@ static int open_istream_loose(struct git_istream *st, struct repository *r,
|
||||
st->read = read_istream_loose;
|
||||
|
||||
return 0;
|
||||
error:
|
||||
git_inflate_end(&st->z);
|
||||
munmap(st->u.loose.mapped, st->u.loose.mapsize);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user