FUNC(MISSING_TREE, ERROR) \
FUNC(MISSING_TYPE, ERROR) \
FUNC(MISSING_TYPE_ENTRY, ERROR) \
+ FUNC(MULTIPLE_AUTHORS, ERROR) \
FUNC(NUL_IN_HEADER, ERROR) \
FUNC(TAG_OBJECT_NOT_TAG, ERROR) \
FUNC(TREE_NOT_SORTED, ERROR) \
{
int msg_type;
- msg_type = msg_id_info[msg_id].msg_type;
- if (options->strict && msg_type == FSCK_WARN)
- msg_type = FSCK_ERROR;
+ assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
+
+ if (options->msg_type)
+ msg_type = options->msg_type[msg_id];
+ else {
+ msg_type = msg_id_info[msg_id].msg_type;
+ if (options->strict && msg_type == FSCK_WARN)
+ msg_type = FSCK_ERROR;
+ }
return msg_type;
}
+static int parse_msg_type(const char *str)
+{
+ if (!strcmp(str, "error"))
+ return FSCK_ERROR;
+ else if (!strcmp(str, "warn"))
+ return FSCK_WARN;
+ else
+ die("Unknown fsck message type: '%s'", str);
+}
+
+int is_valid_msg_type(const char *msg_id, const char *msg_type)
+{
+ if (parse_msg_id(msg_id) < 0)
+ return 0;
+ parse_msg_type(msg_type);
+ return 1;
+}
+
+void fsck_set_msg_type(struct fsck_options *options,
+ const char *msg_id, const char *msg_type)
+{
+ int id = parse_msg_id(msg_id), type;
+
+ if (id < 0)
+ die("Unhandled message id: %s", msg_id);
+ type = parse_msg_type(msg_type);
+
+ if (!options->msg_type) {
+ int i;
+ int *msg_type = xmalloc(sizeof(int) * FSCK_MSG_MAX);
+ for (i = 0; i < FSCK_MSG_MAX; i++)
+ msg_type[i] = fsck_msg_type(i, options);
+ options->msg_type = msg_type;
+ }
+
+ options->msg_type[id] = type;
+}
+
+void fsck_set_msg_types(struct fsck_options *options, const char *values)
+{
+ char *buf = xstrdup(values), *to_free = buf;
+ int done = 0;
+
+ while (!done) {
+ int len = strcspn(buf, " ,|"), equal;
+
+ done = !buf[len];
+ if (!len) {
+ buf++;
+ continue;
+ }
+ buf[len] = '\0';
+
+ for (equal = 0;
+ equal < len && buf[equal] != '=' && buf[equal] != ':';
+ equal++)
+ buf[equal] = tolower(buf[equal]);
+ buf[equal] = '\0';
+
+ if (equal == len)
+ die("Missing '=': '%s'", buf);
+
+ fsck_set_msg_type(options, buf, buf + equal + 1);
+ buf += len + 1;
+ }
+ free(to_free);
+}
+
+static void append_msg_id(struct strbuf *sb, const char *msg_id)
+{
+ for (;;) {
+ char c = *(msg_id)++;
+
+ if (!c)
+ break;
+ if (c != '_')
+ strbuf_addch(sb, tolower(c));
+ else {
+ assert(*msg_id);
+ strbuf_addch(sb, *(msg_id)++);
+ }
+ }
+
+ strbuf_addstr(sb, ": ");
+}
+
__attribute__((format (printf, 4, 5)))
static int report(struct fsck_options *options, struct object *object,
enum fsck_msg_id id, const char *fmt, ...)
struct strbuf sb = STRBUF_INIT;
int msg_type = fsck_msg_type(id, options), result;
+ append_msg_id(&sb, msg_id_info[id].id_string);
+
va_start(ap, fmt);
strbuf_vaddf(&sb, fmt, ap);
result = options->error_func(object, msg_type, sb.buf);
static int fsck_ident(const char **ident, struct object *obj, struct fsck_options *options)
{
+ const char *p = *ident;
char *end;
- if (**ident == '<')
+ *ident = strchrnul(*ident, '\n');
+ if (**ident == '\n')
+ (*ident)++;
+
+ if (*p == '<')
return report(options, obj, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
- *ident += strcspn(*ident, "<>\n");
- if (**ident == '>')
+ p += strcspn(p, "<>\n");
+ if (*p == '>')
return report(options, obj, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name");
- if (**ident != '<')
+ if (*p != '<')
return report(options, obj, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email");
- if ((*ident)[-1] != ' ')
+ if (p[-1] != ' ')
return report(options, obj, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
- (*ident)++;
- *ident += strcspn(*ident, "<>\n");
- if (**ident != '>')
+ p++;
+ p += strcspn(p, "<>\n");
+ if (*p != '>')
return report(options, obj, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email");
- (*ident)++;
- if (**ident != ' ')
+ p++;
+ if (*p != ' ')
return report(options, obj, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date");
- (*ident)++;
- if (**ident == '0' && (*ident)[1] != ' ')
+ p++;
+ if (*p == '0' && p[1] != ' ')
return report(options, obj, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date");
- if (date_overflows(strtoul(*ident, &end, 10)))
+ if (date_overflows(strtoul(p, &end, 10)))
return report(options, obj, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
- if (end == *ident || *end != ' ')
+ if ((end == p || *end != ' '))
return report(options, obj, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
- *ident = end + 1;
- if ((**ident != '+' && **ident != '-') ||
- !isdigit((*ident)[1]) ||
- !isdigit((*ident)[2]) ||
- !isdigit((*ident)[3]) ||
- !isdigit((*ident)[4]) ||
- ((*ident)[5] != '\n'))
+ p = end + 1;
+ if ((*p != '+' && *p != '-') ||
+ !isdigit(p[1]) ||
+ !isdigit(p[2]) ||
+ !isdigit(p[3]) ||
+ !isdigit(p[4]) ||
+ (p[5] != '\n'))
return report(options, obj, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone");
- (*ident) += 6;
+ p += 6;
return 0;
}
{
unsigned char tree_sha1[20], sha1[20];
struct commit_graft *graft;
- unsigned parent_count, parent_line_count = 0;
+ unsigned parent_count, parent_line_count = 0, author_count;
int err;
if (require_end_of_header(buffer, size, &commit->object, options))
if (!skip_prefix(buffer, "tree ", &buffer))
return report(options, &commit->object, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line");
- if (get_sha1_hex(buffer, tree_sha1) || buffer[40] != '\n')
- return report(options, &commit->object, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
+ if (get_sha1_hex(buffer, tree_sha1) || buffer[40] != '\n') {
+ err = report(options, &commit->object, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
+ if (err)
+ return err;
+ }
buffer += 41;
while (skip_prefix(buffer, "parent ", &buffer)) {
- if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n')
- return report(options, &commit->object, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
+ if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
+ err = report(options, &commit->object, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
+ if (err)
+ return err;
+ }
buffer += 41;
parent_line_count++;
}
if (graft) {
if (graft->nr_parent == -1 && !parent_count)
; /* shallow commit */
- else if (graft->nr_parent != parent_count)
- return report(options, &commit->object, FSCK_MSG_MISSING_GRAFT, "graft objects missing");
+ else if (graft->nr_parent != parent_count) {
+ err = report(options, &commit->object, FSCK_MSG_MISSING_GRAFT, "graft objects missing");
+ if (err)
+ return err;
+ }
} else {
- if (parent_count != parent_line_count)
- return report(options, &commit->object, FSCK_MSG_MISSING_PARENT, "parent objects missing");
+ if (parent_count != parent_line_count) {
+ err = report(options, &commit->object, FSCK_MSG_MISSING_PARENT, "parent objects missing");
+ if (err)
+ return err;
+ }
}
- if (!skip_prefix(buffer, "author ", &buffer))
- return report(options, &commit->object, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line");
- err = fsck_ident(&buffer, &commit->object, options);
+ author_count = 0;
+ while (skip_prefix(buffer, "author ", &buffer)) {
+ author_count++;
+ err = fsck_ident(&buffer, &commit->object, options);
+ if (err)
+ return err;
+ }
+ if (author_count < 1)
+ err = report(options, &commit->object, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line");
+ else if (author_count > 1)
+ err = report(options, &commit->object, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines");
if (err)
return err;
if (!skip_prefix(buffer, "committer ", &buffer))
int fsck_error_function(struct object *obj, int msg_type, const char *message)
{
+ if (msg_type == FSCK_WARN) {
+ warning("object %s: %s", sha1_to_hex(obj->sha1), message);
+ return 0;
+ }
error("object %s: %s", sha1_to_hex(obj->sha1), message);
return 1;
}