fsck: provide a function to fsck buffer without object struct
The fsck code has been slowly moving away from requiring an object struct in commits like 103fb6d43b (fsck: accept an oid instead of a "struct tag" for fsck_tag(), 2019-10-18), c5b4269b57 (fsck: accept an oid instead of a "struct commit" for fsck_commit(), 2019-10-18), etc. However, the only external interface that fsck.c provides is fsck_object(), which requires an object struct, then promptly discards everything except its oid and type. Let's factor out the post-discard part of that function as fsck_buffer(), leaving fsck_object() as a thin wrapper around it. That will provide more flexibility for callers which may not have a struct. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jan 18, 2023 at 15:43 UTC
35ff327e2da2e9fa9820643d2e44f3b30530d06c
2 files changed
+26
-11
fsck.c
+18
-11
@@ -1237,19 +1237,26 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
1237
if (!obj)
1238
return report(options, NULL, OBJ_NONE, FSCK_MSG_BAD_OBJECT_SHA1, "no valid object to fsck");
1239
1240
- if (obj->type == OBJ_BLOB)
1241
- return fsck_blob(&obj->oid, data, size, options);
1242
- if (obj->type == OBJ_TREE)
1243
- return fsck_tree(&obj->oid, data, size, options);
1244
- if (obj->type == OBJ_COMMIT)
1245
- return fsck_commit(&obj->oid, data, size, options);
1246
- if (obj->type == OBJ_TAG)
1247
- return fsck_tag(&obj->oid, data, size, options);
1248
-
1249
- return report(options, &obj->oid, obj->type,
1240
+ return fsck_buffer(&obj->oid, obj->type, data, size, options);
1241
+}
1242
+
1243
+int fsck_buffer(const struct object_id *oid, enum object_type type,
1244
+ void *data, unsigned long size,
1245
+ struct fsck_options *options)
1246
+{
1247
+ if (type == OBJ_BLOB)
1248
+ return fsck_blob(oid, data, size, options);
1249
+ if (type == OBJ_TREE)
1250
+ return fsck_tree(oid, data, size, options);
1251
+ if (type == OBJ_COMMIT)
1252
+ return fsck_commit(oid, data, size, options);
1253
+ if (type == OBJ_TAG)
1254
+ return fsck_tag(oid, data, size, options);
1255
+
1256
+ return report(options, oid, type,
1257
FSCK_MSG_UNKNOWN_TYPE,
1258
"unknown type '%d' (internal fsck error)",
1252
- obj->type);
1259
+ type);
1260
}
1261
1262
int fsck_error_function(struct fsck_options *o,
fsck.h
+8
@@ -183,6 +183,14 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
183
int fsck_object(struct object *obj, void *data, unsigned long size,
184
struct fsck_options *options);
185
186
+/*
187
+ * Same as fsck_object(), but for when the caller doesn't have an object
188
+ * struct.
189
+ */
190
+int fsck_buffer(const struct object_id *oid, enum object_type,
191
+ void *data, unsigned long size,
192
+ struct fsck_options *options);
193
+
194
/*
195
* fsck a tag, and pass info about it back to the caller. This is
196
* exposed fsck_object() internals for git-mktag(1).