Skip to content

Commit 547f719

Browse files
peffgitster
authored andcommitted
unpack_loose_rest(): simplify error handling
Inflating a loose object is considered successful only if we got Z_STREAM_END and there were no more bytes. We check both of those conditions and return success, but then have to check them a second time to decide which error message to produce. I.e., we do something like this: if (!error_1 && !error_2) ...return success... if (error_1) ...handle error1... else if (error_2) ...handle error2... ...common error handling... This repetition was the source of a small bug fixed in an earlier commit (our Z_STREAM_END check was not the same in the two conditionals). Instead we can chain them all into a single if/else cascade, which avoids repeating ourselves: if (error_1) ...handle error1... else if (error_2) ...handle error2.... else ...return success... ...common error handling... Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 84b5c1a commit 547f719

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

object-file.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,15 +1347,15 @@ static void *unpack_loose_rest(git_zstream *stream,
13471347
obj_read_lock();
13481348
}
13491349
}
1350-
if (status == Z_STREAM_END && !stream->avail_in) {
1351-
return buf;
1352-
}
13531350

13541351
if (status != Z_STREAM_END)
13551352
error(_("corrupt loose object '%s'"), oid_to_hex(oid));
13561353
else if (stream->avail_in)
13571354
error(_("garbage at end of loose object '%s'"),
13581355
oid_to_hex(oid));
1356+
else
1357+
return buf;
1358+
13591359
free(buf);
13601360
return NULL;
13611361
}

0 commit comments

Comments
 (0)