Skip to content

Commit 0ec5dfe

Browse files
shejialuogitster
authored andcommitted
fsck: make "fsck_error" callback generic
The "fsck_error" callback is designed to report the objects-related error messages. It accepts two parameter "oid" and "object_type" which is not generic. In order to provide a unified callback which can report either objects or refs, remove the objects-related parameters and add the generic parameter "void *fsck_report". Create a new "fsck_object_report" structure which incorporates the removed parameters "oid" and "object_type". Then change the corresponding references to adapt to new "fsck_error" callback. 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 8cd4a44 commit 0ec5dfe

File tree

5 files changed

+38
-24
lines changed

5 files changed

+38
-24
lines changed

builtin/fsck.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,15 @@ static int objerror(struct object *obj, const char *err)
9090
}
9191

9292
static int fsck_objects_error_func(struct fsck_options *o UNUSED,
93-
const struct object_id *oid,
94-
enum object_type object_type,
93+
void *fsck_report,
9594
enum fsck_msg_type msg_type,
9695
enum fsck_msg_id msg_id UNUSED,
9796
const char *message)
9897
{
98+
struct fsck_object_report *report = fsck_report;
99+
const struct object_id *oid = report->oid;
100+
enum object_type object_type = report->object_type;
101+
99102
switch (msg_type) {
100103
case FSCK_WARN:
101104
/* TRANSLATORS: e.g. warning in tree 01bfda: <more explanation> */

builtin/mktag.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ static int option_strict = 1;
1818
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
1919

2020
static int mktag_fsck_error_func(struct fsck_options *o UNUSED,
21-
const struct object_id *oid UNUSED,
22-
enum object_type object_type UNUSED,
21+
void *fsck_report UNUSED,
2322
enum fsck_msg_type msg_type,
2423
enum fsck_msg_id msg_id UNUSED,
2524
const char *message)

fsck.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ static int report(struct fsck_options *options,
232232
enum fsck_msg_id msg_id, const char *fmt, ...)
233233
{
234234
va_list ap;
235+
struct fsck_object_report report = {
236+
.oid = oid,
237+
.object_type = object_type
238+
};
235239
struct strbuf sb = STRBUF_INIT;
236240
enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options);
237241
int result;
@@ -252,7 +256,7 @@ static int report(struct fsck_options *options,
252256

253257
va_start(ap, fmt);
254258
strbuf_vaddf(&sb, fmt, ap);
255-
result = options->error_func(options, oid, object_type,
259+
result = options->error_func(options, &report,
256260
msg_type, msg_id, sb.buf);
257261
strbuf_release(&sb);
258262
va_end(ap);
@@ -1201,12 +1205,14 @@ int fsck_buffer(const struct object_id *oid, enum object_type type,
12011205
}
12021206

12031207
int fsck_objects_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)
1208+
void *fsck_report,
1209+
enum fsck_msg_type msg_type,
1210+
enum fsck_msg_id msg_id UNUSED,
1211+
const char *message)
12091212
{
1213+
struct fsck_object_report *report = fsck_report;
1214+
const struct object_id *oid = report->oid;
1215+
12101216
if (msg_type == FSCK_WARN) {
12111217
warning("object %s: %s", fsck_describe_object(o, oid), message);
12121218
return 0;
@@ -1304,16 +1310,16 @@ int git_fsck_config(const char *var, const char *value,
13041310
*/
13051311

13061312
int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o,
1307-
const struct object_id *oid,
1308-
enum object_type object_type,
1313+
void *fsck_report,
13091314
enum fsck_msg_type msg_type,
13101315
enum fsck_msg_id msg_id,
13111316
const char *message)
13121317
{
13131318
if (msg_id == FSCK_MSG_GITMODULES_MISSING) {
1314-
puts(oid_to_hex(oid));
1319+
struct fsck_object_report *report = fsck_report;
1320+
puts(oid_to_hex(report->oid));
13151321
return 0;
13161322
}
1317-
return fsck_objects_error_function(o, oid, object_type,
1323+
return fsck_objects_error_function(o, fsck_report,
13181324
msg_type, msg_id, message);
13191325
}

fsck.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,30 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type);
114114
typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
115115
void *data, struct fsck_options *options);
116116

117-
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
117+
/*
118+
* Callback for reporting errors either for objects or refs. The "fsck_report"
119+
* is a generic pointer that can be used to pass any information.
120+
*/
118121
typedef int (*fsck_error)(struct fsck_options *o,
119-
const struct object_id *oid, enum object_type object_type,
122+
void *fsck_report,
120123
enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
121124
const char *message);
122125

123126
int fsck_objects_error_function(struct fsck_options *o,
124-
const struct object_id *oid, enum object_type object_type,
127+
void *fsck_report,
125128
enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
126129
const char *message);
127130
int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o,
128-
const struct object_id *oid,
129-
enum object_type object_type,
131+
void *fsck_report,
130132
enum fsck_msg_type msg_type,
131133
enum fsck_msg_id msg_id,
132134
const char *message);
133135

136+
struct fsck_object_report {
137+
const struct object_id *oid;
138+
enum object_type object_type;
139+
};
140+
134141
struct fsck_options {
135142
fsck_walk_func walk;
136143
fsck_error error_func;

object-file.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,11 +2470,10 @@ int repo_has_object_file(struct repository *r,
24702470
* give more context.
24712471
*/
24722472
static int hash_format_check_report(struct fsck_options *opts UNUSED,
2473-
const struct object_id *oid UNUSED,
2474-
enum object_type object_type UNUSED,
2475-
enum fsck_msg_type msg_type UNUSED,
2476-
enum fsck_msg_id msg_id UNUSED,
2477-
const char *message)
2473+
void *fsck_report UNUSED,
2474+
enum fsck_msg_type msg_type UNUSED,
2475+
enum fsck_msg_id msg_id UNUSED,
2476+
const char *message)
24782477
{
24792478
error(_("object fails fsck: %s"), message);
24802479
return 1;

0 commit comments

Comments
 (0)