Commit

301a1ce92adc3128a3705a210c104c21bf862d41

builtin/fsck: use `fsck_obj_buffer()` when checking loose objects

When checking loose objects we manually parse the object buffer we have
read from the on-disk file, mark the object and then call `fsck_obj()`.
The exact same steps are also performed by `fsck_obj_buffer()`.

Stop open-coding this logic and call `fsck_obj_buffer()` instead.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt <ps@pks.im> · 2026-09-11 13:27 UTC · committed by Junio C Hamano

Browse files
1 file changed, +1 −16
modified builtin/fsck.c
@@ -722,7 +722,6 @@ static int fsck_loose(const struct object_id *oid, const char *path,
722 722 void *cb_data)
723 723 {
724 724 struct for_each_loose_cb *data = cb_data;
725 - struct object *obj;
726 725 enum object_type type = OBJ_NONE;
727 726 size_t size;
728 727 void *contents = NULL;
@@ -751,21 +750,7 @@ static int fsck_loose(const struct object_id *oid, const char *path,
751 750 if (!contents && type != OBJ_BLOB)
752 751 BUG("read_loose_object streamed a non-blob");
753 752
754 - obj = parse_object_buffer(data->repo, oid, type, size,
755 - contents, &eaten);
756 -
757 - if (!obj) {
758 - errors_found |= ERROR_OBJECT;
759 - error(_("%s: object could not be parsed: %s"),
760 - oid_to_hex(oid), path);
761 - if (!eaten)
762 - free(contents);
763 - return 0; /* keep checking other objects */
764 - }
765 -
766 - obj->flags &= ~(REACHABLE | SEEN);
767 - obj->flags |= HAS_OBJ;
768 - if (fsck_obj(data->repo, obj, contents, size))
753 + if (fsck_obj_buffer(oid, type, size, contents, &eaten, data->repo))
769 754 errors_found |= ERROR_OBJECT;
770 755
771 756 if (!eaten)