108
{
109
int msg_type;
110
111
- msg_type = msg_id_info[msg_id].msg_type;
112
- if (options->strict && msg_type == FSCK_WARN)
113
- msg_type = FSCK_ERROR;
111
+ assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
112
+
113
+ if (options->msg_type)
114
+ msg_type = options->msg_type[msg_id];
115
+ else {
116
+ msg_type = msg_id_info[msg_id].msg_type;
117
+ if (options->strict && msg_type == FSCK_WARN)
118
+ msg_type = FSCK_ERROR;
119
+ }
120
121
return msg_type;
122
}
123
124
+static int parse_msg_type(const char *str)
125
+{
126
+ if (!strcmp(str, "error"))
127
+ return FSCK_ERROR;
128
+ else if (!strcmp(str, "warn"))
129
+ return FSCK_WARN;
130
+ else
131
+ die("Unknown fsck message type: '%s'", str);
132
+}
133
+
134
+void fsck_set_msg_type(struct fsck_options *options,
135
+ const char *msg_id, const char *msg_type)
136
+{
137
+ int id = parse_msg_id(msg_id), type;
138
+
139
+ if (id < 0)
140
+ die("Unhandled message id: %s", msg_id);
141
+ type = parse_msg_type(msg_type);
142
+
143
+ if (!options->msg_type) {
144
+ int i;
145
+ int *msg_type = xmalloc(sizeof(int) * FSCK_MSG_MAX);
146
+ for (i = 0; i < FSCK_MSG_MAX; i++)
147
+ msg_type[i] = fsck_msg_type(i, options);
148
+ options->msg_type = msg_type;
149
+ }
150
+
151
+ options->msg_type[id] = type;
152
+}
153
+
154
+void fsck_set_msg_types(struct fsck_options *options, const char *values)
155
+{
156
+ char *buf = xstrdup(values), *to_free = buf;
157
+ int done = 0;
158
+
159
+ while (!done) {
160
+ int len = strcspn(buf, " ,|"), equal;
161
+
162
+ done = !buf[len];
163
+ if (!len) {
164
+ buf++;
165
+ continue;
166
+ }
167
+ buf[len] = '\0';
168
+
169
+ for (equal = 0;
170
+ equal < len && buf[equal] != '=' && buf[equal] != ':';
171
+ equal++)
172
+ buf[equal] = tolower(buf[equal]);
173
+ buf[equal] = '\0';
174
+
175
+ if (equal == len)
176
+ die("Missing '=': '%s'", buf);
177
+
178
+ fsck_set_msg_type(options, buf, buf + equal + 1);
179
+ buf += len + 1;
180
+ }
181
+ free(to_free);
182
+}
183
+
184
__attribute__((format (printf, 4, 5)))
185
static int report(struct fsck_options *options, struct object *object,
186
enum fsck_msg_id id, const char *fmt, ...)
670
671
int fsck_error_function(struct object *obj, int msg_type, const char *message)
672
{
673
+ if (msg_type == FSCK_WARN) {
674
+ warning("object %s: %s", sha1_to_hex(obj->sha1), message);
675
+ return 0;
676
+ }
677
error("object %s: %s", sha1_to_hex(obj->sha1), message);
678
return 1;
679
}