@@ -205,7 +205,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
205
205
if (!strcmp (buf , "skiplist" )) {
206
206
if (equal == len )
207
207
die ("skiplist requires a path" );
208
- oidset_parse_file (& options -> skiplist , buf + equal + 1 ,
208
+ oidset_parse_file (& options -> skip_oids , buf + equal + 1 ,
209
209
the_repository -> hash_algo );
210
210
buf += len + 1 ;
211
211
continue ;
@@ -223,25 +223,25 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
223
223
static int object_on_skiplist (struct fsck_options * opts ,
224
224
const struct object_id * oid )
225
225
{
226
- return opts && oid && oidset_contains (& opts -> skiplist , oid );
226
+ return opts && oid && oidset_contains (& opts -> skip_oids , oid );
227
227
}
228
228
229
- __attribute__((format (printf , 5 , 6 )))
230
- static int report (struct fsck_options * options ,
231
- const struct object_id * oid , enum object_type object_type ,
232
- enum fsck_msg_id msg_id , const char * fmt , ...)
229
+ /*
230
+ * Provide the common functionality for either fscking refs or objects.
231
+ * It will get the current msg error type and call the error_func callback
232
+ * which is registered in the "fsck_options" struct.
233
+ */
234
+ static int fsck_vreport (struct fsck_options * options ,
235
+ void * fsck_report ,
236
+ enum fsck_msg_id msg_id , const char * fmt , va_list ap )
233
237
{
234
- va_list ap ;
235
238
struct strbuf sb = STRBUF_INIT ;
236
239
enum fsck_msg_type msg_type = fsck_msg_type (msg_id , options );
237
240
int result ;
238
241
239
242
if (msg_type == FSCK_IGNORE )
240
243
return 0 ;
241
244
242
- if (object_on_skiplist (options , oid ))
243
- return 0 ;
244
-
245
245
if (msg_type == FSCK_FATAL )
246
246
msg_type = FSCK_ERROR ;
247
247
else if (msg_type == FSCK_INFO )
@@ -250,16 +250,49 @@ static int report(struct fsck_options *options,
250
250
prepare_msg_ids ();
251
251
strbuf_addf (& sb , "%s: " , msg_id_info [msg_id ].camelcased );
252
252
253
- va_start (ap , fmt );
254
253
strbuf_vaddf (& sb , fmt , ap );
255
- result = options -> error_func (options , oid , object_type ,
254
+ result = options -> error_func (options , fsck_report ,
256
255
msg_type , msg_id , sb .buf );
257
256
strbuf_release (& sb );
257
+
258
+ return result ;
259
+ }
260
+
261
+ __attribute__((format (printf , 5 , 6 )))
262
+ static int report (struct fsck_options * options ,
263
+ const struct object_id * oid , enum object_type object_type ,
264
+ enum fsck_msg_id msg_id , const char * fmt , ...)
265
+ {
266
+ va_list ap ;
267
+ struct fsck_object_report report = {
268
+ .oid = oid ,
269
+ .object_type = object_type
270
+ };
271
+ int result ;
272
+
273
+ if (object_on_skiplist (options , oid ))
274
+ return 0 ;
275
+
276
+ va_start (ap , fmt );
277
+ result = fsck_vreport (options , & report , msg_id , fmt , ap );
258
278
va_end (ap );
259
279
260
280
return result ;
261
281
}
262
282
283
+ int fsck_report_ref (struct fsck_options * options ,
284
+ struct fsck_ref_report * report ,
285
+ enum fsck_msg_id msg_id ,
286
+ const char * fmt , ...)
287
+ {
288
+ va_list ap ;
289
+ int result ;
290
+ va_start (ap , fmt );
291
+ result = fsck_vreport (options , report , msg_id , fmt , ap );
292
+ va_end (ap );
293
+ return result ;
294
+ }
295
+
263
296
void fsck_enable_object_names (struct fsck_options * options )
264
297
{
265
298
if (!options -> object_names )
@@ -1200,13 +1233,15 @@ int fsck_buffer(const struct object_id *oid, enum object_type type,
1200
1233
type );
1201
1234
}
1202
1235
1203
- int fsck_error_function (struct fsck_options * o ,
1204
- const struct object_id * oid ,
1205
- enum object_type object_type UNUSED ,
1206
- enum fsck_msg_type msg_type ,
1207
- enum fsck_msg_id msg_id UNUSED ,
1208
- const char * message )
1236
+ int fsck_objects_error_function (struct fsck_options * o ,
1237
+ void * fsck_report ,
1238
+ enum fsck_msg_type msg_type ,
1239
+ enum fsck_msg_id msg_id UNUSED ,
1240
+ const char * message )
1209
1241
{
1242
+ struct fsck_object_report * report = fsck_report ;
1243
+ const struct object_id * oid = report -> oid ;
1244
+
1210
1245
if (msg_type == FSCK_WARN ) {
1211
1246
warning ("object %s: %s" , fsck_describe_object (o , oid ), message );
1212
1247
return 0 ;
@@ -1215,6 +1250,32 @@ int fsck_error_function(struct fsck_options *o,
1215
1250
return 1 ;
1216
1251
}
1217
1252
1253
+ int fsck_refs_error_function (struct fsck_options * options UNUSED ,
1254
+ void * fsck_report ,
1255
+ enum fsck_msg_type msg_type ,
1256
+ enum fsck_msg_id msg_id UNUSED ,
1257
+ const char * message )
1258
+ {
1259
+ struct fsck_ref_report * report = fsck_report ;
1260
+ struct strbuf sb = STRBUF_INIT ;
1261
+ int ret = 0 ;
1262
+
1263
+ strbuf_addstr (& sb , report -> path );
1264
+
1265
+ if (report -> oid )
1266
+ strbuf_addf (& sb , " -> (%s)" , oid_to_hex (report -> oid ));
1267
+ else if (report -> referent )
1268
+ strbuf_addf (& sb , " -> (%s)" , report -> referent );
1269
+
1270
+ if (msg_type == FSCK_WARN )
1271
+ warning ("%s: %s" , sb .buf , message );
1272
+ else
1273
+ ret = error ("%s: %s" , sb .buf , message );
1274
+
1275
+ strbuf_release (& sb );
1276
+ return ret ;
1277
+ }
1278
+
1218
1279
static int fsck_blobs (struct oidset * blobs_found , struct oidset * blobs_done ,
1219
1280
enum fsck_msg_id msg_missing , enum fsck_msg_id msg_type ,
1220
1281
struct fsck_options * options , const char * blob_type )
@@ -1270,6 +1331,17 @@ int fsck_finish(struct fsck_options *options)
1270
1331
return ret ;
1271
1332
}
1272
1333
1334
+ void fsck_options_clear (struct fsck_options * options )
1335
+ {
1336
+ free (options -> msg_type );
1337
+ oidset_clear (& options -> skip_oids );
1338
+ oidset_clear (& options -> gitmodules_found );
1339
+ oidset_clear (& options -> gitmodules_done );
1340
+ oidset_clear (& options -> gitattributes_found );
1341
+ oidset_clear (& options -> gitattributes_done );
1342
+ kh_clear_oid_map (options -> object_names );
1343
+ }
1344
+
1273
1345
int git_fsck_config (const char * var , const char * value ,
1274
1346
const struct config_context * ctx , void * cb )
1275
1347
{
@@ -1303,16 +1375,17 @@ int git_fsck_config(const char *var, const char *value,
1303
1375
* Custom error callbacks that are used in more than one place.
1304
1376
*/
1305
1377
1306
- int fsck_error_cb_print_missing_gitmodules (struct fsck_options * o ,
1307
- const struct object_id * oid ,
1308
- enum object_type object_type ,
1309
- enum fsck_msg_type msg_type ,
1310
- enum fsck_msg_id msg_id ,
1311
- const char * message )
1378
+ int fsck_objects_error_cb_print_missing_gitmodules (struct fsck_options * o ,
1379
+ void * fsck_report ,
1380
+ enum fsck_msg_type msg_type ,
1381
+ enum fsck_msg_id msg_id ,
1382
+ const char * message )
1312
1383
{
1313
1384
if (msg_id == FSCK_MSG_GITMODULES_MISSING ) {
1314
- puts (oid_to_hex (oid ));
1385
+ struct fsck_object_report * report = fsck_report ;
1386
+ puts (oid_to_hex (report -> oid ));
1315
1387
return 0 ;
1316
1388
}
1317
- return fsck_error_function (o , oid , object_type , msg_type , msg_id , message );
1389
+ return fsck_objects_error_function (o , fsck_report ,
1390
+ msg_type , msg_id , message );
1318
1391
}
0 commit comments