Skip to content

Commit 35ff327

Browse files
peffgitster
authored andcommitted
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 103fb6d (fsck: accept an oid instead of a "struct tag" for fsck_tag(), 2019-10-18), c5b4269 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 34959d8 commit 35ff327

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

fsck.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,19 +1237,26 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
12371237
if (!obj)
12381238
return report(options, NULL, OBJ_NONE, FSCK_MSG_BAD_OBJECT_SHA1, "no valid object to fsck");
12391239

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,
12501257
FSCK_MSG_UNKNOWN_TYPE,
12511258
"unknown type '%d' (internal fsck error)",
1252-
obj->type);
1259+
type);
12531260
}
12541261

12551262
int fsck_error_function(struct fsck_options *o,

fsck.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
183183
int fsck_object(struct object *obj, void *data, unsigned long size,
184184
struct fsck_options *options);
185185

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+
186194
/*
187195
* fsck a tag, and pass info about it back to the caller. This is
188196
* exposed fsck_object() internals for git-mktag(1).

0 commit comments

Comments
 (0)