@@ -205,7 +205,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
205205 if (!strcmp (buf , "skiplist" )) {
206206 if (equal == len )
207207 die ("skiplist requires a path" );
208- oidset_parse_file (& options -> skiplist , buf + equal + 1 ,
208+ oidset_parse_file (& options -> skip_oids , buf + equal + 1 ,
209209 the_repository -> hash_algo );
210210 buf += len + 1 ;
211211 continue ;
@@ -223,25 +223,25 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
223223static int object_on_skiplist (struct fsck_options * opts ,
224224 const struct object_id * oid )
225225{
226- return opts && oid && oidset_contains (& opts -> skiplist , oid );
226+ return opts && oid && oidset_contains (& opts -> skip_oids , oid );
227227}
228228
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 )
233237{
234- va_list ap ;
235238 struct strbuf sb = STRBUF_INIT ;
236239 enum fsck_msg_type msg_type = fsck_msg_type (msg_id , options );
237240 int result ;
238241
239242 if (msg_type == FSCK_IGNORE )
240243 return 0 ;
241244
242- if (object_on_skiplist (options , oid ))
243- return 0 ;
244-
245245 if (msg_type == FSCK_FATAL )
246246 msg_type = FSCK_ERROR ;
247247 else if (msg_type == FSCK_INFO )
@@ -250,16 +250,49 @@ static int report(struct fsck_options *options,
250250 prepare_msg_ids ();
251251 strbuf_addf (& sb , "%s: " , msg_id_info [msg_id ].camelcased );
252252
253- va_start (ap , fmt );
254253 strbuf_vaddf (& sb , fmt , ap );
255- result = options -> error_func (options , oid , object_type ,
254+ result = options -> error_func (options , fsck_report ,
256255 msg_type , msg_id , sb .buf );
257256 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 );
258278 va_end (ap );
259279
260280 return result ;
261281}
262282
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+
263296void fsck_enable_object_names (struct fsck_options * options )
264297{
265298 if (!options -> object_names )
@@ -1200,13 +1233,15 @@ int fsck_buffer(const struct object_id *oid, enum object_type type,
12001233 type );
12011234}
12021235
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 )
12091241{
1242+ struct fsck_object_report * report = fsck_report ;
1243+ const struct object_id * oid = report -> oid ;
1244+
12101245 if (msg_type == FSCK_WARN ) {
12111246 warning ("object %s: %s" , fsck_describe_object (o , oid ), message );
12121247 return 0 ;
@@ -1215,6 +1250,32 @@ int fsck_error_function(struct fsck_options *o,
12151250 return 1 ;
12161251}
12171252
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+
12181279static int fsck_blobs (struct oidset * blobs_found , struct oidset * blobs_done ,
12191280 enum fsck_msg_id msg_missing , enum fsck_msg_id msg_type ,
12201281 struct fsck_options * options , const char * blob_type )
@@ -1270,6 +1331,17 @@ int fsck_finish(struct fsck_options *options)
12701331 return ret ;
12711332}
12721333
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+
12731345int git_fsck_config (const char * var , const char * value ,
12741346 const struct config_context * ctx , void * cb )
12751347{
@@ -1303,16 +1375,17 @@ int git_fsck_config(const char *var, const char *value,
13031375 * Custom error callbacks that are used in more than one place.
13041376 */
13051377
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 )
13121383{
13131384 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 ));
13151387 return 0 ;
13161388 }
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 );
13181391}
0 commit comments