Skip to content

Commit 53692df

Browse files
avargitster
authored andcommitted
fsck.c: add an fsck_set_msg_type() API that takes enums
Change code I added in acf9de4 (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 0282f4d (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 394d5d3 commit 53692df

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

builtin/mktag.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
8888
die_errno(_("could not read from stdin"));
8989

9090
fsck_options.error_func = mktag_fsck_error_func;
91-
fsck_set_msg_type(&fsck_options, "extraheaderentry", "warn");
91+
fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
92+
FSCK_WARN);
9293
/* config might set fsck.extraHeaderEntry=* again */
9394
git_config(git_fsck_config, &fsck_options);
9495
if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,

fsck.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
132132
return 1;
133133
}
134134

135+
void fsck_set_msg_type_from_ids(struct fsck_options *options,
136+
enum fsck_msg_id msg_id,
137+
enum fsck_msg_type msg_type)
138+
{
139+
if (!options->msg_type) {
140+
int i;
141+
enum fsck_msg_type *severity;
142+
ALLOC_ARRAY(severity, FSCK_MSG_MAX);
143+
for (i = 0; i < FSCK_MSG_MAX; i++)
144+
severity[i] = fsck_msg_type(i, options);
145+
options->msg_type = severity;
146+
}
147+
148+
options->msg_type[msg_id] = msg_type;
149+
}
150+
135151
void fsck_set_msg_type(struct fsck_options *options,
136152
const char *msg_id_str, const char *msg_type_str)
137153
{
@@ -144,16 +160,7 @@ void fsck_set_msg_type(struct fsck_options *options,
144160
if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
145161
die("Cannot demote %s to %s", msg_id_str, msg_type_str);
146162

147-
if (!options->msg_type) {
148-
int i;
149-
enum fsck_msg_type *severity;
150-
ALLOC_ARRAY(severity, FSCK_MSG_MAX);
151-
for (i = 0; i < FSCK_MSG_MAX; i++)
152-
severity[i] = fsck_msg_type(i, options);
153-
options->msg_type = severity;
154-
}
155-
156-
options->msg_type[msg_id] = msg_type;
163+
fsck_set_msg_type_from_ids(options, msg_id, msg_type);
157164
}
158165

159166
void fsck_set_msg_types(struct fsck_options *options, const char *values)

fsck.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ enum fsck_msg_id {
8282
struct fsck_options;
8383
struct object;
8484

85+
void fsck_set_msg_type_from_ids(struct fsck_options *options,
86+
enum fsck_msg_id msg_id,
87+
enum fsck_msg_type msg_type);
8588
void fsck_set_msg_type(struct fsck_options *options,
8689
const char *msg_id, const char *msg_type);
8790
void fsck_set_msg_types(struct fsck_options *options, const char *values);

0 commit comments

Comments
 (0)