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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Dec 1, 2022 at 15:46 UTC
a59a8c687f18db2b4c54a9d0795f93c4df1f9703
1 file changed
+22
-12
fsck.c
+22
-12
@@ -1243,19 +1243,21 @@ int fsck_error_function(struct fsck_options *o,
1243
return 1;
1244
}
1245
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)
1249
{
1250
int ret = 0;
1251
struct oidset_iter iter;
1252
const struct object_id *oid;
1253
1252
- oidset_iter_init(&options->gitmodules_found, &iter);
1254
+ oidset_iter_init(blobs_found, &iter);
1255
while ((oid = oidset_iter_next(&iter))) {
1256
enum object_type type;
1257
unsigned long size;
1258
char *buf;
1259
1258
- if (oidset_contains(&options->gitmodules_done, oid))
1260
+ if (oidset_contains(blobs_done, oid))
1261
continue;
1262
1263
buf = read_object_file(oid, &type, &size);
@@ -1263,25 +1265,33 @@ int fsck_finish(struct fsck_options *options)
1265
if (is_promisor_object(oid))
1266
continue;
1267
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);
1270
continue;
1271
}
1272
1273
if (type == OBJ_BLOB)
1274
ret |= fsck_blob(oid, buf, size, options);
1275
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);
1278
free(buf);
1279
}
1280
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");
1294
1283
- oidset_clear(&options->gitmodules_found);
1284
- oidset_clear(&options->gitmodules_done);
1295
return ret;
1296
}
1297