@@ -939,9 +939,9 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
fsck_walk_options.walk = mark_object;
fsck_obj_options.walk = mark_used;
- fsck_obj_options.error_func = fsck_error_func;
+ fsck_obj_options.fsck_options.error_func = fsck_error_func;
if (check_strict)
- fsck_obj_options.strict = 1;
+ fsck_obj_options.fsck_options.strict = 1;
if (show_progress == -1)
show_progress = isatty(2);
@@ -956,7 +956,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
if (name_objects)
fsck_enable_object_names(&fsck_walk_options);
- git_config(git_fsck_config, &fsck_obj_options);
+ git_config(git_fsck_config, &fsck_obj_options.fsck_options);
prepare_repo_settings(the_repository);
if (connectivity_only) {
@@ -1770,13 +1770,13 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
} else if (skip_to_optional_arg(arg, "--strict", &arg)) {
strict = 1;
do_fsck_object = 1;
- fsck_set_msg_types(&fsck_objects_options, arg);
+ fsck_set_msg_types(&fsck_objects_options.fsck_options, arg);
} else if (!strcmp(arg, "--check-self-contained-and-connected")) {
strict = 1;
check_self_contained_and_connected = 1;
} else if (skip_to_optional_arg(arg, "--fsck-objects", &arg)) {
do_fsck_object = 1;
- fsck_set_msg_types(&fsck_objects_options, arg);
+ fsck_set_msg_types(&fsck_objects_options.fsck_options, arg);
} else if (!strcmp(arg, "--verify")) {
verify = 1;
} else if (!strcmp(arg, "--verify-stat")) {
@@ -91,12 +91,12 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
if (strbuf_read(&buf, 0, 0) < 0)
die_errno(_("could not read from stdin"));
- fsck_objects_options.error_func = mktag_fsck_error_func;
- fsck_set_msg_type_from_ids(&fsck_objects_options,
+ fsck_objects_options.fsck_options.error_func = mktag_fsck_error_func;
+ fsck_set_msg_type_from_ids(&fsck_objects_options.fsck_options,
FSCK_MSG_EXTRA_HEADER_ENTRY,
FSCK_WARN);
/* config might set fsck.extraHeaderEntry=* again */
- git_config(git_fsck_config, &fsck_objects_options);
+ git_config(git_fsck_config, &fsck_objects_options.fsck_options);
if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_objects_options,
&tagged_oid, &tagged_type))
die(_("tag on stdin did not pass our strict fsck check"));
@@ -635,7 +635,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
}
if (skip_prefix(arg, "--strict=", &arg)) {
strict = 1;
- fsck_set_msg_types(&fsck_objects_options, arg);
+ fsck_set_msg_types(&fsck_objects_options.fsck_options, arg);
continue;
}
if (starts_with(arg, "--pack_header=")) {
@@ -107,7 +107,7 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)
}
static enum fsck_msg_type fsck_msg_type(enum fsck_msg_id msg_id,
- struct fsck_objects_options *options)
+ struct fsck_options *options)
{
assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
@@ -142,7 +142,7 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
return 1;
}
-void fsck_set_msg_type_from_ids(struct fsck_objects_options *options,
+void fsck_set_msg_type_from_ids(struct fsck_options *options,
enum fsck_msg_id msg_id,
enum fsck_msg_type msg_type)
{
@@ -158,7 +158,7 @@ void fsck_set_msg_type_from_ids(struct fsck_objects_options *options,
fsck_configs.msg_type[msg_id] = msg_type;
}
-void fsck_set_msg_type(struct fsck_objects_options *options,
+void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id_str, const char *msg_type_str)
{
int msg_id = parse_msg_id(msg_id_str);
@@ -187,7 +187,7 @@ void fsck_set_msg_type(struct fsck_objects_options *options,
free(to_free);
}
-void fsck_set_msg_types(struct fsck_objects_options *options, const char *values)
+void fsck_set_msg_types(struct fsck_options *options, const char *values)
{
char *buf = xstrdup(values), *to_free = buf;
int done = 0;
@@ -237,9 +237,16 @@ static int report(struct fsck_objects_options *options,
{
va_list ap;
struct strbuf sb = STRBUF_INIT;
- enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options);
+ struct fsck_options *fsck_options;
+ enum fsck_msg_type msg_type;
int result;
+ if (options)
+ fsck_options = &options->fsck_options;
+ else
+ BUG("fsck_options is not set");
+
+ msg_type = fsck_msg_type(msg_id, fsck_options);
if (msg_type == FSCK_IGNORE)
return 0;
@@ -256,8 +263,8 @@ static int report(struct fsck_objects_options *options,
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
- result = options->error_func(options, oid, object_type,
- msg_type, msg_id, sb.buf);
+ result = fsck_options->error_func(options, oid, object_type,
+ msg_type, msg_id, sb.buf);
strbuf_release(&sb);
va_end(ap);
@@ -711,7 +718,7 @@ static int fsck_tree(const struct object_id *tree_oid,
* bits..
*/
case S_IFREG | 0664:
- if (!options->strict)
+ if (!options->fsck_options.strict)
break;
/* fallthrough */
default:
@@ -1283,7 +1290,7 @@ int fsck_finish(struct fsck_objects_options *options)
int git_fsck_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
- struct fsck_objects_options *options = cb;
+ struct fsck_options *options = cb;
const char *msg_id;
if (strcmp(var, "fsck.skiplist") == 0) {
@@ -92,15 +92,16 @@ enum fsck_msg_id {
};
#undef MSG_ID
+struct fsck_options;
struct fsck_objects_options;
struct object;
-void fsck_set_msg_type_from_ids(struct fsck_objects_options *options,
+void fsck_set_msg_type_from_ids(struct fsck_options *options,
enum fsck_msg_id msg_id,
enum fsck_msg_type msg_type);
-void fsck_set_msg_type(struct fsck_objects_options *options,
+void fsck_set_msg_type(struct fsck_options *options,
const char *msg_id, const char *msg_type);
-void fsck_set_msg_types(struct fsck_objects_options *options, const char *values);
+void fsck_set_msg_types(struct fsck_options *options, const char *values);
int is_valid_msg_type(const char *msg_id, const char *msg_type);
/*
@@ -131,10 +132,15 @@ int fsck_error_cb_print_missing_gitmodules(struct fsck_objects_options *o,
enum fsck_msg_id msg_id,
const char *message);
+struct fsck_options {
+ fsck_error error_func;
+ unsigned verbose:1,
+ strict:1;
+};
+
struct fsck_objects_options {
+ struct fsck_options fsck_options;
fsck_walk_func walk;
- fsck_error error_func;
- unsigned strict:1;
struct oidset gitmodules_found;
struct oidset gitmodules_done;
struct oidset gitattributes_found;
@@ -143,27 +149,33 @@ struct fsck_objects_options {
};
#define FSCK_OBJECTS_OPTIONS_DEFAULT { \
+ .fsck_options = { \
+ .error_func = fsck_error_function, \
+ }, \
.gitmodules_found = OIDSET_INIT, \
.gitmodules_done = OIDSET_INIT, \
.gitattributes_found = OIDSET_INIT, \
.gitattributes_done = OIDSET_INIT, \
- .error_func = fsck_error_function \
}
#define FSCK_OBJECTS_OPTIONS_STRICT { \
- .strict = 1, \
+ .fsck_options = { \
+ .error_func = fsck_error_function, \
+ .strict = 1, \
+ }, \
.gitmodules_found = OIDSET_INIT, \
.gitmodules_done = OIDSET_INIT, \
.gitattributes_found = OIDSET_INIT, \
.gitattributes_done = OIDSET_INIT, \
- .error_func = fsck_error_function, \
}
#define FSCK_OBJECTS_OPTIONS_MISSING_GITMODULES { \
- .strict = 1, \
+ .fsck_options = { \
+ .error_func = fsck_error_cb_print_missing_gitmodules, \
+ .strict = 1, \
+ }, \
.gitmodules_found = OIDSET_INIT, \
.gitmodules_done = OIDSET_INIT, \
.gitattributes_found = OIDSET_INIT, \
.gitattributes_done = OIDSET_INIT, \
- .error_func = fsck_error_cb_print_missing_gitmodules, \
}
/* descend in all linked child objects
@@ -2509,8 +2509,8 @@ static int index_mem(struct index_state *istate,
if (flags & HASH_FORMAT_CHECK) {
struct fsck_objects_options opts = FSCK_OBJECTS_OPTIONS_DEFAULT;
- opts.strict = 1;
- opts.error_func = hash_format_check_report;
+ opts.fsck_options.strict = 1;
+ opts.fsck_options.error_func = hash_format_check_report;
if (fsck_buffer(null_oid(), type, buf, size, &opts))
die(_("refusing to create malformed object"));
fsck_finish(&opts);
Create "fsck_options" struct to contain the general fields. Change "fsck_objects_options" to incorporate the general "fsck_options" and object-speicifc options. The fsck message will use "strict" option to set the corresponding "msg_type". Rename the parameter name from "struct fsck_objects_options *" to "struct fsck_options *". Mentored-by: Patrick Steinhardt <ps@pks.im> Mentored-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: shejialuo <shejialuo@gmail.com> --- builtin/fsck.c | 6 +++--- builtin/index-pack.c | 4 ++-- builtin/mktag.c | 6 +++--- builtin/unpack-objects.c | 2 +- fsck.c | 25 ++++++++++++++++--------- fsck.h | 32 ++++++++++++++++++++++---------- object-file.c | 4 ++-- 7 files changed, 49 insertions(+), 30 deletions(-)