object API users + docs: check <0, not !0 with check_object_signature()
Change those users of the object API that misused check_object_signature() by assuming it returned any non-zero when the OID didn't match the expected value to check <0 instead. In practice all of this code worked before, but it wasn't consistent with rest of the users of the API. Let's also clarify what the <0 return value means in API docs. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Feb 5, 2022 at 00:48 UTC
ee213de22d15e801ba3712be0cb8ecbf7415fa1d
5 files changed
+8
-6
builtin/index-pack.c
+2
-3
@@ -1412,9 +1412,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
1412
if (!data)
1413
continue;
1414
1415
- if (check_object_signature(the_repository, &d->oid,
1416
- data, size,
1417
- type_name(type), NULL))
1415
+ if (check_object_signature(the_repository, &d->oid, data, size,
1416
+ type_name(type), NULL) < 0)
1417
die(_("local object %s is corrupt"), oid_to_hex(&d->oid));
1418
1419
/*
builtin/mktag.c
+1
-1
@@ -97,7 +97,7 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
97
&tagged_oid, &tagged_type))
98
die(_("tag on stdin did not pass our strict fsck check"));
99
100
- if (verify_object_in_tag(&tagged_oid, &tagged_type))
100
+ if (verify_object_in_tag(&tagged_oid, &tagged_type) < 0)
101
die(_("tag on stdin did not refer to a valid object"));
102
103
if (write_object_file(buf.buf, buf.len, OBJ_TAG, &result) < 0)
cache.h
+3
@@ -1324,6 +1324,9 @@ int parse_loose_header(const char *hdr, struct object_info *oi);
1324
* object name actually matches "oid" to detect object corruption.
1325
* With "buf" == NULL, try reading the object named with "oid" using
1326
* the streaming interface and rehash it to do the same.
1327
+ *
1328
+ * A negative value indicates an error, usually that the OID is not
1329
+ * what we expected, but it might also indicate another error.
1330
*/
1331
int check_object_signature(struct repository *r, const struct object_id *oid,
1332
void *buf, unsigned long size, const char *type,
object-file.c
+1
-1
@@ -2613,7 +2613,7 @@ int read_loose_object(const char *path,
2613
}
2614
if (check_object_signature(the_repository, expected_oid,
2615
*contents, *size,
2616
- oi->type_name->buf, real_oid))
2616
+ oi->type_name->buf, real_oid) < 0)
2617
goto out;
2618
}
2619
pack-check.c
+1
-1
@@ -143,7 +143,7 @@ static int verify_packfile(struct repository *r,
143
oid_to_hex(&oid), p->pack_name,
144
(uintmax_t)entries[i].offset);
145
else if (check_object_signature(r, &oid, data, size,
146
- type_name(type), NULL))
146
+ type_name(type), NULL) < 0)
147
err = error("packed %s from %s is corrupt",
148
oid_to_hex(&oid), p->pack_name);
149
else if (fn) {