]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsck.c: add an fsck_set_msg_type() API that takes enums
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Sun, 28 Mar 2021 13:15:47 +0000 (15:15 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Mar 2021 02:03:10 +0000 (19:03 -0700)
Change code I added in acf9de4c94e (mktag: use fsck instead of custom
verify_tag(), 2021-01-05) to make use of a new API function that takes
the fsck_msg_{id,type} types, instead of arbitrary strings that
we'll (hopefully) parse into those types.

At the time that the fsck_set_msg_type() API was introduced in
0282f4dced0 (fsck: offer a function to demote fsck errors to warnings,
2015-06-22) it was only intended to be used to parse user-supplied
data.

For things that are purely internal to the C code it makes sense to
have the compiler check these arguments, and to skip the sanity
checking of the data in fsck_set_msg_type() which is redundant to
checks we get from the compiler.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/mktag.c
fsck.c
fsck.h

index 96e63bc772ae2f051b629edc4f76f6634edce671..dddcccdd368328261db51d47b3b5a7b444fbaca5 100644 (file)
@@ -88,7 +88,8 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
                die_errno(_("could not read from stdin"));
 
        fsck_options.error_func = mktag_fsck_error_func;
-       fsck_set_msg_type(&fsck_options, "extraheaderentry", "warn");
+       fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
+                                  FSCK_WARN);
        /* config might set fsck.extraHeaderEntry=* again */
        git_config(git_fsck_config, &fsck_options);
        if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
diff --git a/fsck.c b/fsck.c
index 23a77fe2e0fbd4fa7b05bdbaa72b430ba1deca0f..a59832a1650850a937cfe7c1b754f3c9c5ae3725 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -132,6 +132,22 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
        return 1;
 }
 
+void fsck_set_msg_type_from_ids(struct fsck_options *options,
+                               enum fsck_msg_id msg_id,
+                               enum fsck_msg_type msg_type)
+{
+       if (!options->msg_type) {
+               int i;
+               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);
+               options->msg_type = severity;
+       }
+
+       options->msg_type[msg_id] = msg_type;
+}
+
 void fsck_set_msg_type(struct fsck_options *options,
                       const char *msg_id_str, const char *msg_type_str)
 {
@@ -144,16 +160,7 @@ void fsck_set_msg_type(struct fsck_options *options,
        if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
                die("Cannot demote %s to %s", msg_id_str, msg_type_str);
 
-       if (!options->msg_type) {
-               int i;
-               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);
-               options->msg_type = severity;
-       }
-
-       options->msg_type[msg_id] = msg_type;
+       fsck_set_msg_type_from_ids(options, msg_id, msg_type);
 }
 
 void fsck_set_msg_types(struct fsck_options *options, const char *values)
diff --git a/fsck.h b/fsck.h
index fa2d4955ab3b04308eb738d83ad080c9b25bf1a3..d284bac361498e6fb418c973c59941667d01798b 100644 (file)
--- a/fsck.h
+++ b/fsck.h
@@ -82,6 +82,9 @@ enum fsck_msg_id {
 struct fsck_options;
 struct object;
 
+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_options *options,
                       const char *msg_id, const char *msg_type);
 void fsck_set_msg_types(struct fsck_options *options, const char *values);