Skip to content

Commit 1b32b59

Browse files
avargitster
authored andcommitted
fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum
Move the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new fsck_msg_type enum. These defines were originally introduced in: - ba002f3 (builtin-fsck: move common object checking code to fsck.c, 2008-02-25) - f50c440 (fsck: disallow demoting grave fsck errors to warnings, 2015-06-22) - efaba7c (fsck: optionally ignore specific fsck issues completely, 2015-06-22) - f27d05b (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e35d65a commit 1b32b59

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

builtin/fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static int objerror(struct object *obj, const char *err)
8484
static int fsck_error_func(struct fsck_options *o,
8585
const struct object_id *oid,
8686
enum object_type object_type,
87-
int msg_type, const char *message)
87+
enum fsck_msg_type msg_type, const char *message)
8888
{
8989
switch (msg_type) {
9090
case FSCK_WARN:

builtin/index-pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,8 @@ static void show_pack_info(int stat_only)
17161716
static int print_dangling_gitmodules(struct fsck_options *o,
17171717
const struct object_id *oid,
17181718
enum object_type object_type,
1719-
int msg_type, const char *message)
1719+
enum fsck_msg_type msg_type,
1720+
const char *message)
17201721
{
17211722
/*
17221723
* NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it

builtin/mktag.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
1717
static int mktag_fsck_error_func(struct fsck_options *o,
1818
const struct object_id *oid,
1919
enum object_type object_type,
20-
int msg_type, const char *message)
20+
enum fsck_msg_type msg_type,
21+
const char *message)
2122
{
2223
switch (msg_type) {
2324
case FSCK_WARN:

fsck.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
static struct oidset gitmodules_found = OIDSET_INIT;
2323
static struct oidset gitmodules_done = OIDSET_INIT;
2424

25-
#define FSCK_FATAL -1
26-
#define FSCK_INFO -2
27-
2825
#define FOREACH_MSG_ID(FUNC) \
2926
/* fatal errors */ \
3027
FUNC(NUL_IN_HEADER, FATAL) \
@@ -97,7 +94,7 @@ static struct {
9794
const char *id_string;
9895
const char *downcased;
9996
const char *camelcased;
100-
int msg_type;
97+
enum fsck_msg_type msg_type;
10198
} msg_id_info[FSCK_MSG_MAX + 1] = {
10299
FOREACH_MSG_ID(MSG_ID)
103100
{ NULL, NULL, NULL, -1 }
@@ -164,13 +161,13 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix)
164161
list_config_item(list, prefix, msg_id_info[i].camelcased);
165162
}
166163

167-
static int fsck_msg_type(enum fsck_msg_id msg_id,
164+
static enum fsck_msg_type fsck_msg_type(enum fsck_msg_id msg_id,
168165
struct fsck_options *options)
169166
{
170167
assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
171168

172169
if (!options->msg_type) {
173-
int msg_type = msg_id_info[msg_id].msg_type;
170+
enum fsck_msg_type msg_type = msg_id_info[msg_id].msg_type;
174171

175172
if (options->strict && msg_type == FSCK_WARN)
176173
msg_type = FSCK_ERROR;
@@ -180,7 +177,7 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,
180177
return options->msg_type[msg_id];
181178
}
182179

183-
static int parse_msg_type(const char *str)
180+
static enum fsck_msg_type parse_msg_type(const char *str)
184181
{
185182
if (!strcmp(str, "error"))
186183
return FSCK_ERROR;
@@ -203,7 +200,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
203200
void fsck_set_msg_type(struct fsck_options *options,
204201
const char *msg_id_str, const char *msg_type_str)
205202
{
206-
int msg_id = parse_msg_id(msg_id_str), msg_type;
203+
int msg_id = parse_msg_id(msg_id_str);
204+
enum fsck_msg_type msg_type;
207205

208206
if (msg_id < 0)
209207
die("Unhandled message id: %s", msg_id_str);
@@ -214,7 +212,7 @@ void fsck_set_msg_type(struct fsck_options *options,
214212

215213
if (!options->msg_type) {
216214
int i;
217-
int *severity;
215+
enum fsck_msg_type *severity;
218216
ALLOC_ARRAY(severity, FSCK_MSG_MAX);
219217
for (i = 0; i < FSCK_MSG_MAX; i++)
220218
severity[i] = fsck_msg_type(i, options);
@@ -275,7 +273,8 @@ static int report(struct fsck_options *options,
275273
{
276274
va_list ap;
277275
struct strbuf sb = STRBUF_INIT;
278-
int msg_type = fsck_msg_type(msg_id, options), result;
276+
enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options);
277+
int result;
279278

280279
if (msg_type == FSCK_IGNORE)
281280
return 0;
@@ -1247,7 +1246,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
12471246
int fsck_error_function(struct fsck_options *o,
12481247
const struct object_id *oid,
12491248
enum object_type object_type,
1250-
int msg_type, const char *message)
1249+
enum fsck_msg_type msg_type, const char *message)
12511250
{
12521251
if (msg_type == FSCK_WARN) {
12531252
warning("object %s: %s", fsck_describe_object(o, oid), message);

fsck.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33

44
#include "oidset.h"
55

6-
#define FSCK_ERROR 1
7-
#define FSCK_WARN 2
8-
#define FSCK_IGNORE 3
6+
enum fsck_msg_type {
7+
FSCK_INFO = -2,
8+
FSCK_FATAL = -1,
9+
FSCK_ERROR = 1,
10+
FSCK_WARN,
11+
FSCK_IGNORE
12+
};
913

1014
struct fsck_options;
1115
struct object;
@@ -29,17 +33,17 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
2933
/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
3034
typedef int (*fsck_error)(struct fsck_options *o,
3135
const struct object_id *oid, enum object_type object_type,
32-
int msg_type, const char *message);
36+
enum fsck_msg_type msg_type, const char *message);
3337

3438
int fsck_error_function(struct fsck_options *o,
3539
const struct object_id *oid, enum object_type object_type,
36-
int msg_type, const char *message);
40+
enum fsck_msg_type msg_type, const char *message);
3741

3842
struct fsck_options {
3943
fsck_walk_func walk;
4044
fsck_error error_func;
4145
unsigned strict:1;
42-
int *msg_type;
46+
enum fsck_msg_type *msg_type;
4347
struct oidset skiplist;
4448
kh_oid_map_t *object_names;
4549
};

0 commit comments

Comments
 (0)