From 1b32b59f9bd78b3475195a6e99c629a5ffefdea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Sun, 28 Mar 2021 15:15:40 +0200 Subject: fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new fsck_msg_type enum. These defines were originally introduced in: - ba002f3b28a (builtin-fsck: move common object checking code to fsck.c, 2008-02-25) - f50c4407305 (fsck: disallow demoting grave fsck errors to warnings, 2015-06-22) - efaba7cc77f (fsck: optionally ignore specific fsck issues completely, 2015-06-22) - f27d05b1704 (fsck: allow upgrading fsck warnings to errors, 2015-06-22) The reason these were defined in two different places is because we use FSCK_{IGNORE,INFO,FATAL} only in fsck.c, but FSCK_{ERROR,WARN} are used by external callbacks. Untangling that would take some more work, since we expose the new "enum fsck_msg_type" to both. Similar to "enum object_type" it's not worth structuring the API in such a way that only those who need FSCK_{ERROR,WARN} pass around a different type. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- fsck.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'fsck.c') diff --git a/fsck.c b/fsck.c index 8614ee2c2a..c5a81e4ff0 100644 --- a/fsck.c +++ b/fsck.c @@ -22,9 +22,6 @@ static struct oidset gitmodules_found = OIDSET_INIT; static struct oidset gitmodules_done = OIDSET_INIT; -#define FSCK_FATAL -1 -#define FSCK_INFO -2 - #define FOREACH_MSG_ID(FUNC) \ /* fatal errors */ \ FUNC(NUL_IN_HEADER, FATAL) \ @@ -97,7 +94,7 @@ static struct { const char *id_string; const char *downcased; const char *camelcased; - int msg_type; + enum fsck_msg_type msg_type; } msg_id_info[FSCK_MSG_MAX + 1] = { FOREACH_MSG_ID(MSG_ID) { NULL, NULL, NULL, -1 } @@ -164,13 +161,13 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix) list_config_item(list, prefix, msg_id_info[i].camelcased); } -static int fsck_msg_type(enum fsck_msg_id msg_id, +static enum fsck_msg_type fsck_msg_type(enum fsck_msg_id msg_id, struct fsck_options *options) { assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX); if (!options->msg_type) { - int msg_type = msg_id_info[msg_id].msg_type; + enum fsck_msg_type msg_type = msg_id_info[msg_id].msg_type; if (options->strict && msg_type == FSCK_WARN) msg_type = FSCK_ERROR; @@ -180,7 +177,7 @@ static int fsck_msg_type(enum fsck_msg_id msg_id, return options->msg_type[msg_id]; } -static int parse_msg_type(const char *str) +static enum fsck_msg_type parse_msg_type(const char *str) { if (!strcmp(str, "error")) return FSCK_ERROR; @@ -203,7 +200,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type) 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), msg_type; + int msg_id = parse_msg_id(msg_id_str); + enum fsck_msg_type msg_type; if (msg_id < 0) die("Unhandled message id: %s", msg_id_str); @@ -214,7 +212,7 @@ void fsck_set_msg_type(struct fsck_options *options, if (!options->msg_type) { int i; - int *severity; + enum fsck_msg_type *severity; ALLOC_ARRAY(severity, FSCK_MSG_MAX); for (i = 0; i < FSCK_MSG_MAX; i++) severity[i] = fsck_msg_type(i, options); @@ -275,7 +273,8 @@ static int report(struct fsck_options *options, { va_list ap; struct strbuf sb = STRBUF_INIT; - int msg_type = fsck_msg_type(msg_id, options), result; + enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options); + int result; if (msg_type == FSCK_IGNORE) return 0; @@ -1247,7 +1246,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size, int fsck_error_function(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, - int msg_type, const char *message) + enum fsck_msg_type msg_type, const char *message) { if (msg_type == FSCK_WARN) { warning("object %s: %s", fsck_describe_object(o, oid), message); -- cgit v1.2.3