Skip to content

Commit 3473d18

Browse files
shejialuogitster
authored andcommitted
fsck: add a unified interface for reporting fsck messages
The static function "report" provided by "fsck.c" aims at checking error type and calling the callback "error_func" to report the message. Both refs and objects need to check the error type of the current fsck message. In order to extract this common behavior, create a new function "fsck_vreport". Instead of using "...", provide "va_list" to allow more flexibility. Instead of changing "report" prototype to be align with the "fsck_vreport" function, we leave the "report" prototype unchanged due to the reason that there are nearly 62 references about "report" function. Simply change "report" function to use "fsck_vreport" to report objects related messages. Mentored-by: Patrick Steinhardt <[email protected]> Mentored-by: Karthik Nayak <[email protected]> Signed-off-by: shejialuo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0ec5dfe commit 3473d18

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

fsck.c

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -226,26 +226,22 @@ static int object_on_skiplist(struct fsck_options *opts,
226226
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;
235-
struct fsck_object_report report = {
236-
.oid = oid,
237-
.object_type = object_type
238-
};
239238
struct strbuf sb = STRBUF_INIT;
240239
enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options);
241240
int result;
242241

243242
if (msg_type == FSCK_IGNORE)
244243
return 0;
245244

246-
if (object_on_skiplist(options, oid))
247-
return 0;
248-
249245
if (msg_type == FSCK_FATAL)
250246
msg_type = FSCK_ERROR;
251247
else if (msg_type == FSCK_INFO)
@@ -254,11 +250,31 @@ static int report(struct fsck_options *options,
254250
prepare_msg_ids();
255251
strbuf_addf(&sb, "%s: ", msg_id_info[msg_id].camelcased);
256252

257-
va_start(ap, fmt);
258253
strbuf_vaddf(&sb, fmt, ap);
259-
result = options->error_func(options, &report,
254+
result = options->error_func(options, fsck_report,
260255
msg_type, msg_id, sb.buf);
261256
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);
262278
va_end(ap);
263279

264280
return result;

0 commit comments

Comments
 (0)