Skip to content

Commit a59a8c6

Browse files
pks-tgitster
authored andcommitted
fsck: pull out function to check a set of blobs
In `fsck_finish()` we check all blobs for consistency that we have found during the tree walk, but that haven't yet been checked. This is only required for gitmodules right now, but will also be required for a new check for gitattributes. Pull out a function `fsck_blobs()` that allows the caller to check a set of blobs for consistency. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bb3a926 commit a59a8c6

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

fsck.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,45 +1243,55 @@ int fsck_error_function(struct fsck_options *o,
12431243
return 1;
12441244
}
12451245

1246-
int fsck_finish(struct fsck_options *options)
1246+
static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done,
1247+
enum fsck_msg_id msg_missing, enum fsck_msg_id msg_type,
1248+
struct fsck_options *options, const char *blob_type)
12471249
{
12481250
int ret = 0;
12491251
struct oidset_iter iter;
12501252
const struct object_id *oid;
12511253

1252-
oidset_iter_init(&options->gitmodules_found, &iter);
1254+
oidset_iter_init(blobs_found, &iter);
12531255
while ((oid = oidset_iter_next(&iter))) {
12541256
enum object_type type;
12551257
unsigned long size;
12561258
char *buf;
12571259

1258-
if (oidset_contains(&options->gitmodules_done, oid))
1260+
if (oidset_contains(blobs_done, oid))
12591261
continue;
12601262

12611263
buf = read_object_file(oid, &type, &size);
12621264
if (!buf) {
12631265
if (is_promisor_object(oid))
12641266
continue;
12651267
ret |= report(options,
1266-
oid, OBJ_BLOB,
1267-
FSCK_MSG_GITMODULES_MISSING,
1268-
"unable to read .gitmodules blob");
1268+
oid, OBJ_BLOB, msg_missing,
1269+
"unable to read %s blob", blob_type);
12691270
continue;
12701271
}
12711272

12721273
if (type == OBJ_BLOB)
12731274
ret |= fsck_blob(oid, buf, size, options);
12741275
else
1275-
ret |= report(options,
1276-
oid, type,
1277-
FSCK_MSG_GITMODULES_BLOB,
1278-
"non-blob found at .gitmodules");
1276+
ret |= report(options, oid, type, msg_type,
1277+
"non-blob found at %s", blob_type);
12791278
free(buf);
12801279
}
12811280

1281+
oidset_clear(blobs_found);
1282+
oidset_clear(blobs_done);
1283+
1284+
return ret;
1285+
}
1286+
1287+
int fsck_finish(struct fsck_options *options)
1288+
{
1289+
int ret = 0;
1290+
1291+
ret |= fsck_blobs(&options->gitmodules_found, &options->gitmodules_done,
1292+
FSCK_MSG_GITMODULES_MISSING, FSCK_MSG_GITMODULES_BLOB,
1293+
options, ".gitmodules");
12821294

1283-
oidset_clear(&options->gitmodules_found);
1284-
oidset_clear(&options->gitmodules_done);
12851295
return ret;
12861296
}
12871297

0 commit comments

Comments
 (0)