#include "fsck.h"
#include "refs.h"
#include "utf8.h"
+#include "sha1-array.h"
#define FSCK_FATAL -1
#define FSCK_INFO -2
return msg_type;
}
+static void init_skiplist(struct fsck_options *options, const char *path)
+{
+ static struct sha1_array skiplist = SHA1_ARRAY_INIT;
+ int sorted, fd;
+ char buffer[41];
+ unsigned char sha1[20];
+
+ if (options->skiplist)
+ sorted = options->skiplist->sorted;
+ else {
+ sorted = 1;
+ options->skiplist = &skiplist;
+ }
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ die("Could not open skip list: %s", path);
+ for (;;) {
+ int result = read_in_full(fd, buffer, sizeof(buffer));
+ if (result < 0)
+ die_errno("Could not read '%s'", path);
+ if (!result)
+ break;
+ if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n')
+ die("Invalid SHA-1: %s", buffer);
+ sha1_array_append(&skiplist, sha1);
+ if (sorted && skiplist.nr > 1 &&
+ hashcmp(skiplist.sha1[skiplist.nr - 2],
+ sha1) > 0)
+ sorted = 0;
+ }
+ close(fd);
+
+ if (sorted)
+ skiplist.sorted = 1;
+}
+
static int parse_msg_type(const char *str)
{
if (!strcmp(str, "error"))
buf[equal] = tolower(buf[equal]);
buf[equal] = '\0';
+ if (!strcmp(buf, "skiplist")) {
+ if (equal == len)
+ die("skiplist requires a path");
+ init_skiplist(options, buf + equal + 1);
+ buf += len + 1;
+ continue;
+ }
+
if (equal == len)
die("Missing '=': '%s'", buf);
if (msg_type == FSCK_IGNORE)
return 0;
+ if (options->skiplist && object &&
+ sha1_array_lookup(options->skiplist, object->sha1) >= 0)
+ return 0;
+
if (msg_type == FSCK_FATAL)
msg_type = FSCK_ERROR;
else if (msg_type == FSCK_INFO)
return retval;
}
-static int require_end_of_header(const void *data, unsigned long size,
- struct object *obj, struct fsck_options *options)
+static int verify_headers(const void *data, unsigned long size,
+ struct object *obj, struct fsck_options *options)
{
const char *buffer = (const char *)data;
unsigned long i;
}
}
+ /*
+ * We did not find double-LF that separates the header
+ * and the body. Not having a body is not a crime but
+ * we do want to see the terminating LF for the last header
+ * line.
+ */
+ if (size && buffer[size - 1] == '\n')
+ return 0;
+
return report(options, obj,
FSCK_MSG_UNTERMINATED_HEADER, "unterminated header");
}
unsigned parent_count, parent_line_count = 0, author_count;
int err;
- if (require_end_of_header(buffer, size, &commit->object, options))
+ if (verify_headers(buffer, size, &commit->object, options))
return -1;
if (!skip_prefix(buffer, "tree ", &buffer))
}
}
- if (require_end_of_header(buffer, size, &tag->object, options))
+ if (verify_headers(buffer, size, &tag->object, options))
goto done;
if (!skip_prefix(buffer, "object ", &buffer)) {