Convert the verify_pack callback to struct object_id
Make the verify_pack_callback take a pointer to struct object_id. Change the pack checksum to use GIT_MAX_RAWSZ, even though it is not strictly an object ID. Doing so ensures resilience against future hash size changes, and allows us to remove hard-coded assumptions about how big the buffer needs to be. Also, use a union to convert the pointer from nth_packed_object_sha1 to to a pointer to struct object_id. This behavior is compatible with GCC and clang and explicitly sanctioned by C11. The alternatives are to just perform a cast, which would run afoul of strict aliasing rules, but should just work, and changing the pointer into an instance of struct object_id and copying the value. The latter operation could seriously bloat memory usage on fsck, which already uses a lot of memory on some repositories. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
d3101b533d
commit
9fd750461b
@ -377,7 +377,7 @@ static int fsck_obj(struct object *obj)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,
|
||||
static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
|
||||
unsigned long size, void *buffer, int *eaten)
|
||||
{
|
||||
/*
|
||||
@ -385,10 +385,10 @@ static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,
|
||||
* verify_packfile(), data_valid variable for details.
|
||||
*/
|
||||
struct object *obj;
|
||||
obj = parse_object_buffer(sha1, type, size, buffer, eaten);
|
||||
obj = parse_object_buffer(oid->hash, type, size, buffer, eaten);
|
||||
if (!obj) {
|
||||
errors_found |= ERROR_OBJECT;
|
||||
return error("%s: object corrupt or missing", sha1_to_hex(sha1));
|
||||
return error("%s: object corrupt or missing", oid_to_hex(oid));
|
||||
}
|
||||
obj->flags = HAS_OBJ;
|
||||
return fsck_obj(obj);
|
||||
|
Reference in New Issue
Block a user