Skip to contentSkip to conversation

Introduce an internal API to interact with the fsck machinery

PATCH Superseded Johannes Schindelin 6 participants 275 messages Jun 15, 2016 Documentation Page 2 of 2

lore
Share & tools
lore
#158 lore raw

PATCH v5 2/19 fsck: Introduce identifiers for fsck messages

In reply to Johannes Schindelin

Instead of specifying whether a message by the fsck machinery constitutes an error or a warning, let's specify an identifier relating to the concrete problem that was encountered. This is necessary for upcoming support to be able to demote certain errors to warnings.

In the process, simplify the requirements on the calling code: instead of having to handle full-blown varargs in every callback, we now send a string buffer ready to be used by the callback.

We could use a simple enum for the message IDs here, but we want to guarantee that the enum values are associated with the appropriate message types (i.e. error or warning?). Besides, we want to introduce a parser in the next commit that maps the string representation to the enum value, hence we use the slightly ugly preprocessor construct that is extensible for use with said parser.

---
 builtin/fsck.c |  26 +++-----
 fsck.c         | 201 +++++++++++++++++++++++++++++++++++++++++----------------
 fsck.h         |   5 +-
 3 files changed, 154 insertions(+), 78 deletions(-)
builtin/fsck.c +8 -18
index 981dca5..fff38fe 100644
@@ -46,33 +46,23 @@ static int show_dangling = 1;
 #define DIRENT_SORT_HINT(de) ((de)->d_ino)
 #endif
 
-static void objreport(struct object *obj, const char *severity,
-                      const char *err, va_list params)
+static void objreport(struct object *obj, const char *msg_type,
+			const char *err)
 {
-	fprintf(stderr, "%s in %s %s: ",
-	        severity, typename(obj->type), sha1_to_hex(obj->sha1));
-	vfprintf(stderr, err, params);
-	fputs("\n", stderr);
+	fprintf(stderr, "%s in %s %s: %s\n",
+		msg_type, typename(obj->type), sha1_to_hex(obj->sha1), err);
 }
 
-__attribute__((format (printf, 2, 3)))
-static int objerror(struct object *obj, const char *err, ...)
+static int objerror(struct object *obj, const char *err)
 {
-	va_list params;
-	va_start(params, err);
 	errors_found |= ERROR_OBJECT;
-	objreport(obj, "error", err, params);
-	va_end(params);
+	objreport(obj, "error", err);
 	return -1;
 }
 
-__attribute__((format (printf, 3, 4)))
-static int fsck_error_func(struct object *obj, int type, const char *err, ...)
+static int fsck_error_func(struct object *obj, int type, const char *message)
 {
-	va_list params;
-	va_start(params, err);
-	objreport(obj, (type == FSCK_WARN) ? "warning" : "error", err, params);
-	va_end(params);
+	objreport(obj, (type == FSCK_WARN) ? "warning" : "error", message);
 	return (type == FSCK_WARN) ? 0 : 1;
 }
 
fsck.c +144 -57

356 lines not on this page · raw message

fsck.h +2 -3
index 07d0ab2..f6f268a 100644
@@ -17,10 +17,9 @@ struct fsck_options;
 typedef int (*fsck_walk_func)(struct object *obj, int type, void *data, struct fsck_options *options);
 
 /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
-typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...);
+typedef int (*fsck_error)(struct object *obj, int type, const char *message);
 
-__attribute__((format (printf, 3, 4)))
-int fsck_error_function(struct object *obj, int type, const char *fmt, ...);
+int fsck_error_function(struct object *obj, int type, const char *message);
 
 struct fsck_options {
 	fsck_walk_func walk;
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#159 lore raw

PATCH v5 3/19 fsck: Provide a function to parse fsck message IDs

In reply to Johannes Schindelin

These functions will be used in the next commits to allow the user to ask fsck to handle specific problems differently, e.g. demoting certain errors to warnings. The upcoming fsck_set_msg_types() function has to handle partial strings because we would like to be able to parse, say, 'missingemail=warn,missingtaggerentry=warn' command line parameters (which will be passed by receive-pack to index-pack and unpack-objects).

To make the parsing robust, we generate strings from the enum keys, and using these keys, we match up strings without dashes case-insensitively to the corresponding enum values.

---
 fsck.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)
fsck.c +28 -2
index ed0bfc3..4595c7f 100644
@@ -63,15 +63,41 @@ enum fsck_msg_id {
 };
 #undef MSG_ID
 
-#define MSG_ID(id, msg_type) { FSCK_##msg_type },
+#define STR(x) #x
+#define MSG_ID(id, msg_type) { STR(id), FSCK_##msg_type },
 static struct {
+	const char *id_string;
 	int msg_type;
 } msg_id_info[FSCK_MSG_MAX + 1] = {
 	FOREACH_MSG_ID(MSG_ID)
-	{ -1 }
+	{ NULL, -1 }
 };
 #undef MSG_ID
 
+static int parse_msg_id(const char *text, int len)
+{
+	int i, j;
+
+	if (len < 0)
+		len = strlen(text);
+
+	for (i = 0; i < FSCK_MSG_MAX; i++) {
+		const char *key = msg_id_info[i].id_string;
+		/* match id_string case-insensitively, without underscores. */
+		for (j = 0; j < len; j++) {
+			char c = *(key++);
+			if (c == '_')
+				c = *(key++);
+			if (toupper(text[j]) != c)
+				break;
+		}
+		if (j == len && !*key)
+			return i;
+	}
+
+	return -1;
+}
+
 static int fsck_msg_type(enum fsck_msg_id msg_id,
 	struct fsck_options *options)
 {
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#160 lore raw

PATCH v5 4/19 fsck: Offer a function to demote fsck errors to warnings

In reply to Johannes Schindelin

There are legacy repositories out there whose older commits and tags have issues that prevent pushing them when 'receive.fsckObjects' is set. One real-life example is a commit object that has been hand-crafted to list two authors.

Often, it is not possible to fix those issues without disrupting the work with said repositories, yet it is still desirable to perform checks by setting receive.fsckObjects = true. This commit is the first step to allow demoting specific fsck issues to mere warnings.

The fsck_set_msg_types() function added by this commit parses a list of settings in the form:

missingemail=warn,badname=warn,...

Unfortunately, the FSCK_WARN/FSCK_ERROR flag is only really heeded by git fsck so far, but other call paths (e.g. git index-pack --strict) error out *always* no matter what type was specified. Therefore, we need to take extra care to set all message types to FSCK_ERROR by default in those cases.

---
 fsck.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 fsck.h | 10 ++++++--
 2 files changed, 87 insertions(+), 5 deletions(-)
fsck.c +79 -3
index 4595c7f..7db81d2 100644
@@ -103,13 +103,85 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,
 {
 	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 inline int substrcmp(const char *string, int len, const char *match)
+{
+	int match_len = strlen(match);
+	if (match_len != len)
+		return -1;
+	return memcmp(string, match, len);
+}
+
+static int parse_msg_type(const char *str, int len)
+{
+	if (len < 0)
+		len = strlen(str);
+
+	if (!substrcmp(str, len, "error"))
+		return FSCK_ERROR;
+	else if (!substrcmp(str, len, "warn"))
+		return FSCK_WARN;
+	else
+		die("Unknown fsck message type: '%.*s'",
+				len, str);
+}
+
+void fsck_set_msg_type(struct fsck_options *options,
+		const char *msg_id, int msg_id_len,
+		const char *msg_type, int msg_type_len)
+{
+	int id = parse_msg_id(msg_id, msg_id_len), type;
+
+	if (id < 0)
+		die("Unhandled message id: %.*s", msg_id_len, msg_id);
+	type = parse_msg_type(msg_type, msg_type_len);
+
+	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)
+{
+	while (*values) {
+		int len = strcspn(values, " ,|"), equal;
+
+		if (!len) {
+			values++;
+			continue;
+		}
+
+		for (equal = 0; equal < len; equal++)
+			if (values[equal] == '=' || values[equal] == ':')
+				break;
+
+		if (equal == len)
+			die("Missing '=': '%.*s'", len, values);
+
+		fsck_set_msg_type(options, values, equal,
+				values + equal + 1, len - equal - 1);
+		values += len;
+	}
+}
+
 __attribute__((format (printf, 4, 5)))
 static int report(struct fsck_options *options, struct object *object,
 	enum fsck_msg_id id, const char *fmt, ...)
@@ -599,6 +671,10 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
 
 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;
 }
fsck.h +8 -2
index f6f268a..edb4540 100644
@@ -6,6 +6,11 @@
 
 struct fsck_options;
 
+void fsck_set_msg_type(struct fsck_options *options,
+		const char *msg_id, int msg_id_len,
+		const char *msg_type, int msg_type_len);
+void fsck_set_msg_types(struct fsck_options *options, const char *values);
+
 /*
  * callback function for fsck_walk
  * type is the expected type of the object or OBJ_ANY
@@ -25,10 +30,11 @@ struct fsck_options {
 	fsck_walk_func walk;
 	fsck_error error_func;
 	unsigned strict:1;
+	int *msg_type;
 };
 
-#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0 }
-#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1 }
+#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL }
+#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL }
 
 /* descend in all linked child objects
  * the return value is:
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#161 lore raw

PATCH v5 5/19 fsck (receive-pack): Allow demoting errors to warnings

In reply to Johannes Schindelin

For example, missing emails in commit and tag objects can be demoted to mere warnings with

git config receive.fsck.missingemail=warn

The value is actually a comma-separated list.

In case that the same key is listed in multiple receive.fsck.<msg-id> lines in the config, the latter configuration wins (this can happen for example when both $HOME/.gitconfig and .git/config contain message type settings).

As git receive-pack does not actually perform the checks, it hands off the setting to index-pack or unpack-objects in the form of an optional argument to the --strict option.

---
 builtin/index-pack.c     |  4 ++++
 builtin/receive-pack.c   | 17 +++++++++++++++--
 builtin/unpack-objects.c |  5 +++++
 fsck.c                   |  8 ++++++++
 fsck.h                   |  1 +
 5 files changed, 33 insertions(+), 2 deletions(-)
builtin/index-pack.c +4 -0
index 87ae9ba..98e14fe 100644
@@ -1633,6 +1633,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 			} else if (!strcmp(arg, "--strict")) {
 				strict = 1;
 				do_fsck_object = 1;
+			} else if (skip_prefix(arg, "--strict=", &arg)) {
+				strict = 1;
+				do_fsck_object = 1;
+				fsck_set_msg_types(&fsck_options, arg);
 			} else if (!strcmp(arg, "--check-self-contained-and-connected")) {
 				strict = 1;
 				check_self_contained_and_connected = 1;
builtin/receive-pack.c +15 -2
index 94d0571..3afe8f8 100644
@@ -19,6 +19,7 @@
 #include "tag.h"
 #include "gpg-interface.h"
 #include "sigchain.h"
+#include "fsck.h"
 
 static const char receive_pack_usage[] = "git receive-pack <git-dir>";
 
@@ -36,6 +37,7 @@ static enum deny_action deny_current_branch = DENY_UNCONFIGURED;
 static enum deny_action deny_delete_current = DENY_UNCONFIGURED;
 static int receive_fsck_objects = -1;
 static int transfer_fsck_objects = -1;
+static struct strbuf fsck_msg_types = STRBUF_INIT;
 static int receive_unpack_limit = -1;
 static int transfer_unpack_limit = -1;
 static int advertise_atomic_push = 1;
@@ -115,6 +117,15 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if (skip_prefix(var, "receive.fsck.", &var)) {
+		if (is_valid_msg_type(var, value))
+			strbuf_addf(&fsck_msg_types, "%c%s=%s",
+				fsck_msg_types.len ? ',' : '=', var, value);
+		else
+			warning("Skipping unknown msg id '%s'", var);
+		return 0;
+	}
+
 	if (strcmp(var, "receive.fsckobjects") == 0) {
 		receive_fsck_objects = git_config_bool(var, value);
 		return 0;
@@ -1490,7 +1501,8 @@ static const char *unpack(int err_fd, struct shallow_info *si)
 		if (quiet)
 			argv_array_push(&child.args, "-q");
 		if (fsck_objects)
-			argv_array_push(&child.args, "--strict");
+			argv_array_pushf(&child.args, "--strict%s",
+				fsck_msg_types.buf);
 		child.no_stdout = 1;
 		child.err = err_fd;
 		child.git_cmd = 1;
@@ -1508,7 +1520,8 @@ static const char *unpack(int err_fd, struct shallow_info *si)
 		argv_array_pushl(&child.args, "index-pack",
 				 "--stdin", hdr_arg, keep_arg, NULL);
 		if (fsck_objects)
-			argv_array_push(&child.args, "--strict");
+			argv_array_pushf(&child.args, "--strict%s",
+				fsck_msg_types.buf);
 		if (fix_thin)
 			argv_array_push(&child.args, "--fix-thin");
 		child.out = -1;
builtin/unpack-objects.c +5 -0
index 6d17040..7cc086f 100644
@@ -530,6 +530,11 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
 				strict = 1;
 				continue;
 			}
+			if (skip_prefix(arg, "--strict=", &arg)) {
+				strict = 1;
+				fsck_set_msg_types(&fsck_options, arg);
+				continue;
+			}
 			if (starts_with(arg, "--pack_header=")) {
 				struct pack_header *hdr;
 				char *c;
fsck.c +8 -0
index 7db81d2..0c7cc26 100644
@@ -138,6 +138,14 @@ static int parse_msg_type(const char *str, int len)
 				len, str);
 }
 
+int is_valid_msg_type(const char *msg_id, const char *msg_type)
+{
+	if (parse_msg_id(msg_id, -1) < 0)
+		return 0;
+	parse_msg_type(msg_type, -1);
+	return 1;
+}
+
 void fsck_set_msg_type(struct fsck_options *options,
 		const char *msg_id, int msg_id_len,
 		const char *msg_type, int msg_type_len)
fsck.h +1 -0
index edb4540..738c9df 100644
@@ -10,6 +10,7 @@ void fsck_set_msg_type(struct fsck_options *options,
 		const char *msg_id, int msg_id_len,
 		const char *msg_type, int msg_type_len);
 void fsck_set_msg_types(struct fsck_options *options, const char *values);
+int is_valid_msg_type(const char *msg_id, const char *msg_type);
 
 /*
  * callback function for fsck_walk
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#162 lore raw

PATCH v5 6/19 fsck: Report the ID of the error/warning

In reply to Johannes Schindelin

Some legacy code has objects with non-fatal fsck issues; To enable the user to ignore those issues, let's print out the ID (e.g. when encountering "missingemail", the user might want to call git config --add receive.fsck.missingemail=warn).

---
 fsck.c          | 16 ++++++++++++++++
 t/t1450-fsck.sh |  4 ++--
 2 files changed, 18 insertions(+), 2 deletions(-)
fsck.c +16 -0
index 0c7cc26..47cb686 100644
@@ -190,6 +190,20 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
 	}
 }
 
+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));
+	}
+
+	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, ...)
@@ -198,6 +212,8 @@ static int report(struct fsck_options *options, struct object *object,
 	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);
t/t1450-fsck.sh +2 -2
index cfb32b6..286a643 100755
@@ -231,8 +231,8 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
 	git fsck --tags 2>out &&
 
 	cat >expect <<-EOF &&
-	warning in tag $tag: invalid '\''tag'\'' name: wrong name format
-	warning in tag $tag: invalid format - expected '\''tagger'\'' line
+	warning in tag $tag: invalidtagname: invalid '\''tag'\'' name: wrong name format
+	warning in tag $tag: missingtaggerentry: invalid format - expected '\''tagger'\'' line
 	EOF
 	test_cmp expect out
 '
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#163 lore raw

PATCH v5 7/19 fsck: Make fsck_ident() warn-friendly

In reply to Johannes Schindelin

When fsck_ident() identifies a problem with the ident, it should still advance the pointer to the next line so that fsck can continue in the case of a mere warning.

---
 fsck.c | 49 +++++++++++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 22 deletions(-)
fsck.c +27 -22
index 47cb686..8a1eea3 100644
@@ -479,40 +479,45 @@ static int require_end_of_header(const void *data, unsigned long size,
 
 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_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;
 }
 
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#164 lore raw

PATCH v5 8/19 fsck: Make fsck_commit() warn-friendly

In reply to Johannes Schindelin

When fsck_commit() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.

Note that some problems are too problematic to simply ignore. For example, when the header lines are mixed up, we punt after encountering an incorrect line. Therefore, demoting certain warnings to errors can hide other problems. Example: demoting the missingauthor error to a warning would hide a problematic committer line.

---
 fsck.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
fsck.c +20 -8
index 8a1eea3..31d218d 100644
@@ -534,12 +534,18 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 
 	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++;
 	}
@@ -548,11 +554,17 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 	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");
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#165 lore raw

PATCH v5 9/19 fsck: Handle multiple authors in commits specially

In reply to Johannes Schindelin

This problem has been detected in the wild, and is the primary reason to introduce an option to demote certain fsck errors to warnings. Let's offer to ignore this particular problem specifically.

Technically, we could handle such repositories by setting receive.fsck.<msg-id> to missingcommitter=warn, but that could hide missing tree objects in the same commit because we cannot continue verifying any commit object after encountering a missing committer line, while we can continue in the case of multiple author lines.

---
 fsck.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fsck.c +9 -0
index 31d218d..856221d 100644
@@ -38,6 +38,7 @@
 	FUNC(MISSING_TREE, ERROR) \
 	FUNC(MISSING_TYPE, ERROR) \
 	FUNC(MISSING_TYPE_ENTRY, ERROR) \
+	FUNC(MULTIPLE_AUTHORS, ERROR) \
 	FUNC(NOT_SORTED, ERROR) \
 	FUNC(NUL_IN_HEADER, ERROR) \
 	FUNC(TAG_OBJECT_NOT_TAG, ERROR) \
@@ -571,6 +572,14 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 	err = fsck_ident(&buffer, &commit->object, options);
 	if (err)
 		return err;
+	while (skip_prefix(buffer, "author ", &buffer)) {
+		err = report(options, &commit->object, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines");
+		if (err)
+			return err;
+		err = fsck_ident(&buffer, &commit->object, options);
+		if (err)
+			return err;
+	}
 	if (!skip_prefix(buffer, "committer ", &buffer))
 		return report(options, &commit->object, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line");
 	err = fsck_ident(&buffer, &commit->object, options);
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#166 lore raw

PATCH v5 10/19 fsck: Make fsck_tag() warn-friendly

In reply to Johannes Schindelin

When fsck_tag() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.

Just like fsck_commit(), there are certain problems that could hide other issues with the same tag object. For example, if the 'type' line is not encountered in the correct position, the 'tag' line – if there is any – would not be handled at all.

---
 fsck.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fsck.c +2 -1
index 856221d..bd4bfc2 100644
@@ -640,7 +640,8 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
 	}
 	if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
 		ret = report(options, &tag->object, FSCK_MSG_INVALID_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
-		goto done;
+		if (ret)
+			goto done;
 	}
 	buffer += 41;
 
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#167 lore raw

PATCH v5 11/19 fsck: Add a simple test for receive.fsck.<msg-id>

In reply to Johannes Schindelin
---
 t/t5504-fetch-receive-strict.sh | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
t/t5504-fetch-receive-strict.sh +21 -0
index 69ee13c..3f7e96a 100755
@@ -115,4 +115,25 @@ test_expect_success 'push with transfer.fsckobjects' '
 	test_cmp exp act
 '
 
+cat >bogus-commit <<\EOF
+tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
+author Bugs Bunny 1234567890 +0000
+committer Bugs Bunny <[email protected]> 1234567890 +0000
+
+This commit object intentionally broken
+EOF
+
+test_expect_success 'push with receive.fsck.missingemail=warn' '
+	commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
+	git push . $commit:refs/heads/bogus &&
+	rm -rf dst &&
+	git init dst &&
+	git --git-dir=dst/.git config receive.fsckobjects true &&
+	test_must_fail git push --porcelain dst bogus &&
+	git --git-dir=dst/.git config \
+		receive.fsck.missingemail warn &&
+	git push --porcelain dst bogus >act 2>&1 &&
+	grep "missingemail" act
+'
+
 test_done
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#168 lore raw

PATCH v5 12/19 fsck: Disallow demoting grave fsck errors to warnings

In reply to Johannes Schindelin

Some kinds of errors are intrinsically unrecoverable (e.g. errors while uncompressing objects). It does not make sense to allow demoting them to mere warnings.

---
 fsck.c                          | 14 ++++++++++++--
 t/t5504-fetch-receive-strict.sh | 11 +++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)
fsck.c +12 -2
index bd4bfc2..2b2a360 100644
@@ -9,7 +9,12 @@
 #include "refs.h"
 #include "utf8.h"
 
+#define FSCK_FATAL -1
+
 #define FOREACH_MSG_ID(FUNC) \
+	/* fatal errors */ \
+	FUNC(NUL_IN_HEADER, FATAL) \
+	FUNC(UNTERMINATED_HEADER, FATAL) \
 	/* errors */ \
 	FUNC(BAD_DATE, ERROR) \
 	FUNC(BAD_EMAIL, ERROR) \
@@ -40,10 +45,8 @@
 	FUNC(MISSING_TYPE_ENTRY, ERROR) \
 	FUNC(MULTIPLE_AUTHORS, ERROR) \
 	FUNC(NOT_SORTED, ERROR) \
-	FUNC(NUL_IN_HEADER, ERROR) \
 	FUNC(TAG_OBJECT_NOT_TAG, ERROR) \
 	FUNC(UNKNOWN_TYPE, ERROR) \
-	FUNC(UNTERMINATED_HEADER, ERROR) \
 	FUNC(ZERO_PADDED_DATE, ERROR) \
 	/* warnings */ \
 	FUNC(BAD_FILEMODE, WARN) \
@@ -157,6 +160,10 @@ void fsck_set_msg_type(struct fsck_options *options,
 		die("Unhandled message id: %.*s", msg_id_len, msg_id);
 	type = parse_msg_type(msg_type, msg_type_len);
 
+	if (type != FSCK_ERROR && msg_id_info[id].msg_type == FSCK_FATAL)
+		die("Cannot demote %.*s to %.*s", msg_id_len, msg_id,
+				msg_type_len, msg_type);
+
 	if (!options->msg_type) {
 		int i;
 		int *msg_type = xmalloc(sizeof(int) * FSCK_MSG_MAX);
@@ -213,6 +220,9 @@ static int report(struct fsck_options *options, struct object *object,
 	struct strbuf sb = STRBUF_INIT;
 	int msg_type = fsck_msg_type(id, options), result;
 
+	if (msg_type == FSCK_FATAL)
+		msg_type = FSCK_ERROR;
+
 	append_msg_id(&sb, msg_id_info[id].id_string);
 
 	va_start(ap, fmt);
t/t5504-fetch-receive-strict.sh +11 -0
index 3f7e96a..0d64229 100755
@@ -136,4 +136,15 @@ test_expect_success 'push with receive.fsck.missingemail=warn' '
 	grep "missingemail" act
 '
 
+test_expect_success \
+	'receive.fsck.unterminatedheader=warn triggers error' '
+	rm -rf dst &&
+	git init dst &&
+	git --git-dir=dst/.git config receive.fsckobjects true &&
+	git --git-dir=dst/.git config \
+		receive.fsck.unterminatedheader warn &&
+	test_must_fail git push --porcelain dst HEAD >act 2>&1 &&
+	grep "Cannot demote unterminatedheader" act
+'
+
 test_done
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#169 lore raw

PATCH v5 13/19 fsck: Optionally ignore specific fsck issues completely

In reply to Johannes Schindelin

An fsck issue in a legacy repository might be so common that one would like not to bother the user with mentioning it at all. With this change, that is possible by setting the respective message type to "ignore".

This change "abuses" the missingemail=warn test to verify that "ignore" is also accepted and works correctly. And while at it, it makes sure that multiple options work, too (they are passed to unpack-objects or index-pack as a comma-separated list via the --strict=... command-line option).

---
 fsck.c                          | 5 +++++
 fsck.h                          | 1 +
 t/t5504-fetch-receive-strict.sh | 9 ++++++++-
 3 files changed, 14 insertions(+), 1 deletion(-)
fsck.c +5 -0
index 2b2a360..0f7eb22 100644
@@ -137,6 +137,8 @@ static int parse_msg_type(const char *str, int len)
 		return FSCK_ERROR;
 	else if (!substrcmp(str, len, "warn"))
 		return FSCK_WARN;
+	else if (!substrcmp(str, len, "ignore"))
+		return FSCK_IGNORE;
 	else
 		die("Unknown fsck message type: '%.*s'",
 				len, str);
@@ -220,6 +222,9 @@ static int report(struct fsck_options *options, struct object *object,
 	struct strbuf sb = STRBUF_INIT;
 	int msg_type = fsck_msg_type(id, options), result;
 
+	if (msg_type == FSCK_IGNORE)
+		return 0;
+
 	if (msg_type == FSCK_FATAL)
 		msg_type = FSCK_ERROR;
 
fsck.h +1 -0
index 738c9df..7e49372 100644
@@ -3,6 +3,7 @@
 
 #define FSCK_ERROR 1
 #define FSCK_WARN 2
+#define FSCK_IGNORE 3
 
 struct fsck_options;
 
t/t5504-fetch-receive-strict.sh +8 -1
index 0d64229..cb077b7 100755
@@ -133,7 +133,14 @@ test_expect_success 'push with receive.fsck.missingemail=warn' '
 	git --git-dir=dst/.git config \
 		receive.fsck.missingemail warn &&
 	git push --porcelain dst bogus >act 2>&1 &&
-	grep "missingemail" act
+	grep "missingemail" act &&
+	git --git-dir=dst/.git branch -D bogus &&
+	git  --git-dir=dst/.git config --add \
+		receive.fsck.missingemail ignore &&
+	git  --git-dir=dst/.git config --add \
+		receive.fsck.baddate warn &&
+	git push --porcelain dst bogus >act 2>&1 &&
+	test_must_fail grep "missingemail" act
 '
 
 test_expect_success \
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#170 lore raw

PATCH v5 14/19 fsck: Allow upgrading fsck warnings to errors

In reply to Johannes Schindelin

The 'invalid tag name' and 'missing tagger entry' warnings can now be upgraded to errors by specifying invalidtagname and missingtaggerentry in the receive.fsck.<msg-id> config setting.

Incidentally, the missing tagger warning is now really shown as a warning (as opposed to being reported with the "error:" prefix, as it used to be the case before this commit).

---
 fsck.c                | 24 +++++++++++++++++-------
 t/t5302-pack-index.sh |  2 +-
 2 files changed, 18 insertions(+), 8 deletions(-)
fsck.c +17 -7
index 0f7eb22..a5e7dfb 100644
@@ -10,6 +10,7 @@
 #include "utf8.h"
 
 #define FSCK_FATAL -1
+#define FSCK_INFO -2
 
 #define FOREACH_MSG_ID(FUNC) \
 	/* fatal errors */ \
@@ -55,10 +56,11 @@
 	FUNC(HAS_DOT, WARN) \
 	FUNC(HAS_DOTDOT, WARN) \
 	FUNC(HAS_DOTGIT, WARN) \
-	FUNC(INVALID_TAG_NAME, WARN) \
-	FUNC(MISSING_TAGGER_ENTRY, WARN) \
 	FUNC(NULL_SHA1, WARN) \
-	FUNC(ZERO_PADDED_FILEMODE, WARN)
+	FUNC(ZERO_PADDED_FILEMODE, WARN) \
+	/* infos (reported as warnings, but ignored by default) */ \
+	FUNC(INVALID_TAG_NAME, INFO) \
+	FUNC(MISSING_TAGGER_ENTRY, INFO)
 
 #define MSG_ID(id, msg_type) FSCK_MSG_##id,
 enum fsck_msg_id {
@@ -227,6 +229,8 @@ static int report(struct fsck_options *options, struct object *object,
 
 	if (msg_type == FSCK_FATAL)
 		msg_type = FSCK_ERROR;
+	else if (msg_type == FSCK_INFO)
+		msg_type = FSCK_WARN;
 
 	append_msg_id(&sb, msg_id_info[id].id_string);
 
@@ -685,15 +689,21 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
 		goto done;
 	}
 	strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
-	if (check_refname_format(sb.buf, 0))
-		report(options, &tag->object, FSCK_MSG_INVALID_TAG_NAME,
+	if (check_refname_format(sb.buf, 0)) {
+		ret = report(options, &tag->object, FSCK_MSG_INVALID_TAG_NAME,
 			   "invalid 'tag' name: %.*s",
 			   (int)(eol - buffer), buffer);
+		if (ret)
+			goto done;
+	}
 	buffer = eol + 1;
 
-	if (!skip_prefix(buffer, "tagger ", &buffer))
+	if (!skip_prefix(buffer, "tagger ", &buffer)) {
 		/* early tags do not contain 'tagger' lines; warn only */
-		report(options, &tag->object, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
+		ret = report(options, &tag->object, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
+		if (ret)
+			goto done;
+	}
 	else
 		ret = fsck_ident(&buffer, &tag->object, options);
 
t/t5302-pack-index.sh +1 -1
index 61bc8da..3dc5ec4 100755
@@ -259,7 +259,7 @@ EOF
     thirtyeight=${tag#??} &&
     rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight &&
     git index-pack --strict tag-test-${pack1}.pack 2>err &&
-    grep "^error:.* expected .tagger. line" err
+    grep "^warning:.* expected .tagger. line" err
 '
 
 test_done
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#171 lore raw

PATCH v5 15/19 fsck: Document the new receive.fsck.<msg-id> options

In reply to Johannes Schindelin
---
 Documentation/config.txt | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/config.txt +14 -0
index 3e37b93..306ab7a 100644
@@ -2205,6 +2205,20 @@ receive.fsckObjects::
 	Defaults to false. If not set, the value of `transfer.fsckObjects`
 	is used instead.
 
+receive.fsck.<msg-id>::
+	When `receive.fsckObjects` is set to true, errors can be switched
+	to warnings and vice versa by configuring the `receive.fsck.<msg-id>`
+	setting where the `<msg-id>` is the fsck message ID and the value
+	is one of `error`, `warn` or `ignore`. For convenience, fsck prefixes
+	the error/warning with the message ID, e.g. "missingemail: invalid
+	author/committer line - missing email" means that setting
+	`receive.fsck.missingemail = ignore` will hide that issue.
++
+This feature is intended to support working with legacy repositories
+which would not pass pushing when `receive.fsckObjects = true`, allowing
+the host to accept repositories with certain known issues but still catch
+other issues.
+
 receive.unpackLimit::
 	If the number of objects received in a push is below this
 	limit then the objects will be unpacked into loose object
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#172 lore raw

PATCH v5 16/19 fsck: Support demoting errors to warnings

In reply to Johannes Schindelin

We already have support in git receive-pack to deal with some legacy repositories which have non-fatal issues.

Let's make git fsck itself useful with such repositories, too, by allowing users to ignore known issues, or at least demote those issues to mere warnings.

Example: git -c fsck.missingemail=ignore fsck would hide problems with missing emails in author, committer and tagger lines.

In the same spirit that git receive-pack's usage of the fsck machinery differs from git fsck's – some of the non-fatal warnings in git fsck are fatal with git receive-pack when receive.fsckObjects = true, for example – we strictly separate the fsck.<msg-id> from the receive.fsck.<msg-id> settings.

---
 Documentation/config.txt | 11 +++++++++++
 builtin/fsck.c           | 12 ++++++++++++
 t/t1450-fsck.sh          | 11 +++++++++++
 3 files changed, 34 insertions(+)
Documentation/config.txt +11 -0
index 306ab7a..41fd460 100644
@@ -1250,6 +1250,17 @@ filter.<driver>.smudge::
 	object to a worktree file upon checkout.  See
 	linkgit:gitattributes[5] for details.
 
+fsck.<msg-id>::
+	Allows overriding the message type (error, warn or ignore) of a
+	specific message ID such as `missingemail`.
++
+For convenience, fsck prefixes the error/warning with the message ID,
+e.g.  "missingemail: invalid author/committer line - missing email" means
+that setting `fsck.missingemail = ignore` will hide that issue.
++
+This feature is intended to support working with legacy repositories
+which cannot be repaired without disruptive changes.
+
 gc.aggressiveDepth::
 	The depth parameter used in the delta compression
 	algorithm used by 'git gc --aggressive'.  This defaults
builtin/fsck.c +12 -0
index fff38fe..6de9f3e 100644
@@ -46,6 +46,16 @@ static int show_dangling = 1;
 #define DIRENT_SORT_HINT(de) ((de)->d_ino)
 #endif
 
+static int fsck_config(const char *var, const char *value, void *cb)
+{
+	if (skip_prefix(var, "fsck.", &var)) {
+		fsck_set_msg_type(&fsck_obj_options, var, -1, value, -1);
+		return 0;
+	}
+
+	return git_default_config(var, value, cb);
+}
+
 static void objreport(struct object *obj, const char *msg_type,
 			const char *err)
 {
@@ -646,6 +656,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 		include_reflogs = 0;
 	}
 
+	git_config(fsck_config, NULL);
+
 	fsck_head_link();
 	fsck_object_dir(get_object_directory());
 
t/t1450-fsck.sh +11 -0
index 286a643..fe4bb03 100755
@@ -287,6 +287,17 @@ test_expect_success 'rev-list --verify-objects with bad sha1' '
 	grep -q "error: sha1 mismatch 63ffffffffffffffffffffffffffffffffffffff" out
 '
 
+test_expect_success 'force fsck to ignore double author' '
+	git cat-file commit HEAD >basis &&
+	sed "s/^author .*/&,&/" <basis | tr , \\n >multiple-authors &&
+	new=$(git hash-object -t commit -w --stdin <multiple-authors) &&
+	test_when_finished "remove_object $new" &&
+	git update-ref refs/heads/bogus "$new" &&
+	test_when_finished "git update-ref -d refs/heads/bogus" &&
+	test_must_fail git fsck &&
+	git -c fsck.multipleauthors=ignore fsck
+'
+
 _bz='\0'
 _bz5="$_bz$_bz$_bz$_bz$_bz"
 _bz20="$_bz5$_bz5$_bz5$_bz5"
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#173 lore raw

PATCH v5 17/19 fsck: Introduce `git fsck --quick`

In reply to Johannes Schindelin

This option avoids unpacking each and all objects, and just verifies the connectivity. In particular with large repositories, this speeds up the operation, at the expense of missing corrupt blobs and ignoring unreachable objects, if any.

---
 Documentation/git-fsck.txt |  7 ++++++-
 builtin/fsck.c             |  7 ++++++-
 t/t1450-fsck.sh            | 22 ++++++++++++++++++++++
 3 files changed, 34 insertions(+), 2 deletions(-)
Documentation/git-fsck.txt +6 -1
index 25c431d..b98fb43 100644
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
-	 [--[no-]full] [--strict] [--verbose] [--lost-found]
+	 [--[no-]full] [--quick] [--strict] [--verbose] [--lost-found]
 	 [--[no-]dangling] [--[no-]progress] [<object>*]
 
 DESCRIPTION
@@ -60,6 +60,11 @@ index file, all SHA-1 references in `refs` namespace, and all reflogs
 	object pools.  This is now default; you can turn it off
 	with --no-full.
 
+--quick::
+	Check only the connectivity of tags, commits and tree objects. By
+	avoiding to unpack blobs, this speeds up the operation, at the
+	expense of missing corrupt objects.
+
 --strict::
 	Enable more strict checking, namely to catch a file mode
 	recorded with g+w bit set, which was created by older
builtin/fsck.c +6 -1
index 6de9f3e..75fcb5f 100644
@@ -23,6 +23,7 @@ static int show_tags;
 static int show_unreachable;
 static int include_reflogs = 1;
 static int check_full = 1;
+static int quick;
 static int check_strict;
 static int keep_cache_objects;
 static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT;
@@ -181,6 +182,8 @@ static void check_reachable_object(struct object *obj)
 	if (!(obj->flags & HAS_OBJ)) {
 		if (has_sha1_pack(obj->sha1))
 			return; /* it is in pack - forget about it */
+		if (quick && has_sha1_file(obj->sha1))
+			return;
 		printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1));
 		errors_found |= ERROR_REACHABLE;
 		return;
@@ -623,6 +626,7 @@ static struct option fsck_opts[] = {
 	OPT_BOOL(0, "cache", &keep_cache_objects, N_("make index objects head nodes")),
 	OPT_BOOL(0, "reflogs", &include_reflogs, N_("make reflogs head nodes (default)")),
 	OPT_BOOL(0, "full", &check_full, N_("also consider packs and alternate objects")),
+	OPT_BOOL(0, "quick", &quick, N_("check only connectivity")),
 	OPT_BOOL(0, "strict", &check_strict, N_("enable more strict checking")),
 	OPT_BOOL(0, "lost-found", &write_lost_and_found,
 				N_("write dangling objects in .git/lost-found")),
@@ -659,7 +663,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 	git_config(fsck_config, NULL);
 
 	fsck_head_link();
-	fsck_object_dir(get_object_directory());
+	if (!quick)
+		fsck_object_dir(get_object_directory());
 
 	prepare_alt_odb();
 	for (alt = alt_odb_list; alt; alt = alt->next) {
t/t1450-fsck.sh +22 -0
index fe4bb03..471e2ea 100755
@@ -431,4 +431,26 @@ test_expect_success 'fsck notices ref pointing to missing tag' '
 	test_must_fail git -C missing fsck
 '
 
+test_expect_success 'fsck --quick' '
+	rm -rf quick &&
+	git init quick &&
+	(
+		cd quick &&
+		touch empty &&
+		git add empty &&
+		test_commit empty &&
+		empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 &&
+		rm -f $empty &&
+		echo invalid >$empty &&
+		test_must_fail git fsck --strict &&
+		git fsck --strict --quick &&
+		tree=$(git rev-parse HEAD:) &&
+		suffix=${tree#??} &&
+		tree=.git/objects/${tree%$suffix}/$suffix &&
+		rm -f $tree &&
+		echo invalid >$tree &&
+		test_must_fail git fsck --strict --quick
+	)
+'
+
 test_done
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#174 lore raw

PATCH v5 18/19 fsck: git receive-pack: support excluding objects from fsck'ing

In reply to Johannes Schindelin

The optional new config option receive.fsck.skiplist specifies the path to a file listing the names, i.e. SHA-1s, one per line, of objects that are to be ignored by git receive-pack when receive.fsckObjects = true.

This is extremely handy in case of legacy repositories where it would cause more pain to change incorrect objects than to live with them (e.g. a duplicate 'author' line in an early commit object).

The intended use case is for server administrators to inspect objects that are reported by git push as being too problematic to enter the repository, and to add the objects' SHA-1 to a (preferably sorted) file when the objects are legitimate, i.e. when it is determined that those problematic objects should be allowed to enter the server.

---
 Documentation/config.txt        |  7 ++++++
 builtin/receive-pack.c          |  8 ++++++
 fsck.c                          | 54 +++++++++++++++++++++++++++++++++++++++++
 fsck.h                          |  1 +
 t/t5504-fetch-receive-strict.sh | 12 +++++++++
 5 files changed, 82 insertions(+)
Documentation/config.txt +7 -0
index 41fd460..5f45115 100644
@@ -2230,6 +2230,13 @@ which would not pass pushing when `receive.fsckObjects = true`, allowing
 the host to accept repositories with certain known issues but still catch
 other issues.
 
+receive.fsck.skipList::
+	The path to a sorted list of object names (i.e. one SHA-1 per
+	line) that are known to be broken in a non-fatal way and should
+	be ignored. This feature is useful when an established project
+	should be accepted despite early commits containing errors that
+	can be safely ignored such as invalid committer email addresses.
+
 receive.unpackLimit::
 	If the number of objects received in a push is below this
 	limit then the objects will be unpacked into loose object
builtin/receive-pack.c +8 -0
index 3afe8f8..80574f9 100644
@@ -117,6 +117,14 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if (strcmp(var, "receive.fsck.skiplist") == 0) {
+		const char *path = is_absolute_path(value) ?
+			value : git_path("%s", value);
+		strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
+			fsck_msg_types.len ? ',' : '=', path);
+		return 0;
+	}
+
 	if (skip_prefix(var, "receive.fsck.", &var)) {
 		if (is_valid_msg_type(var, value))
 			strbuf_addf(&fsck_msg_types, "%c%s=%s",
fsck.c +54 -0

78 lines not on this page · raw message

fsck.h +1 -0
index 7e49372..cab9c65 100644
@@ -33,6 +33,7 @@ struct fsck_options {
 	fsck_error error_func;
 	unsigned strict:1;
 	int *msg_type;
+	struct sha1_array *skiplist;
 };
 
 #define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL }
t/t5504-fetch-receive-strict.sh +12 -0
index cb077b7..1ada54c 100755
@@ -123,6 +123,18 @@ committer Bugs Bunny <[email protected]> 1234567890 +0000
 This commit object intentionally broken
 EOF
 
+test_expect_success 'push with receive.fsck.skiplist' '
+	commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
+	git push . $commit:refs/heads/bogus &&
+	rm -rf dst &&
+	git init dst &&
+	git --git-dir=dst/.git config receive.fsckobjects true &&
+	test_must_fail git push --porcelain dst bogus &&
+	git --git-dir=dst/.git config receive.fsck.skiplist SKIP &&
+	echo $commit >dst/.git/SKIP &&
+	git push --porcelain dst bogus
+'
+
 test_expect_success 'push with receive.fsck.missingemail=warn' '
 	commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
 	git push . $commit:refs/heads/bogus &&
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#175 lore raw

PATCH v5 19/19 fsck: support ignoring objects in `git fsck` via fsck.skiplist

In reply to Johannes Schindelin

Identical to support in git receive-pack for the config option receive.fsck.skiplist, we now support ignoring given objects in git fsck via fsck.skiplist` altogether.

This is extremely handy in case of legacy repositories where it would cause more pain to change incorrect objects than to live with them (e.g. a duplicate 'author' line in an early commit object).

---
 Documentation/config.txt |  7 +++++++
 builtin/fsck.c           | 10 ++++++++++
 2 files changed, 17 insertions(+)
Documentation/config.txt +7 -0
index 5f45115..5aba63a 100644
@@ -1261,6 +1261,13 @@ that setting `fsck.missingemail = ignore` will hide that issue.
 This feature is intended to support working with legacy repositories
 which cannot be repaired without disruptive changes.
 
+fsck.skipList::
+	The path to a sorted list of object names (i.e. one SHA-1 per
+	line) that are known to be broken in a non-fatal way and should
+	be ignored. This feature is useful when an established project
+	should be accepted despite early commits containing errors that
+	can be safely ignored such as invalid committer email addresses.
+
 gc.aggressiveDepth::
 	The depth parameter used in the delta compression
 	algorithm used by 'git gc --aggressive'.  This defaults
builtin/fsck.c +10 -0
index 75fcb5f..ce538ac 100644
@@ -54,6 +54,16 @@ static int fsck_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if (strcmp(var, "fsck.skiplist") == 0) {
+		const char *path = is_absolute_path(value) ?
+			value : git_path("%s", value);
+		struct strbuf sb = STRBUF_INIT;
+		strbuf_addf(&sb, "skiplist=%s", path);
+		fsck_set_msg_types(&fsck_obj_options, sb.buf);
+		strbuf_release(&sb);
+		return 0;
+	}
+
 	return git_default_config(var, value, cb);
 }
 
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#176 lore raw
In reply to Johannes Schindelin
Quoted 10 lines · Johannes Schindelin

At the moment, the git-fsck's integrity checks are targeted toward the end user, i.e. the error messages are really just messages, intended for human consumption.

Under certain circumstances, some of those errors should be allowed to be turned into mere warnings, though, because the cost of fixing the issues might well be larger than the cost of carrying those flawed objects.

Interdiff below the diffstat. It's huge. Sorry.

Heh, no need to say sorry, though. A large interdiff means you did a lot more work, after all.

I haven't had a chance to go through the all the patches, but one thing I noticed that did not appear in the interdiff is that some of the message IDs are unclear. For example, there are BAD_something, INVALID_something and MISSING_something. The last one is in a different category and is good, but how are the former two differenciated? Do they follow some systematic rules, or they are named after the way how they happened to be reported in the original textual error message?

Some of the questionable groups are:

BAD_DATE DATE_OVERFLOW

BAD_TREE_SHA1 INVALID_OBJECT_SHA1 INVALID_TREE

BAD_PARENT_SHA1 INVALID_OBJECT_SHA1

Also it is unclear if NOT_SORTED is to be used ever for any error other than a tree object sorted incorrectly, or if we start noticing a new error that something is not sorted, we will reuse this one.

I also briefly wondered if fsck.skipList should be finer grained than "these are know to be broken, do not bother reporting problems with them" (e.g. I know v0.99 lacks "tagger" so I want to squelch MISSING_TAGGER_ENTRY for it, but I want to be notified on any other errors). But that only matters if we update Git to a version with a new fsck that knows yet more kinds of breakages, so it is not a huge issue, and the simplicity of "be silent on these objects" is probably better overall.

Thanks.

#177 lore raw

Hi Junio,

Quoted 8 lines · Junio C Hamano

I haven't had a chance to go through the all the patches, but one thing I noticed that did not appear in the interdiff is that some of the message IDs are unclear. For example, there are BAD_something, INVALID_something and MISSING_something. The last one is in a different category and is good, but how are the former two differenciated? Do they follow some systematic rules, or they are named after the way how they happened to be reported in the original textual error message?

I basically made up names on the go, based on the messages.

Quoted 3 lines

Some of the questionable groups are:

BAD_DATE DATE_OVERFLOW

I guess it should be BAD_DATE_OVERFLOW to be more consistent?

Quoted 3 lines

BAD_TREE_SHA1 INVALID_OBJECT_SHA1 INVALID_TREE

BAD_PARENT_SHA1 INVALID_OBJECT_SHA1

So how about s/INVALID_/BAD_/g?

Quoted 3 lines

Also it is unclear if NOT_SORTED is to be used ever for any error other than a tree object sorted incorrectly, or if we start noticing a new error that something is not sorted, we will reuse this one.

s/NOT_SORTED/TREE_&/ maybe?

Quoted 8 lines

I also briefly wondered if fsck.skipList should be finer grained than "these are know to be broken, do not bother reporting problems with them" (e.g. I know v0.99 lacks "tagger" so I want to squelch MISSING_TAGGER_ENTRY for it, but I want to be notified on any other errors). But that only matters if we update Git to a version with a new fsck that knows yet more kinds of breakages, so it is not a huge issue, and the simplicity of "be silent on these objects" is probably better overall.

Well, the idea of skiplist is to say: "I have inspected this object and determined that errors in it should be ignored." As such, it does not really matter what problems future Git versions report because the person populating the skiplist is supposed to test thoroughly, not just asking git fsck what is going on.

And yes, the motivation for this feature is to keep it super-simple. ;-)

Ciao,
Dscho

#178 lore raw
Quoted 7 lines · Johannes Schindelin

I basically made up names on the go, based on the messages.

Quoted 3 lines

Some of the questionable groups are:

BAD_DATE DATE_OVERFLOW

I guess it should be BAD_DATE_OVERFLOW to be more consistent?

I am not sure about "consistency", but surely a common prefix would help readers to group things. But for this particular group, I was wondering if singling out "integer overflow", "zero stuffed timestamp", etc. into such a finer sub-errors of "you have a bad timestamp" was beneficial.

Quoted 5 lines
Quoted 3 lines

BAD_TREE_SHA1 INVALID_OBJECT_SHA1 INVALID_TREE

BAD_PARENT_SHA1 INVALID_OBJECT_SHA1

So how about s/INVALID_/BAD_/g?

It is not just about distinction between INVAID and BAD.

I was basically wondering what rule decides which one among BAD_TREE_SHA1, INVALID_OBJECT_SHA1 and INVALID_TREE I would get when I have a random non-hexdigit string in various places, e.g. after 'tree ' in the object header of a commit object, after 'tag ' in a tag object that says 'type tree', etc.

Quoted 5 lines
Quoted 3 lines

Also it is unclear if NOT_SORTED is to be used ever for any error other than a tree object sorted incorrectly, or if we start noticing a new error that something is not sorted, we will reuse this one.

s/NOT_SORTED/TREE_&/ maybe?

If that error is specific to tree sorting order, then that would be a definite improvement.

Thanks.

#179 lore raw

Hi Junio,

first of all: the improvements discussed here are already part of v6.

Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Johannes Schindelin

I basically made up names on the go, based on the messages.

Quoted 3 lines

Some of the questionable groups are:

BAD_DATE DATE_OVERFLOW

Quoted 7 lines
Quoted 1 line

I guess it should be BAD_DATE_OVERFLOW to be more consistent?

I am not sure about "consistency", but surely a common prefix would help readers to group things. But for this particular group, I was wondering if singling out "integer overflow", "zero stuffed timestamp", etc. into such a finer sub-errors of "you have a bad timestamp" was beneficial.

Well, someone thought it a good idea to print different error messages, and I took that as an indicator that there is merit in being able to distinguish these issues from one another.

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

BAD_TREE_SHA1 INVALID_OBJECT_SHA1 INVALID_TREE

BAD_PARENT_SHA1 INVALID_OBJECT_SHA1

So how about s/INVALID_/BAD_/g?

Quoted 7 lines

It is not just about distinction between INVAID and BAD.

I was basically wondering what rule decides which one among BAD_TREE_SHA1, INVALID_OBJECT_SHA1 and INVALID_TREE I would get when I have a random non-hexdigit string in various places, e.g. after 'tree ' in the object header of a commit object, after 'tag ' in a tag object that says 'type tree', etc.

To be honest, I think the IDs do not really matter as much as your comment makes it sound: the IDs purpose is solely to be able to configure the message type (read: whether to error out, warn or ignore the issue). The real information is in the actual message (and I did not change any message, therefore I could not make things worse than they are right now).

Example: you would never read BAD_TREE_SHA1, but instead: "badtreesha1: invalid 'tree' line format - bad sha1".

For BAD_OBJECT_SHA1 (as it is now called), there are actually two code paths generating the error: "invalid 'object' line format - bad sha1" and "no valid object to fsck".

And for BAD_TREE it is: "could not load commit's tree <SHA1>".

Thus, from the error message it should be really clear what is going on.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Also it is unclear if NOT_SORTED is to be used ever for any error other than a tree object sorted incorrectly, or if we start noticing a new error that something is not sorted, we will reuse this one.

s/NOT_SORTED/TREE_&/ maybe?

If that error is specific to tree sorting order, then that would be a definite improvement.

Yes, that is the case. Tree objects are assumed to list their contents in order, and this ID applies to the problem where a tree object's list is out of order.

As I said, I already made both discussed changes part of v6.

Ciao,
Dscho

#180 lore raw

v6 cover Introduce an internal API to interact with the fsck machinery

In reply to Johannes Schindelin

At the moment, the git-fsck's integrity checks are targeted toward the end user, i.e. the error messages are really just messages, intended for human consumption.

Under certain circumstances, some of those errors should be allowed to be turned into mere warnings, though, because the cost of fixing the issues might well be larger than the cost of carrying those flawed objects. For example, when an already-public repository contains a commit object with two authors for years, it does not make sense to force the maintainer to rewrite the history, affecting all contributors negatively by forcing them to update.

This branch introduces an internal fsck API to be able to turn some of the errors into warnings, and to make it easier to call the fsck machinery from elsewhere in general.

I am proud to report that this work has been sponsored by GitHub.

Changes since v5:

- The BAD_* names have been renamed to INVALID_* names

Interdiff below the diffstat.

Johannes Schindelin (19):
fsck: Introduce fsck options
fsck: Introduce identifiers for fsck messages
fsck: Provide a function to parse fsck message IDs
fsck: Offer a function to demote fsck errors to warnings fsck (receive-pack): Allow demoting errors to warnings
fsck: Report the ID of the error/warning
fsck: Make fsck_ident() warn-friendly
fsck: Make fsck_commit() warn-friendly
fsck: Handle multiple authors in commits specially
fsck: Make fsck_tag() warn-friendly
fsck: Add a simple test for receive.fsck.<msg-id>
fsck: Disallow demoting grave fsck errors to warnings
fsck: Optionally ignore specific fsck issues completely
fsck: Allow upgrading fsck warnings to errors
fsck: Document the new receive.fsck.<msg-id> options
fsck: Support demoting errors to warnings
fsck: Introduce git fsck --quick
fsck: git receive-pack: support excluding objects from fsck'ing
fsck: support ignoring objects in git fsck via fsck.skiplist

 Documentation/config.txt        |  39 +++
 Documentation/git-fsck.txt      |   7 +-
 builtin/fsck.c                  |  75 ++++--
 builtin/index-pack.c            |  13 +-
 builtin/receive-pack.c          |  25 +-
 builtin/unpack-objects.c        |  16 +-
 fsck.c                          | 553 +++++++++++++++++++++++++++++++---------
 fsck.h                          |  31 ++-
 t/t1450-fsck.sh                 |  37 ++-
 t/t5302-pack-index.sh           |   2 +-
 t/t5504-fetch-receive-strict.sh |  51 ++++
 11 files changed, 686 insertions(+), 163 deletions(-)
fsck.c +15 -15
index 9b8981e..f80b508 100644
@@ -19,17 +19,17 @@
 	FUNC(UNTERMINATED_HEADER, FATAL) \
 	/* errors */ \
 	FUNC(BAD_DATE, ERROR) \
+	FUNC(BAD_DATE_OVERFLOW, ERROR) \
 	FUNC(BAD_EMAIL, ERROR) \
 	FUNC(BAD_NAME, ERROR) \
+	FUNC(BAD_OBJECT_SHA1, ERROR) \
 	FUNC(BAD_PARENT_SHA1, ERROR) \
+	FUNC(BAD_TAG_OBJECT, ERROR) \
 	FUNC(BAD_TIMEZONE, ERROR) \
+	FUNC(BAD_TREE, ERROR) \
 	FUNC(BAD_TREE_SHA1, ERROR) \
-	FUNC(DATE_OVERFLOW, ERROR) \
+	FUNC(BAD_TYPE, ERROR) \
 	FUNC(DUPLICATE_ENTRIES, ERROR) \
-	FUNC(INVALID_OBJECT_SHA1, ERROR) \
-	FUNC(INVALID_TAG_OBJECT, ERROR) \
-	FUNC(INVALID_TREE, ERROR) \
-	FUNC(INVALID_TYPE, ERROR) \
 	FUNC(MISSING_AUTHOR, ERROR) \
 	FUNC(MISSING_COMMITTER, ERROR) \
 	FUNC(MISSING_EMAIL, ERROR) \
@@ -46,8 +46,8 @@
 	FUNC(MISSING_TYPE, ERROR) \
 	FUNC(MISSING_TYPE_ENTRY, ERROR) \
 	FUNC(MULTIPLE_AUTHORS, ERROR) \
-	FUNC(NOT_SORTED, ERROR) \
 	FUNC(TAG_OBJECT_NOT_TAG, ERROR) \
+	FUNC(TREE_NOT_SORTED, ERROR) \
 	FUNC(UNKNOWN_TYPE, ERROR) \
 	FUNC(ZERO_PADDED_DATE, ERROR) \
 	/* warnings */ \
@@ -60,7 +60,7 @@
 	FUNC(NULL_SHA1, WARN) \
 	FUNC(ZERO_PADDED_FILEMODE, WARN) \
 	/* infos (reported as warnings, but ignored by default) */ \
-	FUNC(INVALID_TAG_NAME, INFO) \
+	FUNC(BAD_TAG_NAME, INFO) \
 	FUNC(MISSING_TAGGER_ENTRY, INFO)
 
 #define MSG_ID(id, msg_type) FSCK_MSG_##id,
@@ -525,7 +525,7 @@ static int fsck_tree(struct tree *item, struct fsck_options *options)
 	if (has_dup_entries)
 		retval += report(options, &item->object, FSCK_MSG_DUPLICATE_ENTRIES, "contains duplicate file entries");
 	if (not_properly_sorted)
-		retval += report(options, &item->object, FSCK_MSG_NOT_SORTED, "not properly sorted");
+		retval += report(options, &item->object, FSCK_MSG_TREE_NOT_SORTED, "not properly sorted");
 	return retval;
 }
 
@@ -580,7 +580,7 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option
 	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(p, &end, 10)))
-		return report(options, obj, FSCK_MSG_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
+		return report(options, obj, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
 	if ((end == p || *end != ' '))
 		return report(options, obj, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
 	p = end + 1;
@@ -659,7 +659,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 	if (err)
 		return err;
 	if (!commit->tree)
-		return report(options, &commit->object, FSCK_MSG_INVALID_TREE, "could not load commit's tree %s", sha1_to_hex(tree_sha1));
+		return report(options, &commit->object, FSCK_MSG_BAD_TREE, "could not load commit's tree %s", sha1_to_hex(tree_sha1));
 
 	return 0;
 }
@@ -712,7 +712,7 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
 		goto done;
 	}
 	if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
-		ret = report(options, &tag->object, FSCK_MSG_INVALID_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
+		ret = report(options, &tag->object, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
 		if (ret)
 			goto done;
 	}
@@ -728,7 +728,7 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
 		goto done;
 	}
 	if (type_from_string_gently(buffer, eol - buffer, 1) < 0)
-		ret = report(options, &tag->object, FSCK_MSG_INVALID_TYPE, "invalid 'type' value");
+		ret = report(options, &tag->object, FSCK_MSG_BAD_TYPE, "invalid 'type' value");
 	if (ret)
 		goto done;
 	buffer = eol + 1;
@@ -744,7 +744,7 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
 	}
 	strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
 	if (check_refname_format(sb.buf, 0)) {
-		ret = report(options, &tag->object, FSCK_MSG_INVALID_TAG_NAME,
+		ret = report(options, &tag->object, FSCK_MSG_BAD_TAG_NAME,
 			   "invalid 'tag' name: %.*s",
 			   (int)(eol - buffer), buffer);
 		if (ret)
@@ -773,7 +773,7 @@ static int fsck_tag(struct tag *tag, const char *data,
 	struct object *tagged = tag->tagged;
 
 	if (!tagged)
-		return report(options, &tag->object, FSCK_MSG_INVALID_TAG_OBJECT, "could not load tagged object");
+		return report(options, &tag->object, FSCK_MSG_BAD_TAG_OBJECT, "could not load tagged object");
 
 	return fsck_tag_buffer(tag, data, size, options);
 }
@@ -782,7 +782,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
 	struct fsck_options *options)
 {
 	if (!obj)
-		return report(options, obj, FSCK_MSG_INVALID_OBJECT_SHA1, "no valid object to fsck");
+		return report(options, obj, FSCK_MSG_BAD_OBJECT_SHA1, "no valid object to fsck");
 
 	if (obj->type == OBJ_BLOB)
 		return 0;
t/t1450-fsck.sh +1 -1
index 471e2ea..2863a8a 100755
@@ -231,7 +231,7 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
 	git fsck --tags 2>out &&
 
 	cat >expect <<-EOF &&
-	warning in tag $tag: invalidtagname: invalid '\''tag'\'' name: wrong name format
+	warning in tag $tag: badtagname: invalid '\''tag'\'' name: wrong name format
 	warning in tag $tag: missingtaggerentry: invalid format - expected '\''tagger'\'' line
 	EOF
 	test_cmp expect out
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#181 lore raw

PATCH v6 1/19 fsck: Introduce fsck options

Just like the diff machinery, we are about to introduce more settings, therefore it makes sense to carry them around as a (pointer to a) struct containing all of them.

---
 builtin/fsck.c           |  20 +++++--
 builtin/index-pack.c     |   9 +--
 builtin/unpack-objects.c |  11 ++--
 fsck.c                   | 150 +++++++++++++++++++++++------------------------
 fsck.h                   |  17 +++++-
 5 files changed, 114 insertions(+), 93 deletions(-)
builtin/fsck.c +14 -6
index 2679793..981dca5 100644
@@ -25,6 +25,8 @@ static int include_reflogs = 1;
 static int check_full = 1;
 static int check_strict;
 static int keep_cache_objects;
+static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT;
+static struct fsck_options fsck_obj_options = FSCK_OPTIONS_DEFAULT;
 static struct object_id head_oid;
 static const char *head_points_at;
 static int errors_found;
@@ -76,7 +78,7 @@ static int fsck_error_func(struct object *obj, int type, const char *err, ...)
 
 static struct object_array pending;
 
-static int mark_object(struct object *obj, int type, void *data)
+static int mark_object(struct object *obj, int type, void *data, struct fsck_options *options)
 {
 	struct object *parent = data;
 
@@ -119,7 +121,7 @@ static int mark_object(struct object *obj, int type, void *data)
 
 static void mark_object_reachable(struct object *obj)
 {
-	mark_object(obj, OBJ_ANY, NULL);
+	mark_object(obj, OBJ_ANY, NULL, NULL);
 }
 
 static int traverse_one_object(struct object *obj)
@@ -132,7 +134,7 @@ static int traverse_one_object(struct object *obj)
 		if (parse_tree(tree) < 0)
 			return 1; /* error already displayed */
 	}
-	result = fsck_walk(obj, mark_object, obj);
+	result = fsck_walk(obj, obj, &fsck_walk_options);
 	if (tree)
 		free_tree_buffer(tree);
 	return result;
@@ -158,7 +160,7 @@ static int traverse_reachable(void)
 	return !!result;
 }
 
-static int mark_used(struct object *obj, int type, void *data)
+static int mark_used(struct object *obj, int type, void *data, struct fsck_options *options)
 {
 	if (!obj)
 		return 1;
@@ -296,9 +298,9 @@ static int fsck_obj(struct object *obj)
 		fprintf(stderr, "Checking %s %s\n",
 			typename(obj->type), sha1_to_hex(obj->sha1));
 
-	if (fsck_walk(obj, mark_used, NULL))
+	if (fsck_walk(obj, NULL, &fsck_obj_options))
 		objerror(obj, "broken links");
-	if (fsck_object(obj, NULL, 0, check_strict, fsck_error_func))
+	if (fsck_object(obj, NULL, 0, &fsck_obj_options))
 		return -1;
 
 	if (obj->type == OBJ_TREE) {
@@ -638,6 +640,12 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 
 	argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
 
+	fsck_walk_options.walk = mark_object;
+	fsck_obj_options.walk = mark_used;
+	fsck_obj_options.error_func = fsck_error_func;
+	if (check_strict)
+		fsck_obj_options.strict = 1;
+
 	if (show_progress == -1)
 		show_progress = isatty(2);
 	if (verbose)
builtin/index-pack.c +5 -4
index 48fa472..87ae9ba 100644
@@ -75,6 +75,7 @@ static int nr_threads;
 static int from_stdin;
 static int strict;
 static int do_fsck_object;
+static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
 static int verbose;
 static int show_stat;
 static int check_self_contained_and_connected;
@@ -192,7 +193,7 @@ static void cleanup_thread(void)
 #endif
 
 
-static int mark_link(struct object *obj, int type, void *data)
+static int mark_link(struct object *obj, int type, void *data, struct fsck_options *options)
 {
 	if (!obj)
 		return -1;
@@ -838,10 +839,10 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 			if (!obj)
 				die(_("invalid %s"), typename(type));
 			if (do_fsck_object &&
-			    fsck_object(obj, buf, size, 1,
-				    fsck_error_function))
+			    fsck_object(obj, buf, size, &fsck_options))
 				die(_("Error in object"));
-			if (fsck_walk(obj, mark_link, NULL))
+			fsck_options.walk = mark_link;
+			if (fsck_walk(obj, NULL, &fsck_options))
 				die(_("Not all child objects of %s are reachable"), sha1_to_hex(obj->sha1));
 
 			if (obj->type == OBJ_TREE) {
builtin/unpack-objects.c +6 -5
index ac66672..6d17040 100644
@@ -20,6 +20,7 @@ static unsigned char buffer[4096];
 static unsigned int offset, len;
 static off_t consumed_bytes;
 static git_SHA_CTX ctx;
+static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
 
 /*
  * When running under --strict mode, objects whose reachability are
@@ -178,7 +179,7 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
  * that have reachability requirements and calls this function.
  * Verify its reachability and validity recursively and write it out.
  */
-static int check_object(struct object *obj, int type, void *data)
+static int check_object(struct object *obj, int type, void *data, struct fsck_options *options)
 {
 	struct obj_buffer *obj_buf;
 
@@ -203,10 +204,10 @@ static int check_object(struct object *obj, int type, void *data)
 	obj_buf = lookup_object_buffer(obj);
 	if (!obj_buf)
 		die("Whoops! Cannot find object '%s'", sha1_to_hex(obj->sha1));
-	if (fsck_object(obj, obj_buf->buffer, obj_buf->size, 1,
-			fsck_error_function))
+	if (fsck_object(obj, obj_buf->buffer, obj_buf->size, &fsck_options))
 		die("Error in object");
-	if (fsck_walk(obj, check_object, NULL))
+	fsck_options.walk = check_object;
+	if (fsck_walk(obj, NULL, &fsck_options))
 		die("Error on reachable objects of %s", sha1_to_hex(obj->sha1));
 	write_cached_object(obj, obj_buf);
 	return 0;
@@ -217,7 +218,7 @@ static void write_rest(void)
 	unsigned i;
 	for (i = 0; i < nr_objects; i++) {
 		if (obj_list[i].obj)
-			check_object(obj_list[i].obj, OBJ_ANY, NULL);
+			check_object(obj_list[i].obj, OBJ_ANY, NULL, NULL);
 	}
 }
 
fsck.c +75 -75

392 lines not on this page · raw message

fsck.h +14 -3
index d1e6387..07d0ab2 100644
@@ -4,6 +4,8 @@
 #define FSCK_ERROR 1
 #define FSCK_WARN 2
 
+struct fsck_options;
+
 /*
  * callback function for fsck_walk
  * type is the expected type of the object or OBJ_ANY
@@ -12,7 +14,7 @@
  *     <0	error signaled and abort
  *     >0	error signaled and do not abort
  */
-typedef int (*fsck_walk_func)(struct object *obj, int type, void *data);
+typedef int (*fsck_walk_func)(struct object *obj, int type, void *data, struct fsck_options *options);
 
 /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
 typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...);
@@ -20,6 +22,15 @@ typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...);
 __attribute__((format (printf, 3, 4)))
 int fsck_error_function(struct object *obj, int type, const char *fmt, ...);
 
+struct fsck_options {
+	fsck_walk_func walk;
+	fsck_error error_func;
+	unsigned strict:1;
+};
+
+#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0 }
+#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1 }
+
 /* descend in all linked child objects
  * the return value is:
  *    -1	error in processing the object
@@ -27,9 +38,9 @@ int fsck_error_function(struct object *obj, int type, const char *fmt, ...);
  *    >0	return value of the first signaled error >0 (in the case of no other errors)
  *    0		everything OK
  */
-int fsck_walk(struct object *obj, fsck_walk_func walk, void *data);
+int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
 /* If NULL is passed for data, we assume the object is local and read it. */
 int fsck_object(struct object *obj, void *data, unsigned long size,
-	int strict, fsck_error error_func);
+	struct fsck_options *options);
 
 #endif
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#182 lore raw

Re: [PATCH v6 01/19] fsck: Introduce fsck options

builtin/index-pack.c static int nr_threads; · line 78

Quoted 9 lines · Johannes Schindelin
builtin/index-pack.c +1 -0
index 48fa472..87ae9ba 100644
@@ -75,6 +75,7 @@ static int nr_threads;
 static int from_stdin;
 static int strict;
 static int do_fsck_object;
+static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;

So there is a global fsck_options used throughout the entire session here.

builtin/index-pack.c static void sha1_object(const void *data, struct object_entry *obj_entry, · line 843

Quoted 8 lines
builtin/index-pack.c +1 -2
@@ -838,10 +839,10 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 			if (!obj)
 				die(_("invalid %s"), typename(type));
 			if (do_fsck_object &&
-			    fsck_object(obj, buf, size, 1,
-				    fsck_error_function))
+			    fsck_object(obj, buf, size, &fsck_options))
 				die(_("Error in object"));

And that is used here to inspect each and every object we encounter.

builtin/index-pack.c static void sha1_object(const void *data, struct object_entry *obj_entry, · line 844

Quoted 2 lines
builtin/index-pack.c +1 -1
-			if (fsck_walk(obj, mark_link, NULL))
+			fsck_options.walk = mark_link;

Then we do a call to fsck_walk() starting from this object, letting mark_link() to inspect it and set the LINK bit.

builtin/index-pack.c static void sha1_object(const void *data, struct object_entry *obj_entry, · line 846

Quoted 2 lines
builtin/index-pack.c +1 -0
+			if (fsck_walk(obj, NULL, &fsck_options))
 				die(_("Not all child objects of %s are reachable"), sha1_to_hex(obj->sha1));

Since nobody else sets fsck_options.walk to any other value, and nobody else calls fsck_walk(), shouldn't that assignment be done only once somewhere a lot higher in the callchain? The apparent "overriding while inspecting this object" that does not have any corresponding "now we are done, so revert it to the original value" puzzled me, and I am sure it would puzzle future readers of this code.

#183 lore raw

Re: [PATCH v6 01/19] fsck: Introduce fsck options

Hi Junio,

Quoted 32 lines · Junio C Hamano

builtin/index-pack.c static int nr_threads; · line 78

Quoted 9 lines · Johannes Schindelin
builtin/index-pack.c +1 -0
index 48fa472..87ae9ba 100644
@@ -75,6 +75,7 @@ static int nr_threads;
 static int from_stdin;
 static int strict;
 static int do_fsck_object;
+static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;

So there is a global fsck_options used throughout the entire session here.

builtin/index-pack.c static void sha1_object(const void *data, struct object_entry *obj_entry, · line 843

Quoted 8 lines
builtin/index-pack.c +1 -2
@@ -838,10 +839,10 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 			if (!obj)
 				die(_("invalid %s"), typename(type));
 			if (do_fsck_object &&
-			    fsck_object(obj, buf, size, 1,
-				    fsck_error_function))
+			    fsck_object(obj, buf, size, &fsck_options))
 				die(_("Error in object"));

And that is used here to inspect each and every object we encounter.

builtin/index-pack.c static void sha1_object(const void *data, struct object_entry *obj_entry, · line 844

Quoted 2 lines
builtin/index-pack.c +1 -1
-			if (fsck_walk(obj, mark_link, NULL))
+			fsck_options.walk = mark_link;

Then we do a call to fsck_walk() starting from this object, letting mark_link() to inspect it and set the LINK bit.

Quoted 10 lines

builtin/index-pack.c static void sha1_object(const void *data, struct object_entry *obj_entry, · line 846

Quoted 2 lines
builtin/index-pack.c +1 -0
+			if (fsck_walk(obj, NULL, &fsck_options))
 				die(_("Not all child objects of %s are reachable"), sha1_to_hex(obj->sha1));

Since nobody else sets fsck_options.walk to any other value, and nobody else calls fsck_walk(), shouldn't that assignment be done only once somewhere a lot higher in the callchain? The apparent "overriding while inspecting this object" that does not have any corresponding "now we are done, so revert it to the original value" puzzled me, and I am sure it would puzzle future readers of this code.

Good point. I guess I was really wary that a configured walk function might change the behavior of fsck_object(). But after inspecting the code paths carefully, I conclude that the walk function is really only used in the fsck_walk_*() family of functions.

I changed that locally, will be part of v7.

Ciao,
Dscho

#184 lore raw

PATCH v6 2/19 fsck: Introduce identifiers for fsck messages

In reply to Johannes Schindelin

Instead of specifying whether a message by the fsck machinery constitutes an error or a warning, let's specify an identifier relating to the concrete problem that was encountered. This is necessary for upcoming support to be able to demote certain errors to warnings.

In the process, simplify the requirements on the calling code: instead of having to handle full-blown varargs in every callback, we now send a string buffer ready to be used by the callback.

We could use a simple enum for the message IDs here, but we want to guarantee that the enum values are associated with the appropriate message types (i.e. error or warning?). Besides, we want to introduce a parser in the next commit that maps the string representation to the enum value, hence we use the slightly ugly preprocessor construct that is extensible for use with said parser.

---
 builtin/fsck.c |  26 +++-----
 fsck.c         | 201 +++++++++++++++++++++++++++++++++++++++++----------------
 fsck.h         |   5 +-
 3 files changed, 154 insertions(+), 78 deletions(-)
builtin/fsck.c +8 -18
index 981dca5..fff38fe 100644
@@ -46,33 +46,23 @@ static int show_dangling = 1;
 #define DIRENT_SORT_HINT(de) ((de)->d_ino)
 #endif
 
-static void objreport(struct object *obj, const char *severity,
-                      const char *err, va_list params)
+static void objreport(struct object *obj, const char *msg_type,
+			const char *err)
 {
-	fprintf(stderr, "%s in %s %s: ",
-	        severity, typename(obj->type), sha1_to_hex(obj->sha1));
-	vfprintf(stderr, err, params);
-	fputs("\n", stderr);
+	fprintf(stderr, "%s in %s %s: %s\n",
+		msg_type, typename(obj->type), sha1_to_hex(obj->sha1), err);
 }
 
-__attribute__((format (printf, 2, 3)))
-static int objerror(struct object *obj, const char *err, ...)
+static int objerror(struct object *obj, const char *err)
 {
-	va_list params;
-	va_start(params, err);
 	errors_found |= ERROR_OBJECT;
-	objreport(obj, "error", err, params);
-	va_end(params);
+	objreport(obj, "error", err);
 	return -1;
 }
 
-__attribute__((format (printf, 3, 4)))
-static int fsck_error_func(struct object *obj, int type, const char *err, ...)
+static int fsck_error_func(struct object *obj, int type, const char *message)
 {
-	va_list params;
-	va_start(params, err);
-	objreport(obj, (type == FSCK_WARN) ? "warning" : "error", err, params);
-	va_end(params);
+	objreport(obj, (type == FSCK_WARN) ? "warning" : "error", message);
 	return (type == FSCK_WARN) ? 0 : 1;
 }
 
fsck.c +144 -57

356 lines not on this page · raw message

fsck.h +2 -3
index 07d0ab2..f6f268a 100644
@@ -17,10 +17,9 @@ struct fsck_options;
 typedef int (*fsck_walk_func)(struct object *obj, int type, void *data, struct fsck_options *options);
 
 /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
-typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...);
+typedef int (*fsck_error)(struct object *obj, int type, const char *message);
 
-__attribute__((format (printf, 3, 4)))
-int fsck_error_function(struct object *obj, int type, const char *fmt, ...);
+int fsck_error_function(struct object *obj, int type, const char *message);
 
 struct fsck_options {
 	fsck_walk_func walk;
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#185 lore raw

Re: [PATCH v6 02/19] fsck: Introduce identifiers for fsck messages

Quoted 16 lines · Johannes Schindelin

Instead of specifying whether a message by the fsck machinery constitutes an error or a warning, let's specify an identifier relating to the concrete problem that was encountered. This is necessary for upcoming support to be able to demote certain errors to warnings.

In the process, simplify the requirements on the calling code: instead of having to handle full-blown varargs in every callback, we now send a string buffer ready to be used by the callback.

We could use a simple enum for the message IDs here, but we want to guarantee that the enum values are associated with the appropriate message types (i.e. error or warning?). Besides, we want to introduce a parser in the next commit that maps the string representation to the enum value, hence we use the slightly ugly preprocessor construct that is extensible for use with said parser.

Quoted 2 lines

---

Nicely implemented. Looks good.

#186 lore raw

PATCH v6 3/19 fsck: Provide a function to parse fsck message IDs

In reply to Johannes Schindelin

These functions will be used in the next commits to allow the user to ask fsck to handle specific problems differently, e.g. demoting certain errors to warnings. The upcoming fsck_set_msg_types() function has to handle partial strings because we would like to be able to parse, say, 'missingemail=warn,missingtaggerentry=warn' command line parameters (which will be passed by receive-pack to index-pack and unpack-objects).

To make the parsing robust, we generate strings from the enum keys, and using these keys, we match up strings without dashes case-insensitively to the corresponding enum values.

---
 fsck.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)
fsck.c +28 -2
index ab24618..da5717c 100644
@@ -63,15 +63,41 @@ enum fsck_msg_id {
 };
 #undef MSG_ID
 
-#define MSG_ID(id, msg_type) { FSCK_##msg_type },
+#define STR(x) #x
+#define MSG_ID(id, msg_type) { STR(id), FSCK_##msg_type },
 static struct {
+	const char *id_string;
 	int msg_type;
 } msg_id_info[FSCK_MSG_MAX + 1] = {
 	FOREACH_MSG_ID(MSG_ID)
-	{ -1 }
+	{ NULL, -1 }
 };
 #undef MSG_ID
 
+static int parse_msg_id(const char *text, int len)
+{
+	int i, j;
+
+	if (len < 0)
+		len = strlen(text);
+
+	for (i = 0; i < FSCK_MSG_MAX; i++) {
+		const char *key = msg_id_info[i].id_string;
+		/* match id_string case-insensitively, without underscores. */
+		for (j = 0; j < len; j++) {
+			char c = *(key++);
+			if (c == '_')
+				c = *(key++);
+			if (toupper(text[j]) != c)
+				break;
+		}
+		if (j == len && !*key)
+			return i;
+	}
+
+	return -1;
+}
+
 static int fsck_msg_type(enum fsck_msg_id msg_id,
 	struct fsck_options *options)
 {
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#187 lore raw

Re: [PATCH v6 03/19] fsck: Provide a function to parse fsck message IDs

Quoted 9 lines · Johannes Schindelin
fsck.c +3 -1
+#define MSG_ID(id, msg_type) { STR(id), FSCK_##msg_type },
 static struct {
+	const char *id_string;
 	int msg_type;
 } msg_id_info[FSCK_MSG_MAX + 1] = {
 	FOREACH_MSG_ID(MSG_ID)
-	{ -1 }
+	{ NULL, -1 }
 };

fsck.c enum fsck_msg_id { · line 84

Quoted 10 lines
fsck.c +8 -0
 #undef MSG_ID
 
+static int parse_msg_id(const char *text, int len)
+{
+	int i, j;
+
+	if (len < 0)
+		len = strlen(text);
+
+	for (i = 0; i < FSCK_MSG_MAX; i++) {

I wonder an array without sentinel at the end with ARRAY_SIZE() may be a leaner way to do these, especially as this is all limited to this single file.

fsck.c enum fsck_msg_id { · line 90

Quoted 6 lines
fsck.c +6 -0
+		const char *key = msg_id_info[i].id_string;
+		/* match id_string case-insensitively, without underscores. */
+		for (j = 0; j < len; j++) {
+			char c = *(key++);
+			if (c == '_')
+				c = *(key++);

s/if/while/ perhaps?

fsck.c enum fsck_msg_id { · line 91

Quoted 1 line
fsck.c +1 -0
+			if (toupper(text[j]) != c)

I know the performance would not matter very much but calling toupper() for each letter in the user input FSCK_MSG_MAX times sounds rather inefficient.

Would it make sense to make the caller upcase instead (or upcase upfront in the function)?

Quoted 12 lines
fsck.c +9 -0
+				break;
+		}
+		if (j == len && !*key)
+			return i;
+	}
+
+	return -1;
+}
+
 static int fsck_msg_type(enum fsck_msg_id msg_id,
 	struct fsck_options *options)
 {
#188 lore raw

Re: [PATCH v6 03/19] fsck: Provide a function to parse fsck message IDs

Hi Junio,

Quoted 13 lines · Junio C Hamano
Quoted 11 lines · Johannes Schindelin
fsck.c +3 -1
+#define MSG_ID(id, msg_type) { STR(id), FSCK_##msg_type },
 static struct {
+	const char *id_string;
 	int msg_type;
 } msg_id_info[FSCK_MSG_MAX + 1] = {
 	FOREACH_MSG_ID(MSG_ID)
-	{ -1 }
+	{ NULL, -1 }
 };
 #undef MSG_ID
Quoted 12 lines

fsck.c enum fsck_msg_id { · line 84

Quoted 8 lines
fsck.c +8 -0
+static int parse_msg_id(const char *text, int len)
+{
+	int i, j;
+
+	if (len < 0)
+		len = strlen(text);
+
+	for (i = 0; i < FSCK_MSG_MAX; i++) {

I wonder an array without sentinel at the end with ARRAY_SIZE() may be a leaner way to do these, especially as this is all limited to this single file.

The real reason is that I cannot prevent a trailing comma with the way I construct the array, so FSCK_MSG_MAX is a natural way to support compilers that do not allow something like

    enum { A, B, C, };
Quoted 8 lines

fsck.c enum fsck_msg_id { · line 90

Quoted 6 lines
fsck.c +6 -0
+		const char *key = msg_id_info[i].id_string;
+		/* match id_string case-insensitively, without underscores. */
+		for (j = 0; j < len; j++) {
+			char c = *(key++);
+			if (c == '_')
+				c = *(key++);

s/if/while/ perhaps?

Actually, I want to prevent double underscores so that no ambiguity occurs between the camelCased version of, say, JUNIO_HAMANO and JUNIO__HAMANO.

I inserted an assert();

Quoted 8 lines

fsck.c enum fsck_msg_id { · line 91

Quoted 1 line
fsck.c +1 -0
+			if (toupper(text[j]) != c)

I know the performance would not matter very much but calling toupper() for each letter in the user input FSCK_MSG_MAX times sounds rather inefficient.

Would it make sense to make the caller upcase instead (or upcase upfront in the function)?

As you said, performance plays a lesser role here than simplicity. The strings we receive here are passed in read-only, therefore I would have to strdup() them first and then make sure to free() them. That was too un-simple for my taste.

Having said that, if you disagree, I will introduce the complexity, though. Do you want me to do that?

Ciao,
Dscho

#189 lore raw

PATCH v6 4/19 fsck: Offer a function to demote fsck errors to warnings

In reply to Johannes Schindelin

There are legacy repositories out there whose older commits and tags have issues that prevent pushing them when 'receive.fsckObjects' is set. One real-life example is a commit object that has been hand-crafted to list two authors.

Often, it is not possible to fix those issues without disrupting the work with said repositories, yet it is still desirable to perform checks by setting receive.fsckObjects = true. This commit is the first step to allow demoting specific fsck issues to mere warnings.

The fsck_set_msg_types() function added by this commit parses a list of settings in the form:

missingemail=warn,badname=warn,...

Unfortunately, the FSCK_WARN/FSCK_ERROR flag is only really heeded by git fsck so far, but other call paths (e.g. git index-pack --strict) error out *always* no matter what type was specified. Therefore, we need to take extra care to set all message types to FSCK_ERROR by default in those cases.

---
 fsck.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 fsck.h | 10 ++++++--
 2 files changed, 87 insertions(+), 5 deletions(-)
fsck.c +79 -3
index da5717c..8c3caff 100644
@@ -103,13 +103,85 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,
 {
 	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 inline int substrcmp(const char *string, int len, const char *match)
+{
+	int match_len = strlen(match);
+	if (match_len != len)
+		return -1;
+	return memcmp(string, match, len);
+}
+
+static int parse_msg_type(const char *str, int len)
+{
+	if (len < 0)
+		len = strlen(str);
+
+	if (!substrcmp(str, len, "error"))
+		return FSCK_ERROR;
+	else if (!substrcmp(str, len, "warn"))
+		return FSCK_WARN;
+	else
+		die("Unknown fsck message type: '%.*s'",
+				len, str);
+}
+
+void fsck_set_msg_type(struct fsck_options *options,
+		const char *msg_id, int msg_id_len,
+		const char *msg_type, int msg_type_len)
+{
+	int id = parse_msg_id(msg_id, msg_id_len), type;
+
+	if (id < 0)
+		die("Unhandled message id: %.*s", msg_id_len, msg_id);
+	type = parse_msg_type(msg_type, msg_type_len);
+
+	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)
+{
+	while (*values) {
+		int len = strcspn(values, " ,|"), equal;
+
+		if (!len) {
+			values++;
+			continue;
+		}
+
+		for (equal = 0; equal < len; equal++)
+			if (values[equal] == '=' || values[equal] == ':')
+				break;
+
+		if (equal == len)
+			die("Missing '=': '%.*s'", len, values);
+
+		fsck_set_msg_type(options, values, equal,
+				values + equal + 1, len - equal - 1);
+		values += len;
+	}
+}
+
 __attribute__((format (printf, 4, 5)))
 static int report(struct fsck_options *options, struct object *object,
 	enum fsck_msg_id id, const char *fmt, ...)
@@ -599,6 +671,10 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
 
 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;
 }
fsck.h +8 -2
index f6f268a..edb4540 100644
@@ -6,6 +6,11 @@
 
 struct fsck_options;
 
+void fsck_set_msg_type(struct fsck_options *options,
+		const char *msg_id, int msg_id_len,
+		const char *msg_type, int msg_type_len);
+void fsck_set_msg_types(struct fsck_options *options, const char *values);
+
 /*
  * callback function for fsck_walk
  * type is the expected type of the object or OBJ_ANY
@@ -25,10 +30,11 @@ struct fsck_options {
 	fsck_walk_func walk;
 	fsck_error error_func;
 	unsigned strict:1;
+	int *msg_type;
 };
 
-#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0 }
-#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1 }
+#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL }
+#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL }
 
 /* descend in all linked child objects
  * the return value is:
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#190 lore raw

Re: [PATCH v6 04/19] fsck: Offer a function to demote fsck errors to warnings

Quoted 13 lines · Johannes Schindelin
fsck.c +2 -3
index da5717c..8c3caff 100644
@@ -103,13 +103,85 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,
 {
 	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);
+

fsck.c static int fsck_msg_type(enum fsck_msg_id msg_id, · line 117

Quoted 10 lines
fsck.c +7 -0
+	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;
 }

Nice.

fsck.c static int fsck_msg_type(enum fsck_msg_id msg_id, · line 125

Quoted 7 lines
fsck.c +7 -0
+static inline int substrcmp(const char *string, int len, const char *match)
+{
+	int match_len = strlen(match);
+	if (match_len != len)
+		return -1;
+	return memcmp(string, match, len);
+}

What this does looks suspiciously like starts_with(), but its name "substrcmp()" does not give any hint that this is about the beginnig part of "string"; if anything, it gives a wrong hint that it may be any substring. prefixcmp() might be a better name but that was the old name for !starts_with() so we cannot use it here. It is a mouthful, but starts_with_counted() may be.

But the whole thing may be moot.

If we take the "why not upcase the end-user string upfront" suggestion from the previous review, fsck_set_msg_types() would have an upcased copy of the end-user string that it can muck with; it can turn "badfoo=error,poorbar=..." into "BADFOO=error,POORBAR=..." that is stored in its own writable memory (possibly a strbuf), and at that point it can afford to NUL-terminate BADFOO=error after finding where one specification ends with strcspn() before calling fsck_set_msg_type(), which in turn calls parse_msg_type().

So all parse_msg_type() needs to do is just !strcmp().

Quoted 104 lines
fsck.c +63 -0
+
+static int parse_msg_type(const char *str, int len)
+{
+	if (len < 0)
+		len = strlen(str);
+
+	if (!substrcmp(str, len, "error"))
+		return FSCK_ERROR;
+	else if (!substrcmp(str, len, "warn"))
+		return FSCK_WARN;
 
+	else
+		die("Unknown fsck message type: '%.*s'",
+				len, str);
+}
+
+void fsck_set_msg_type(struct fsck_options *options,
+		const char *msg_id, int msg_id_len,
+		const char *msg_type, int msg_type_len)
+{
+	int id = parse_msg_id(msg_id, msg_id_len), type;
+
+	if (id < 0)
+		die("Unhandled message id: %.*s", msg_id_len, msg_id);
+	type = parse_msg_type(msg_type, msg_type_len);
+
+	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)
+{
+	while (*values) {
+		int len = strcspn(values, " ,|"), equal;
+
+		if (!len) {
+			values++;
+			continue;
+		}
+
+		for (equal = 0; equal < len; equal++)
+			if (values[equal] == '=' || values[equal] == ':')
+				break;
+
+		if (equal == len)
+			die("Missing '=': '%.*s'", len, values);
+
+		fsck_set_msg_type(options, values, equal,
+				values + equal + 1, len - equal - 1);
+		values += len;
+	}
+}
+
 __attribute__((format (printf, 4, 5)))
 static int report(struct fsck_options *options, struct object *object,
 	enum fsck_msg_id id, const char *fmt, ...)
@@ -599,6 +671,10 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
 
 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;
 }
fsck.h +8 -2
index f6f268a..edb4540 100644
@@ -6,6 +6,11 @@
 
 struct fsck_options;
 
+void fsck_set_msg_type(struct fsck_options *options,
+		const char *msg_id, int msg_id_len,
+		const char *msg_type, int msg_type_len);
+void fsck_set_msg_types(struct fsck_options *options, const char *values);
+
 /*
  * callback function for fsck_walk
  * type is the expected type of the object or OBJ_ANY
@@ -25,10 +30,11 @@ struct fsck_options {
 	fsck_walk_func walk;
 	fsck_error error_func;
 	unsigned strict:1;
+	int *msg_type;
 };
 
-#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0 }
-#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1 }
+#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL }
+#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL }
 
 /* descend in all linked child objects
  * the return value is:
#191 lore raw

Re: [PATCH v6 04/19] fsck: Offer a function to demote fsck errors to warnings

Hi Junio,

Quoted 16 lines · Junio C Hamano

fsck.c static int fsck_msg_type(enum fsck_msg_id msg_id, · line 125

Quoted 7 lines · Johannes Schindelin
fsck.c +7 -0
+static inline int substrcmp(const char *string, int len, const char *match)
+{
+	int match_len = strlen(match);
+	if (match_len != len)
+		return -1;
+	return memcmp(string, match, len);
+}

What this does looks suspiciously like starts_with(), but its name "substrcmp()" does not give any hint that this is about the beginnig part of "string"; if anything, it gives a wrong hint that it may be any substring. prefixcmp() might be a better name but that was the old name for !starts_with() so we cannot use it here. It is a mouthful, but starts_with_counted() may be.

It is actually not prefixcmp() because it requires that match has precisely len bytes, while prefixcmp() or starts_with() would not care as long as the first strlen(match) bytes of string match match.

Maybe fixed_length_strcmp() would be an appropriate name, but it is pretty long and *still* does not convey exactly what this function is about.

Also please note that this is a static inline function, i.e. its definition does not bleed outside of this file.

So I hope that you are satisfied with simply adding

    /** compares a counted string to a NUL-terminated one. */

as comment above the substrcmp() function?

Quoted 10 lines

But the whole thing may be moot.

If we take the "why not upcase the end-user string upfront" suggestion from the previous review, fsck_set_msg_types() would have an upcased copy of the end-user string that it can muck with; it can turn "badfoo=error,poorbar=..." into "BADFOO=error,POORBAR=..." that is stored in its own writable memory (possibly a strbuf), and at that point it can afford to NUL-terminate BADFOO=error after finding where one specification ends with strcspn() before calling fsck_set_msg_type(), which in turn calls parse_msg_type().

Hmm. I really do not like that kind of thinking, i.e. having to duplicate, then modify data to be able to call the API, only to have to modify the data back afterwards, and eventually having to unallocate the data in all code paths. That feels just very inelegant to me.

I agree that it cannot be helped, sometimes, when you *have* to do exactly such mucking with data on a copy, be it to avoid additional complexity or poor performance. But I simply do not see the need for that here.

Ciao,
Dscho

#192 lore raw

Re: [PATCH v6 04/19] fsck: Offer a function to demote fsck errors to warnings

Quoted 5 lines · Johannes Schindelin

Hmm. I really do not like that kind of thinking, i.e. having to duplicate, then modify data to be able to call the API, only to have to modify the data back afterwards, and eventually having to unallocate the data in all code paths. That feels just very inelegant to me.

You can see in our codebase that I have avoided touching end-user strings by using a substring in place by introducing a new API function or using an existing API function that takes <ptr, len> for exactly that reason. There also are cases where we are better off if we make a copy upfront at a very high level in the callchain if that makes the processing of that string deeper in the callchain much simpler without customized helpers that take counted strings.

And 03/19 and this one taken together, I think it is an example of the latter [*1*].

You not only need to invent counted string comparison in 04/19 but also need upcasing byte-by-byte comparison in a loop in 03/19; both of which can be made much simpler if you massaged the end-user input "foo=error,bar=ignore" into "FOO=error,BAR=ignore" and allowed the code to loop over it to turn ',' into NUL while parsing each individual piece (i.e. "FOO=error").

So contrary to what you said in response to my review on 03/19, I view this as not "adding complexity" but its total opposite. It is to make the code and logic much less complex by paying the price for one copied (and massaged) string.

Having said all that, as long as the result functions correctly, I suspect that it may not matter much either way. As I already said, "we can demote this error to a warning (or ignored)" is much less useful in practice than the "we know this and that object in this project does not pass fsck, so please do not bother checking" in my mind, and that makes me think that this part of the series is much less important than the skip-list thing. Unnecessary complexity in the code and otherwise useless helper functions may be something that can be simplified following my advice, but that can be done as a code clean-up, simplification and optimization by somebody else later if they really cared.

Thanks.

[Footnote]

*1* Everything I say in my messages is what "I think", so saying "I think" before saying what I think is redundant, but this one needs that, because I think ;-) it is in the "taste" territory to view each individual case and decide which one of these two opposite approaches is more appropriate.

#193 lore raw

Re: [PATCH v6 04/19] fsck: Offer a function to demote fsck errors to warnings

Hi Junio,

Quoted 26 lines · Junio C Hamano
Quoted 5 lines · Johannes Schindelin

Hmm. I really do not like that kind of thinking, i.e. having to duplicate, then modify data to be able to call the API, only to have to modify the data back afterwards, and eventually having to unallocate the data in all code paths. That feels just very inelegant to me.

You can see in our codebase that I have avoided touching end-user strings by using a substring in place by introducing a new API function or using an existing API function that takes <ptr, len> for exactly that reason. There also are cases where we are better off if we make a copy upfront at a very high level in the callchain if that makes the processing of that string deeper in the callchain much simpler without customized helpers that take counted strings.

And 03/19 and this one taken together, I think it is an example of the latter [*1*].

You not only need to invent counted string comparison in 04/19 but also need upcasing byte-by-byte comparison in a loop in 03/19; both of which can be made much simpler if you massaged the end-user input "foo=error,bar=ignore" into "FOO=error,BAR=ignore" and allowed the code to loop over it to turn ',' into NUL while parsing each individual piece (i.e. "FOO=error").

Quoted 4 lines

So contrary to what you said in response to my review on 03/19, I view this as not "adding complexity" but its total opposite. It is to make the code and logic much less complex by paying the price for one copied (and massaged) string.

How about I implement your suggestion tomorrow, then show the diff between the two versions and we can assess what looks to be simpler (i.e. more maintainable)?

BTW I agree about the skip-list feature being the most important outcome of this patch series; It only occurred to me as a useful feature at the very end of my work on the fsck IDs, but then I did not want to throw away all of that previous work ;-)

Ciao,
Dscho

#194 lore raw

Re: [PATCH v6 04/19] fsck: Offer a function to demote fsck errors to warnings

Quoted 3 lines · Johannes Schindelin

How about I implement your suggestion tomorrow, then show the diff between the two versions and we can assess what looks to be simpler (i.e. more maintainable)?

I'm indifferent at this point, partly because as we agree that what you have as long as it works is ok, and more importantly, Michael's suggestion to turn "check unconditionally and only control if we ignore or warn or error out the result" into "do not even check if we are told to ignore" is a much more prouctive thing to spend your time on.

#195 lore raw

Re: [PATCH v6 04/19] fsck: Offer a function to demote fsck errors to warnings

In reply to Junio C Hamano

Hi Junio,

Quoted 28 lines · Junio C Hamano

fsck.c static int fsck_msg_type(enum fsck_msg_id msg_id, · line 125

Quoted 7 lines · Johannes Schindelin
fsck.c +7 -0
+static inline int substrcmp(const char *string, int len, const char *match)
+{
+	int match_len = strlen(match);
+	if (match_len != len)
+		return -1;
+	return memcmp(string, match, len);
+}

What this does looks suspiciously like starts_with(), but its name "substrcmp()" does not give any hint that this is about the beginnig part of "string"; if anything, it gives a wrong hint that it may be any substring. prefixcmp() might be a better name but that was the old name for !starts_with() so we cannot use it here. It is a mouthful, but starts_with_counted() may be.

But the whole thing may be moot.

If we take the "why not upcase the end-user string upfront" suggestion from the previous review, fsck_set_msg_types() would have an upcased copy of the end-user string that it can muck with; it can turn "badfoo=error,poorbar=..." into "BADFOO=error,POORBAR=..." that is stored in its own writable memory (possibly a strbuf), and at that point it can afford to NUL-terminate BADFOO=error after finding where one specification ends with strcspn() before calling fsck_set_msg_type(), which in turn calls parse_msg_type().

Quoted 1 line

So all parse_msg_type() needs to do is just !strcmp().

Turns out that the diffstat says it saves 10 lines. So I changed it according to your suggestion. Part of v7.

Ciao,
Dscho

#196 lore raw

PATCH v6 5/19 fsck (receive-pack): Allow demoting errors to warnings

In reply to Johannes Schindelin

For example, missing emails in commit and tag objects can be demoted to mere warnings with

git config receive.fsck.missingemail=warn

The value is actually a comma-separated list.

In case that the same key is listed in multiple receive.fsck.<msg-id> lines in the config, the latter configuration wins (this can happen for example when both $HOME/.gitconfig and .git/config contain message type settings).

As git receive-pack does not actually perform the checks, it hands off the setting to index-pack or unpack-objects in the form of an optional argument to the --strict option.

---
 builtin/index-pack.c     |  4 ++++
 builtin/receive-pack.c   | 17 +++++++++++++++--
 builtin/unpack-objects.c |  5 +++++
 fsck.c                   |  8 ++++++++
 fsck.h                   |  1 +
 5 files changed, 33 insertions(+), 2 deletions(-)
builtin/index-pack.c +4 -0
index 87ae9ba..98e14fe 100644
@@ -1633,6 +1633,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 			} else if (!strcmp(arg, "--strict")) {
 				strict = 1;
 				do_fsck_object = 1;
+			} else if (skip_prefix(arg, "--strict=", &arg)) {
+				strict = 1;
+				do_fsck_object = 1;
+				fsck_set_msg_types(&fsck_options, arg);
 			} else if (!strcmp(arg, "--check-self-contained-and-connected")) {
 				strict = 1;
 				check_self_contained_and_connected = 1;
builtin/receive-pack.c +15 -2
index 94d0571..3afe8f8 100644
@@ -19,6 +19,7 @@
 #include "tag.h"
 #include "gpg-interface.h"
 #include "sigchain.h"
+#include "fsck.h"
 
 static const char receive_pack_usage[] = "git receive-pack <git-dir>";
 
@@ -36,6 +37,7 @@ static enum deny_action deny_current_branch = DENY_UNCONFIGURED;
 static enum deny_action deny_delete_current = DENY_UNCONFIGURED;
 static int receive_fsck_objects = -1;
 static int transfer_fsck_objects = -1;
+static struct strbuf fsck_msg_types = STRBUF_INIT;
 static int receive_unpack_limit = -1;
 static int transfer_unpack_limit = -1;
 static int advertise_atomic_push = 1;
@@ -115,6 +117,15 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if (skip_prefix(var, "receive.fsck.", &var)) {
+		if (is_valid_msg_type(var, value))
+			strbuf_addf(&fsck_msg_types, "%c%s=%s",
+				fsck_msg_types.len ? ',' : '=', var, value);
+		else
+			warning("Skipping unknown msg id '%s'", var);
+		return 0;
+	}
+
 	if (strcmp(var, "receive.fsckobjects") == 0) {
 		receive_fsck_objects = git_config_bool(var, value);
 		return 0;
@@ -1490,7 +1501,8 @@ static const char *unpack(int err_fd, struct shallow_info *si)
 		if (quiet)
 			argv_array_push(&child.args, "-q");
 		if (fsck_objects)
-			argv_array_push(&child.args, "--strict");
+			argv_array_pushf(&child.args, "--strict%s",
+				fsck_msg_types.buf);
 		child.no_stdout = 1;
 		child.err = err_fd;
 		child.git_cmd = 1;
@@ -1508,7 +1520,8 @@ static const char *unpack(int err_fd, struct shallow_info *si)
 		argv_array_pushl(&child.args, "index-pack",
 				 "--stdin", hdr_arg, keep_arg, NULL);
 		if (fsck_objects)
-			argv_array_push(&child.args, "--strict");
+			argv_array_pushf(&child.args, "--strict%s",
+				fsck_msg_types.buf);
 		if (fix_thin)
 			argv_array_push(&child.args, "--fix-thin");
 		child.out = -1;
builtin/unpack-objects.c +5 -0
index 6d17040..7cc086f 100644
@@ -530,6 +530,11 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
 				strict = 1;
 				continue;
 			}
+			if (skip_prefix(arg, "--strict=", &arg)) {
+				strict = 1;
+				fsck_set_msg_types(&fsck_options, arg);
+				continue;
+			}
 			if (starts_with(arg, "--pack_header=")) {
 				struct pack_header *hdr;
 				char *c;
fsck.c +8 -0
index 8c3caff..8e6faa8 100644
@@ -138,6 +138,14 @@ static int parse_msg_type(const char *str, int len)
 				len, str);
 }
 
+int is_valid_msg_type(const char *msg_id, const char *msg_type)
+{
+	if (parse_msg_id(msg_id, -1) < 0)
+		return 0;
+	parse_msg_type(msg_type, -1);
+	return 1;
+}
+
 void fsck_set_msg_type(struct fsck_options *options,
 		const char *msg_id, int msg_id_len,
 		const char *msg_type, int msg_type_len)
fsck.h +1 -0
index edb4540..738c9df 100644
@@ -10,6 +10,7 @@ void fsck_set_msg_type(struct fsck_options *options,
 		const char *msg_id, int msg_id_len,
 		const char *msg_type, int msg_type_len);
 void fsck_set_msg_types(struct fsck_options *options, const char *values);
+int is_valid_msg_type(const char *msg_id, const char *msg_type);
 
 /*
  * callback function for fsck_walk
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#197 lore raw

PATCH v6 6/19 fsck: Report the ID of the error/warning

In reply to Johannes Schindelin

Some legacy code has objects with non-fatal fsck issues; To enable the user to ignore those issues, let's print out the ID (e.g. when encountering "missingemail", the user might want to call git config --add receive.fsck.missingemail=warn).

---
 fsck.c          | 16 ++++++++++++++++
 t/t1450-fsck.sh |  4 ++--
 2 files changed, 18 insertions(+), 2 deletions(-)
fsck.c +16 -0
index 8e6faa8..0b3e18f 100644
@@ -190,6 +190,20 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
 	}
 }
 
+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));
+	}
+
+	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, ...)
@@ -198,6 +212,8 @@ static int report(struct fsck_options *options, struct object *object,
 	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);
t/t1450-fsck.sh +2 -2
index cfb32b6..d6d3b13 100755
@@ -231,8 +231,8 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
 	git fsck --tags 2>out &&
 
 	cat >expect <<-EOF &&
-	warning in tag $tag: invalid '\''tag'\'' name: wrong name format
-	warning in tag $tag: invalid format - expected '\''tagger'\'' line
+	warning in tag $tag: badtagname: invalid '\''tag'\'' name: wrong name format
+	warning in tag $tag: missingtaggerentry: invalid format - expected '\''tagger'\'' line
 	EOF
 	test_cmp expect out
 '
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#198 lore raw

Re: [PATCH v6 06/19] fsck: Report the ID of the error/warning

Quoted 37 lines · Johannes Schindelin

Some legacy code has objects with non-fatal fsck issues; To enable the user to ignore those issues, let's print out the ID (e.g. when encountering "missingemail", the user might want to call git config --add receive.fsck.missingemail=warn).

---
 fsck.c          | 16 ++++++++++++++++
 t/t1450-fsck.sh |  4 ++--
 2 files changed, 18 insertions(+), 2 deletions(-)
fsck.c +14 -0
index 8e6faa8..0b3e18f 100644
@@ -190,6 +190,20 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
 	}
 }
 
+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));
+	}
+
+	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, ...)

fsck.c static int report(struct fsck_options *options, struct object *object, · line 215

Quoted 4 lines
fsck.c +1 -0
@@ -198,6 +212,8 @@ static int report(struct fsck_options *options, struct object *object,
 	struct strbuf sb = STRBUF_INIT;
 	int msg_type = fsck_msg_type(id, options), result;
 
+	append_msg_id(&sb, msg_id_info[id].id_string);

Nice. The append function can be made a bit more context sensitive to upcase a char immediately after _ to make it easier to cut and paste into "git config" and keep the result readable, I think.

	git config --add receive.fsck.missingEmail=warn
Quoted 18 lines
fsck.c +0 -0
 	va_start(ap, fmt);
 	strbuf_vaddf(&sb, fmt, ap);
 	result = options->error_func(object, msg_type, sb.buf);
t/t1450-fsck.sh +2 -2
index cfb32b6..d6d3b13 100755
@@ -231,8 +231,8 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
 	git fsck --tags 2>out &&
 
 	cat >expect <<-EOF &&
-	warning in tag $tag: invalid '\''tag'\'' name: wrong name format
-	warning in tag $tag: invalid format - expected '\''tagger'\'' line
+	warning in tag $tag: badtagname: invalid '\''tag'\'' name: wrong name format
+	warning in tag $tag: missingtaggerentry: invalid format - expected '\''tagger'\'' line
 	EOF
 	test_cmp expect out
 '
#199 lore raw

Re: [PATCH v6 06/19] fsck: Report the ID of the error/warning

Hi Junio,

Quoted 42 lines · Junio C Hamano
Quoted 40 lines · Johannes Schindelin

Some legacy code has objects with non-fatal fsck issues; To enable the user to ignore those issues, let's print out the ID (e.g. when encountering "missingemail", the user might want to call git config --add receive.fsck.missingemail=warn).

---
 fsck.c          | 16 ++++++++++++++++
 t/t1450-fsck.sh |  4 ++--
 2 files changed, 18 insertions(+), 2 deletions(-)
fsck.c +14 -0
index 8e6faa8..0b3e18f 100644
@@ -190,6 +190,20 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
 	}
 }
 
+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));
+	}
+
+	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, ...)
@@ -198,6 +212,8 @@ static int report(struct fsck_options *options, struct object *object,
 	struct strbuf sb = STRBUF_INIT;
 	int msg_type = fsck_msg_type(id, options), result;
 
Quoted 8 lines

fsck.c static int report(struct fsck_options *options, struct object *object, · line 215

Quoted 1 line
fsck.c +1 -0
+	append_msg_id(&sb, msg_id_info[id].id_string);

Nice. The append function can be made a bit more context sensitive to upcase a char immediately after _ to make it easier to cut and paste into "git config" and keep the result readable, I think.

	git config --add receive.fsck.missingEmail=warn

Okay. I camelCased the IDs; it is a bit sore on my eyes in the command-line output, and the config variables are case-insensitive, anyway, but your wish is my command... I changed it locally, it will be part of v7.

Ciao,
Dscho

#200 lore raw

Re: [PATCH v6 06/19] fsck: Report the ID of the error/warning

That "... can be made ..." was not my wish but more like "the way the code is structured it is possible for somebody to do such a thing easily, well done" compliment ;-)

The message names will have to be shown somewhere in the documentation, and in Documentation/ we try to use camelCase to show the word boundary; it would be better to match that, as this output is meant to be used there.

Quoted 58 lines · Johannes Schindelin

Hi Junio,

Quoted 42 lines · Junio C Hamano
Quoted 40 lines · Johannes Schindelin

Some legacy code has objects with non-fatal fsck issues; To enable the user to ignore those issues, let's print out the ID (e.g. when encountering "missingemail", the user might want to call git config --add receive.fsck.missingemail=warn).

---
 fsck.c          | 16 ++++++++++++++++
 t/t1450-fsck.sh |  4 ++--
 2 files changed, 18 insertions(+), 2 deletions(-)
fsck.c +14 -0
index 8e6faa8..0b3e18f 100644
@@ -190,6 +190,20 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
     }
 }
 
+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));
+    }
+
+    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, ...)
@@ -198,6 +212,8 @@ static int report(struct fsck_options *options, struct object *object,
     struct strbuf sb = STRBUF_INIT;
     int msg_type = fsck_msg_type(id, options), result;
 
Quoted 8 lines

fsck.c static int report(struct fsck_options *options, struct object *object, · line 215

Quoted 1 line
fsck.c +1 -0
+    append_msg_id(&sb, msg_id_info[id].id_string);

Nice. The append function can be made a bit more context sensitive to upcase a char immediately after _ to make it easier to cut and paste into "git config" and keep the result readable, I think.

      git config --add receive.fsck.missingEmail=warn

Okay. I camelCased the IDs; it is a bit sore on my eyes in the command-line output, and the config variables are case-insensitive, anyway, but your wish is my command... I changed it locally, it will be part of v7.

Ciao,
Dscho

#201 lore raw

PATCH v6 7/19 fsck: Make fsck_ident() warn-friendly

In reply to Johannes Schindelin

When fsck_ident() identifies a problem with the ident, it should still advance the pointer to the next line so that fsck can continue in the case of a mere warning.

---
 fsck.c | 49 +++++++++++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 22 deletions(-)
fsck.c +27 -22
index 0b3e18f..9faaf53 100644
@@ -479,40 +479,45 @@ static int require_end_of_header(const void *data, unsigned long size,
 
 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;
 }
 
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#202 lore raw

Re: [PATCH v6 07/19] fsck: Make fsck_ident() warn-friendly

Quoted 6 lines · Johannes Schindelin

When fsck_ident() identifies a problem with the ident, it should still advance the pointer to the next line so that fsck can continue in the case of a mere warning.

---

Makes sense.

#203 lore raw

PATCH v6 8/19 fsck: Make fsck_commit() warn-friendly

In reply to Johannes Schindelin

When fsck_commit() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.

Note that some problems are too problematic to simply ignore. For example, when the header lines are mixed up, we punt after encountering an incorrect line. Therefore, demoting certain warnings to errors can hide other problems. Example: demoting the missingauthor error to a warning would hide a problematic committer line.

---
 fsck.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
fsck.c +20 -8
index 9faaf53..9fe9f48 100644
@@ -534,12 +534,18 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 
 	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++;
 	}
@@ -548,11 +554,17 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 	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");
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#204 lore raw

Re: [PATCH v6 08/19] fsck: Make fsck_commit() warn-friendly

Quoted 3 lines · Johannes Schindelin

When fsck_commit() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.

That makes sense.

Quoted 5 lines

Note that some problems are too problematic to simply ignore. For example, when the header lines are mixed up, we punt after encountering an incorrect line. Therefore, demoting certain warnings to errors can hide other problems. Example: demoting the missingauthor error to a warning would hide a problematic committer line.

Is this a warning to end-users (which should be better in the doc), or "because some of them are too problematic to ignore" that forgot to add the explanation "hence we do not keep going in this code" (which should be in the log message if that is what is going on)?

I notice that there are many instances of

	if (object does not pass some test)
		return report(...);

that do not do "err = report(); if (err) return;" in this function after applying this patch.

I think that answers the above question. The answer is "because some are too problematic, even after this patch, we give up parsing the remainder of the commit object once we hit certain errors, leaving some other errors that appear later in the object undetected".

I think that is a sensible design decision, but the proposed log message forgets to say so.

Quoted 10 lines
---
 fsck.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
fsck.c +0 -0
index 9faaf53..9fe9f48 100644

fsck.c static int fsck_commit_buffer(struct commit *commit, const char *buffer, · line 541

Quoted 10 lines
fsck.c +5 -2
@@ -534,12 +534,18 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 
 	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;
+	}

I do not think this "if (err) return err;" that uses the return value of report(), makes sense.

As all the errors that use this pattern are isolated ones that does not break parsing of the remainder (e.g. author ident had an extra > in it may break "author " but that does not prevent us from checking "committer ").

Your report() switches its return value based on the user setting; specifically, it returns 0 if the user tells us to ignore/skip or warn. Which means that the user will see all warnings, but we stop at the first error.

Shouldn't we continue regardless of the end-user setting in order to show errors on other fields, too?

#205 lore raw

Re: [PATCH v6 08/19] fsck: Make fsck_commit() warn-friendly

Hi Junio,

Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Johannes Schindelin

Note that some problems are too problematic to simply ignore. For example, when the header lines are mixed up, we punt after encountering an incorrect line. Therefore, demoting certain warnings to errors can hide other problems. Example: demoting the missingauthor error to a warning would hide a problematic committer line.

Quoted 4 lines

Is this a warning to end-users (which should be better in the doc), or "because some of them are too problematic to ignore" that forgot to add the explanation "hence we do not keep going in this code" (which should be in the log message if that is what is going on)?

It was intended to offer the explanation for the design decision you commented on later:

Quoted 46 lines

I notice that there are many instances of

	if (object does not pass some test)
		return report(...);

that do not do "err = report(); if (err) return;" in this function after applying this patch.

I think that answers the above question. The answer is "because some are too problematic, even after this patch, we give up parsing the remainder of the commit object once we hit certain errors, leaving some other errors that appear later in the object undetected".

I think that is a sensible design decision, but the proposed log message forgets to say so.

Quoted 10 lines
---
 fsck.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
fsck.c +0 -0
index 9faaf53..9fe9f48 100644

fsck.c static int fsck_commit_buffer(struct commit *commit, const char *buffer, · line 541

Quoted 10 lines
fsck.c +5 -2
@@ -534,12 +534,18 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 
 	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;
+	}

I do not think this "if (err) return err;" that uses the return value of report(), makes sense.

As all the errors that use this pattern are isolated ones that does not break parsing of the remainder (e.g. author ident had an extra > in it may break "author " but that does not prevent us from checking "committer ").

Quoted 7 lines

Your report() switches its return value based on the user setting; specifically, it returns 0 if the user tells us to ignore/skip or warn. Which means that the user will see all warnings, but we stop at the first error.

Shouldn't we continue regardless of the end-user setting in order to show errors on other fields, too?

I can make that happen, but please note that this is a change of behavior: we always stopped upon the first error.

It was my intention not to change behavior in that way without a proper reason, and I saw none.

I actually see a really good reason to *keep* the current behavior: one of the most prominent users of this code path is git receive-pack --strict. It is used heavily by GitHub to ensure at least a certain level of validity of pushed objects. Now, for this use case it is easy to see that you want to stop *as soon as an error was encountered*. And as GitHub sponsors my work on this patch series, my main aim is to support their use case.

Having said that, I agree that it could actually make sense for git fsck to show all errors, or at least to have an option to do so.

But that is a story for another night ;-)
Dscho

#206 lore raw

Re: [PATCH v6 08/19] fsck: Make fsck_commit() warn-friendly

Quoted 13 lines · Johannes Schindelin
Quoted 13 lines

I do not think this "if (err) return err;" that uses the return value of report(), makes sense.

As all the errors that use this pattern are isolated ones that does not break parsing of the remainder (e.g. author ident had an extra > in it may break "author " but that does not prevent us from checking "committer ").

Your report() switches its return value based on the user setting; specifically, it returns 0 if the user tells us to ignore/skip or warn. Which means that the user will see all warnings, but we stop at the first error.

Quoted 5 lines
Quoted 2 lines

Shouldn't we continue regardless of the end-user setting in order to show errors on other fields, too?

I can make that happen, but please note that this is a change of
behavior: we always stopped upon the first error.

Yeah, and we always died when we saw error, without giving users an option to turn it down. So?

Quoted 2 lines

It was my intention not to change behavior in that way without a proper reason, and I saw none.

What would be the end-user experience if you stopped at the first error? You see an error, add an "fsck.<msg-id> = ignore" and rerun, only to find another error and rinse and repeat? Wouldn't you rather see all of them and add the "ignore" to cover them in one go?

Quoted 7 lines

I actually see a really good reason to *keep* the current behavior:
one of the most prominent users of this code path is git receive-pack --strict. It is used heavily by GitHub to ensure at least a certain level of validity of pushed objects. Now, for this use case it is easy to see that you want to stop *as soon as an error was encountered*. And as GitHub sponsors my work on this patch series, my main aim is to support their use case.

While I understand that use case, I do not think stopping after showing three more errors in a single commit would make much difference in the bigger picture.

#207 lore raw

Re: [PATCH v6 08/19] fsck: Make fsck_commit() warn-friendly

Quoted 13 lines · Junio C Hamano

What would be the end-user experience if you stopped at the first error? You see an error, add an "fsck.<msg-id> = ignore" and rerun, only to find another error and rinse and repeat? Wouldn't you rather see all of them and add the "ignore" to cover them in one go?

Quoted 7 lines

I actually see a really good reason to *keep* the current behavior:
one of the most prominent users of this code path is git receive-pack --strict. It is used heavily by GitHub to ensure at least a certain level of validity of pushed objects. Now, for this use case it is easy to see that you want to stop *as soon as an error was encountered*. And as GitHub sponsors my work on this patch series, my main aim is to support their use case.

Quoted 3 lines

While I understand that use case, I do not think stopping after showing three more errors in a single commit would make much difference in the bigger picture.

I actually changed my mind. The above talks about the value given to the end user by noticing as many errors in a single object, but I'd think fsck.<msg-id> is pretty much useless as a tool to keep using a repository with malformed object in its history. When you are told object d6602ec is bad (that's the v0.99 tag that does not have tagger field), you would never want to say "in this repository, any tag without tagger is allowed", because you would still want to catch and prevent future breakages of the same kind in new tags.

And the way to do so is to say "I know the object d6602ec is bad, so do not report breakage you find to me" by using the skip-list. For that use case, showing _all_ errors (or warnings for that matter) does not add any value.

So let's stop at the first error as your patch did.

#208 lore raw

PATCH v6 9/19 fsck: Handle multiple authors in commits specially

In reply to Johannes Schindelin

This problem has been detected in the wild, and is the primary reason to introduce an option to demote certain fsck errors to warnings. Let's offer to ignore this particular problem specifically.

Technically, we could handle such repositories by setting receive.fsck.<msg-id> to missingcommitter=warn, but that could hide missing tree objects in the same commit because we cannot continue verifying any commit object after encountering a missing committer line, while we can continue in the case of multiple author lines.

---
 fsck.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fsck.c +9 -0
index 9fe9f48..0cfa4d0 100644
@@ -38,6 +38,7 @@
 	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) \
@@ -571,6 +572,14 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 	err = fsck_ident(&buffer, &commit->object, options);
 	if (err)
 		return err;
+	while (skip_prefix(buffer, "author ", &buffer)) {
+		err = report(options, &commit->object, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines");
+		if (err)
+			return err;
+		err = fsck_ident(&buffer, &commit->object, options);
+		if (err)
+			return err;
+	}
 	if (!skip_prefix(buffer, "committer ", &buffer))
 		return report(options, &commit->object, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line");
 	err = fsck_ident(&buffer, &commit->object, options);
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#209 lore raw

Re: [PATCH v6 09/19] fsck: Handle multiple authors in commits specially

fsck.c static int fsck_commit_buffer(struct commit *commit, const char *buffer, · line 582

Quoted 11 lines · Johannes Schindelin
fsck.c +8 -0
 	err = fsck_ident(&buffer, &commit->object, options);
 	if (err)
 		return err;
+	while (skip_prefix(buffer, "author ", &buffer)) {
+		err = report(options, &commit->object, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines");
+		if (err)
+			return err;
+		err = fsck_ident(&buffer, &commit->object, options);
+		if (err)
+			return err;
+	}

Hmph, naively I would have expected that you wouldn't need an extra call to fsck_ident() here, and instead would see something like this:

	author_count = 0;
	while (skip_prefix("author ")) {
        	author_count++;
                ... do the existing check as-is ...
	}
        if (author_count < 1)
        	err |= report(missing author);
	else if (author_count > 1)
        	err |= report(multiple authors);
#210 lore raw

Re: [PATCH v6 09/19] fsck: Handle multiple authors in commits specially

Hi Junio,

Quoted 18 lines · Junio C Hamano

fsck.c static int fsck_commit_buffer(struct commit *commit, const char *buffer, · line 582

Quoted 11 lines · Johannes Schindelin
fsck.c +8 -0
 	err = fsck_ident(&buffer, &commit->object, options);
 	if (err)
 		return err;
+	while (skip_prefix(buffer, "author ", &buffer)) {
+		err = report(options, &commit->object, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines");
+		if (err)
+			return err;
+		err = fsck_ident(&buffer, &commit->object, options);
+		if (err)
+			return err;
+	}

Hmph, naively I would have expected that you wouldn't need an extra call to fsck_ident() here, and instead would see something like this:

Quoted 9 lines
	author_count = 0;
	while (skip_prefix("author ")) {
        	author_count++;
                ... do the existing check as-is ...
	}
        if (author_count < 1)
        	err |= report(missing author);
	else if (author_count > 1)
        	err |= report(multiple authors);

Good idea! I fixed this in my branch and it will be part of v7.

Ciao,
Dscho

#211 lore raw

PATCH v6 10/19 fsck: Make fsck_tag() warn-friendly

In reply to Johannes Schindelin

When fsck_tag() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.

Just like fsck_commit(), there are certain problems that could hide other issues with the same tag object. For example, if the 'type' line is not encountered in the correct position, the 'tag' line – if there is any – would not be handled at all.

---
 fsck.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fsck.c +2 -1
index 0cfa4d0..21e3052 100644
@@ -640,7 +640,8 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
 	}
 	if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
 		ret = report(options, &tag->object, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
-		goto done;
+		if (ret)
+			goto done;
 	}
 	buffer += 41;
 
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#212 lore raw

Re: [PATCH v6 10/19] fsck: Make fsck_tag() warn-friendly

Quoted 3 lines · Johannes Schindelin

When fsck_tag() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.

I agree with that. But if FSCK_MSG_BAD_OBJECT_SHA1 is an ignorable error, why should we still have a conditional "goto done" here?

Shouldn't we be parsing the object the same way regardless?

Quoted 24 lines

Just like fsck_commit(), there are certain problems that could hide other issues with the same tag object. For example, if the 'type' line is not encountered in the correct position, the 'tag' line – if there is any – would not be handled at all.

---
 fsck.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fsck.c +2 -1
index 0cfa4d0..21e3052 100644
@@ -640,7 +640,8 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
 	}
 	if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
 		ret = report(options, &tag->object, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
-		goto done;
+		if (ret)
+			goto done;
 	}
 	buffer += 41;
#213 lore raw

Re: [PATCH v6 10/19] fsck: Make fsck_tag() warn-friendly

Hi Junio,

Quoted 10 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin

When fsck_tag() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.

I agree with that. But if FSCK_MSG_BAD_OBJECT_SHA1 is an ignorable error, why should we still have a conditional "goto done" here?

Shouldn't we be parsing the object the same way regardless?

Same reason as I mentioned before: in git receive-pack --strict we want to fail early, there is no sense to keep going when we know that nothing of the rest will make it to the server.

Ciao,
Dscho

#214 lore raw

PATCH v6 11/19 fsck: Add a simple test for receive.fsck.<msg-id>

In reply to Johannes Schindelin
---
 t/t5504-fetch-receive-strict.sh | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
t/t5504-fetch-receive-strict.sh +21 -0
index 69ee13c..3f7e96a 100755
@@ -115,4 +115,25 @@ test_expect_success 'push with transfer.fsckobjects' '
 	test_cmp exp act
 '
 
+cat >bogus-commit <<\EOF
+tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
+author Bugs Bunny 1234567890 +0000
+committer Bugs Bunny <[email protected]> 1234567890 +0000
+
+This commit object intentionally broken
+EOF
+
+test_expect_success 'push with receive.fsck.missingemail=warn' '
+	commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
+	git push . $commit:refs/heads/bogus &&
+	rm -rf dst &&
+	git init dst &&
+	git --git-dir=dst/.git config receive.fsckobjects true &&
+	test_must_fail git push --porcelain dst bogus &&
+	git --git-dir=dst/.git config \
+		receive.fsck.missingemail warn &&
+	git push --porcelain dst bogus >act 2>&1 &&
+	grep "missingemail" act
+'
+
 test_done
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#215 lore raw

PATCH v6 12/19 fsck: Disallow demoting grave fsck errors to warnings

In reply to Johannes Schindelin

Some kinds of errors are intrinsically unrecoverable (e.g. errors while uncompressing objects). It does not make sense to allow demoting them to mere warnings.

---
 fsck.c                          | 14 ++++++++++++--
 t/t5504-fetch-receive-strict.sh | 11 +++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)
fsck.c +12 -2
index 21e3052..a4fbce3 100644
@@ -9,7 +9,12 @@
 #include "refs.h"
 #include "utf8.h"
 
+#define FSCK_FATAL -1
+
 #define FOREACH_MSG_ID(FUNC) \
+	/* fatal errors */ \
+	FUNC(NUL_IN_HEADER, FATAL) \
+	FUNC(UNTERMINATED_HEADER, FATAL) \
 	/* errors */ \
 	FUNC(BAD_DATE, ERROR) \
 	FUNC(BAD_DATE_OVERFLOW, ERROR) \
@@ -39,11 +44,9 @@
 	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) \
 	FUNC(UNKNOWN_TYPE, ERROR) \
-	FUNC(UNTERMINATED_HEADER, ERROR) \
 	FUNC(ZERO_PADDED_DATE, ERROR) \
 	/* warnings */ \
 	FUNC(BAD_FILEMODE, WARN) \
@@ -157,6 +160,10 @@ void fsck_set_msg_type(struct fsck_options *options,
 		die("Unhandled message id: %.*s", msg_id_len, msg_id);
 	type = parse_msg_type(msg_type, msg_type_len);
 
+	if (type != FSCK_ERROR && msg_id_info[id].msg_type == FSCK_FATAL)
+		die("Cannot demote %.*s to %.*s", msg_id_len, msg_id,
+				msg_type_len, msg_type);
+
 	if (!options->msg_type) {
 		int i;
 		int *msg_type = xmalloc(sizeof(int) * FSCK_MSG_MAX);
@@ -213,6 +220,9 @@ static int report(struct fsck_options *options, struct object *object,
 	struct strbuf sb = STRBUF_INIT;
 	int msg_type = fsck_msg_type(id, options), result;
 
+	if (msg_type == FSCK_FATAL)
+		msg_type = FSCK_ERROR;
+
 	append_msg_id(&sb, msg_id_info[id].id_string);
 
 	va_start(ap, fmt);
t/t5504-fetch-receive-strict.sh +11 -0
index 3f7e96a..0d64229 100755
@@ -136,4 +136,15 @@ test_expect_success 'push with receive.fsck.missingemail=warn' '
 	grep "missingemail" act
 '
 
+test_expect_success \
+	'receive.fsck.unterminatedheader=warn triggers error' '
+	rm -rf dst &&
+	git init dst &&
+	git --git-dir=dst/.git config receive.fsckobjects true &&
+	git --git-dir=dst/.git config \
+		receive.fsck.unterminatedheader warn &&
+	test_must_fail git push --porcelain dst HEAD >act 2>&1 &&
+	grep "Cannot demote unterminatedheader" act
+'
+
 test_done
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#216 lore raw

Re: [PATCH v6 12/19] fsck: Disallow demoting grave fsck errors to warnings

Quoted 28 lines · Johannes Schindelin

Some kinds of errors are intrinsically unrecoverable (e.g. errors while uncompressing objects). It does not make sense to allow demoting them to mere warnings.

---
 fsck.c                          | 14 ++++++++++++--
 t/t5504-fetch-receive-strict.sh | 11 +++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)
fsck.c +5 -0
index 21e3052..a4fbce3 100644
@@ -9,7 +9,12 @@
 #include "refs.h"
 #include "utf8.h"
 
+#define FSCK_FATAL -1
+
 #define FOREACH_MSG_ID(FUNC) \
+	/* fatal errors */ \
+	FUNC(NUL_IN_HEADER, FATAL) \
+	FUNC(UNTERMINATED_HEADER, FATAL) \
 	/* errors */ \
 	FUNC(BAD_DATE, ERROR) \
 	FUNC(BAD_DATE_OVERFLOW, ERROR) \

fsck.c line 46

Quoted 8 lines
fsck.c +0 -2
@@ -39,11 +44,9 @@
 	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) \
 	FUNC(UNKNOWN_TYPE, ERROR) \
-	FUNC(UNTERMINATED_HEADER, ERROR) \

I think the end result very much makes a good sense, but why didn't this list enumerate the errors in the above "final" order from the beginning in 02/19?

#217 lore raw

Re: [PATCH v6 12/19] fsck: Disallow demoting grave fsck errors to warnings

Hi Junio,

Quoted 34 lines · Junio C Hamano
Quoted 32 lines · Johannes Schindelin

Some kinds of errors are intrinsically unrecoverable (e.g. errors while uncompressing objects). It does not make sense to allow demoting them to mere warnings.

---
 fsck.c                          | 14 ++++++++++++--
 t/t5504-fetch-receive-strict.sh | 11 +++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)
fsck.c +5 -1
index 21e3052..a4fbce3 100644
@@ -9,7 +9,12 @@
 #include "refs.h"
 #include "utf8.h"
 
+#define FSCK_FATAL -1
+
 #define FOREACH_MSG_ID(FUNC) \
+	/* fatal errors */ \
+	FUNC(NUL_IN_HEADER, FATAL) \
+	FUNC(UNTERMINATED_HEADER, FATAL) \
 	/* errors */ \
 	FUNC(BAD_DATE, ERROR) \
 	FUNC(BAD_DATE_OVERFLOW, ERROR) \
@@ -39,11 +44,9 @@
 	FUNC(MISSING_TYPE, ERROR) \
 	FUNC(MISSING_TYPE_ENTRY, ERROR) \
 	FUNC(MULTIPLE_AUTHORS, ERROR) \
-	FUNC(NUL_IN_HEADER, ERROR) \
Quoted 8 lines

fsck.c line 46

Quoted 4 lines
fsck.c +0 -1
 	FUNC(TAG_OBJECT_NOT_TAG, ERROR) \
 	FUNC(TREE_NOT_SORTED, ERROR) \
 	FUNC(UNKNOWN_TYPE, ERROR) \
-	FUNC(UNTERMINATED_HEADER, ERROR) \

I think the end result very much makes a good sense, but why didn't this list enumerate the errors in the above "final" order from the beginning in 02/19?

Because they are alphabetically ordered, within message type categories, that is; this helped me develop with more ease (you do not want to know how many hundreds of times I ran an interactive rebase on all of these patches...).

And from the point of a development story (which a patch series is), it would puzzle me, as a reader, if those two out of all the others were in front in 02/19, when they are no different from the others at that stage.

Ciao,
Dscho

#218 lore raw

Re: [PATCH v6 12/19] fsck: Disallow demoting grave fsck errors to warnings

Ahh, I didn't see that they were not grouped by object types, features or any meaningful axis.
That explains it (i.e. I can now understand why the original list was ordered differently from the final order).

Quoted 52 lines · Johannes Schindelin

Hi Junio,

Quoted 34 lines · Junio C Hamano
Quoted 32 lines · Johannes Schindelin

Some kinds of errors are intrinsically unrecoverable (e.g. errors while uncompressing objects). It does not make sense to allow demoting them to mere warnings.

---
 fsck.c                          | 14 ++++++++++++--
 t/t5504-fetch-receive-strict.sh | 11 +++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)
fsck.c +5 -1
index 21e3052..a4fbce3 100644
@@ -9,7 +9,12 @@
 #include "refs.h"
 #include "utf8.h"
 
+#define FSCK_FATAL -1
+
 #define FOREACH_MSG_ID(FUNC) \
+    /* fatal errors */ \
+    FUNC(NUL_IN_HEADER, FATAL) \
+    FUNC(UNTERMINATED_HEADER, FATAL) \
     /* errors */ \
     FUNC(BAD_DATE, ERROR) \
     FUNC(BAD_DATE_OVERFLOW, ERROR) \
@@ -39,11 +44,9 @@
     FUNC(MISSING_TYPE, ERROR) \
     FUNC(MISSING_TYPE_ENTRY, ERROR) \
     FUNC(MULTIPLE_AUTHORS, ERROR) \
-    FUNC(NUL_IN_HEADER, ERROR) \
Quoted 8 lines

fsck.c line 46

Quoted 4 lines
fsck.c +0 -1
     FUNC(TAG_OBJECT_NOT_TAG, ERROR) \
     FUNC(TREE_NOT_SORTED, ERROR) \
     FUNC(UNKNOWN_TYPE, ERROR) \
-    FUNC(UNTERMINATED_HEADER, ERROR) \

I think the end result very much makes a good sense, but why didn't this list enumerate the errors in the above "final" order from the beginning in 02/19?

Because they are alphabetically ordered, within message type categories, that is; this helped me develop with more ease (you do not want to know how many hundreds of times I ran an interactive rebase on all of these patches...).

And from the point of a development story (which a patch series is), it would puzzle me, as a reader, if those two out of all the others were in front in 02/19, when they are no different from the others at that stage.

Ciao,
Dscho

#219 lore raw

PATCH v6 13/19 fsck: Optionally ignore specific fsck issues completely

In reply to Johannes Schindelin

An fsck issue in a legacy repository might be so common that one would like not to bother the user with mentioning it at all. With this change, that is possible by setting the respective message type to "ignore".

This change "abuses" the missingemail=warn test to verify that "ignore" is also accepted and works correctly. And while at it, it makes sure that multiple options work, too (they are passed to unpack-objects or index-pack as a comma-separated list via the --strict=... command-line option).

---
 fsck.c                          | 5 +++++
 fsck.h                          | 1 +
 t/t5504-fetch-receive-strict.sh | 9 ++++++++-
 3 files changed, 14 insertions(+), 1 deletion(-)
fsck.c +5 -0
index a4fbce3..b728646 100644
@@ -137,6 +137,8 @@ static int parse_msg_type(const char *str, int len)
 		return FSCK_ERROR;
 	else if (!substrcmp(str, len, "warn"))
 		return FSCK_WARN;
+	else if (!substrcmp(str, len, "ignore"))
+		return FSCK_IGNORE;
 	else
 		die("Unknown fsck message type: '%.*s'",
 				len, str);
@@ -220,6 +222,9 @@ static int report(struct fsck_options *options, struct object *object,
 	struct strbuf sb = STRBUF_INIT;
 	int msg_type = fsck_msg_type(id, options), result;
 
+	if (msg_type == FSCK_IGNORE)
+		return 0;
+
 	if (msg_type == FSCK_FATAL)
 		msg_type = FSCK_ERROR;
 
fsck.h +1 -0
index 738c9df..7e49372 100644
@@ -3,6 +3,7 @@
 
 #define FSCK_ERROR 1
 #define FSCK_WARN 2
+#define FSCK_IGNORE 3
 
 struct fsck_options;
 
t/t5504-fetch-receive-strict.sh +8 -1
index 0d64229..cb077b7 100755
@@ -133,7 +133,14 @@ test_expect_success 'push with receive.fsck.missingemail=warn' '
 	git --git-dir=dst/.git config \
 		receive.fsck.missingemail warn &&
 	git push --porcelain dst bogus >act 2>&1 &&
-	grep "missingemail" act
+	grep "missingemail" act &&
+	git --git-dir=dst/.git branch -D bogus &&
+	git  --git-dir=dst/.git config --add \
+		receive.fsck.missingemail ignore &&
+	git  --git-dir=dst/.git config --add \
+		receive.fsck.baddate warn &&
+	git push --porcelain dst bogus >act 2>&1 &&
+	test_must_fail grep "missingemail" act
 '
 
 test_expect_success \
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#220 lore raw

PATCH v6 14/19 fsck: Allow upgrading fsck warnings to errors

In reply to Johannes Schindelin

The 'invalid tag name' and 'missing tagger entry' warnings can now be upgraded to errors by specifying invalidtagname and missingtaggerentry in the receive.fsck.<msg-id> config setting.

Incidentally, the missing tagger warning is now really shown as a warning (as opposed to being reported with the "error:" prefix, as it used to be the case before this commit).

---
 fsck.c                | 24 +++++++++++++++++-------
 t/t5302-pack-index.sh |  2 +-
 2 files changed, 18 insertions(+), 8 deletions(-)
fsck.c +17 -7
index b728646..dedad01 100644
@@ -10,6 +10,7 @@
 #include "utf8.h"
 
 #define FSCK_FATAL -1
+#define FSCK_INFO -2
 
 #define FOREACH_MSG_ID(FUNC) \
 	/* fatal errors */ \
@@ -50,15 +51,16 @@
 	FUNC(ZERO_PADDED_DATE, ERROR) \
 	/* warnings */ \
 	FUNC(BAD_FILEMODE, WARN) \
-	FUNC(BAD_TAG_NAME, WARN) \
 	FUNC(EMPTY_NAME, WARN) \
 	FUNC(FULL_PATHNAME, WARN) \
 	FUNC(HAS_DOT, WARN) \
 	FUNC(HAS_DOTDOT, WARN) \
 	FUNC(HAS_DOTGIT, WARN) \
-	FUNC(MISSING_TAGGER_ENTRY, WARN) \
 	FUNC(NULL_SHA1, WARN) \
-	FUNC(ZERO_PADDED_FILEMODE, WARN)
+	FUNC(ZERO_PADDED_FILEMODE, WARN) \
+	/* infos (reported as warnings, but ignored by default) */ \
+	FUNC(BAD_TAG_NAME, INFO) \
+	FUNC(MISSING_TAGGER_ENTRY, INFO)
 
 #define MSG_ID(id, msg_type) FSCK_MSG_##id,
 enum fsck_msg_id {
@@ -227,6 +229,8 @@ static int report(struct fsck_options *options, struct object *object,
 
 	if (msg_type == FSCK_FATAL)
 		msg_type = FSCK_ERROR;
+	else if (msg_type == FSCK_INFO)
+		msg_type = FSCK_WARN;
 
 	append_msg_id(&sb, msg_id_info[id].id_string);
 
@@ -685,15 +689,21 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
 		goto done;
 	}
 	strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
-	if (check_refname_format(sb.buf, 0))
-		report(options, &tag->object, FSCK_MSG_BAD_TAG_NAME,
+	if (check_refname_format(sb.buf, 0)) {
+		ret = report(options, &tag->object, FSCK_MSG_BAD_TAG_NAME,
 			   "invalid 'tag' name: %.*s",
 			   (int)(eol - buffer), buffer);
+		if (ret)
+			goto done;
+	}
 	buffer = eol + 1;
 
-	if (!skip_prefix(buffer, "tagger ", &buffer))
+	if (!skip_prefix(buffer, "tagger ", &buffer)) {
 		/* early tags do not contain 'tagger' lines; warn only */
-		report(options, &tag->object, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
+		ret = report(options, &tag->object, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
+		if (ret)
+			goto done;
+	}
 	else
 		ret = fsck_ident(&buffer, &tag->object, options);
 
t/t5302-pack-index.sh +1 -1
index 61bc8da..3dc5ec4 100755
@@ -259,7 +259,7 @@ EOF
     thirtyeight=${tag#??} &&
     rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight &&
     git index-pack --strict tag-test-${pack1}.pack 2>err &&
-    grep "^error:.* expected .tagger. line" err
+    grep "^warning:.* expected .tagger. line" err
 '
 
 test_done
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#221 lore raw

Re: [PATCH v6 14/19] fsck: Allow upgrading fsck warnings to errors

Quoted 12 lines · Johannes Schindelin

#define FSCK_FATAL -1

fsck.c +1 -1
+#define FSCK_INFO -2
 
 #define FOREACH_MSG_ID(FUNC) \
 	/* fatal errors */ \
@@ -50,15 +51,16 @@
 	FUNC(ZERO_PADDED_DATE, ERROR) \
 	/* warnings */ \
 	FUNC(BAD_FILEMODE, WARN) \
-	FUNC(BAD_TAG_NAME, WARN) \
 	FUNC(EMPTY_NAME, WARN) \
 	FUNC(FULL_PATHNAME, WARN) \

fsck.c line 63

Quoted 10 lines
fsck.c +4 -2
 	FUNC(HAS_DOT, WARN) \
 	FUNC(HAS_DOTDOT, WARN) \
 	FUNC(HAS_DOTGIT, WARN) \
-	FUNC(MISSING_TAGGER_ENTRY, WARN) \
 	FUNC(NULL_SHA1, WARN) \
-	FUNC(ZERO_PADDED_FILEMODE, WARN)
+	FUNC(ZERO_PADDED_FILEMODE, WARN) \
+	/* infos (reported as warnings, but ignored by default) */ \
+	FUNC(BAD_TAG_NAME, INFO) \
+	FUNC(MISSING_TAGGER_ENTRY, INFO)

Exactly the same comment as 12/19 applies to this change; not only complaints but also "result makes sense" part.

#222 lore raw

Re: [PATCH v6 14/19] fsck: Allow upgrading fsck warnings to errors

Hi Junio,

Quoted 19 lines · Junio C Hamano
Quoted 17 lines · Johannes Schindelin

#define FSCK_FATAL -1

fsck.c +1 -2
+#define FSCK_INFO -2
 
 #define FOREACH_MSG_ID(FUNC) \
 	/* fatal errors */ \
@@ -50,15 +51,16 @@
 	FUNC(ZERO_PADDED_DATE, ERROR) \
 	/* warnings */ \
 	FUNC(BAD_FILEMODE, WARN) \
-	FUNC(BAD_TAG_NAME, WARN) \
 	FUNC(EMPTY_NAME, WARN) \
 	FUNC(FULL_PATHNAME, WARN) \
 	FUNC(HAS_DOT, WARN) \
 	FUNC(HAS_DOTDOT, WARN) \
 	FUNC(HAS_DOTGIT, WARN) \
-	FUNC(MISSING_TAGGER_ENTRY, WARN) \
 	FUNC(NULL_SHA1, WARN) \
Quoted 8 lines

fsck.c line 63

Quoted 5 lines
fsck.c +4 -1
-	FUNC(ZERO_PADDED_FILEMODE, WARN)
+	FUNC(ZERO_PADDED_FILEMODE, WARN) \
+	/* infos (reported as warnings, but ignored by default) */ \
+	FUNC(BAD_TAG_NAME, INFO) \
+	FUNC(MISSING_TAGGER_ENTRY, INFO)

Exactly the same comment as 12/19 applies to this change; not only complaints but also "result makes sense" part.

And my explanation is the same ;-) At 02/19 time, it would just puzzle me, as a reader, to see special treatment without any good reason.

Ciao,
Dscho

#223 lore raw

PATCH v6 15/19 fsck: Document the new receive.fsck.<msg-id> options

In reply to Johannes Schindelin
---
 Documentation/config.txt | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/config.txt +14 -0
index 3e37b93..306ab7a 100644
@@ -2205,6 +2205,20 @@ receive.fsckObjects::
 	Defaults to false. If not set, the value of `transfer.fsckObjects`
 	is used instead.
 
+receive.fsck.<msg-id>::
+	When `receive.fsckObjects` is set to true, errors can be switched
+	to warnings and vice versa by configuring the `receive.fsck.<msg-id>`
+	setting where the `<msg-id>` is the fsck message ID and the value
+	is one of `error`, `warn` or `ignore`. For convenience, fsck prefixes
+	the error/warning with the message ID, e.g. "missingemail: invalid
+	author/committer line - missing email" means that setting
+	`receive.fsck.missingemail = ignore` will hide that issue.
++
+This feature is intended to support working with legacy repositories
+which would not pass pushing when `receive.fsckObjects = true`, allowing
+the host to accept repositories with certain known issues but still catch
+other issues.
+
 receive.unpackLimit::
 	If the number of objects received in a push is below this
 	limit then the objects will be unpacked into loose object
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#224 lore raw

PATCH v6 16/19 fsck: Support demoting errors to warnings

In reply to Johannes Schindelin

We already have support in git receive-pack to deal with some legacy repositories which have non-fatal issues.

Let's make git fsck itself useful with such repositories, too, by allowing users to ignore known issues, or at least demote those issues to mere warnings.

Example: git -c fsck.missingemail=ignore fsck would hide problems with missing emails in author, committer and tagger lines.

In the same spirit that git receive-pack's usage of the fsck machinery differs from git fsck's – some of the non-fatal warnings in git fsck are fatal with git receive-pack when receive.fsckObjects = true, for example – we strictly separate the fsck.<msg-id> from the receive.fsck.<msg-id> settings.

---
 Documentation/config.txt | 11 +++++++++++
 builtin/fsck.c           | 12 ++++++++++++
 t/t1450-fsck.sh          | 11 +++++++++++
 3 files changed, 34 insertions(+)
Documentation/config.txt +11 -0
index 306ab7a..41fd460 100644
@@ -1250,6 +1250,17 @@ filter.<driver>.smudge::
 	object to a worktree file upon checkout.  See
 	linkgit:gitattributes[5] for details.
 
+fsck.<msg-id>::
+	Allows overriding the message type (error, warn or ignore) of a
+	specific message ID such as `missingemail`.
++
+For convenience, fsck prefixes the error/warning with the message ID,
+e.g.  "missingemail: invalid author/committer line - missing email" means
+that setting `fsck.missingemail = ignore` will hide that issue.
++
+This feature is intended to support working with legacy repositories
+which cannot be repaired without disruptive changes.
+
 gc.aggressiveDepth::
 	The depth parameter used in the delta compression
 	algorithm used by 'git gc --aggressive'.  This defaults
builtin/fsck.c +12 -0
index fff38fe..6de9f3e 100644
@@ -46,6 +46,16 @@ static int show_dangling = 1;
 #define DIRENT_SORT_HINT(de) ((de)->d_ino)
 #endif
 
+static int fsck_config(const char *var, const char *value, void *cb)
+{
+	if (skip_prefix(var, "fsck.", &var)) {
+		fsck_set_msg_type(&fsck_obj_options, var, -1, value, -1);
+		return 0;
+	}
+
+	return git_default_config(var, value, cb);
+}
+
 static void objreport(struct object *obj, const char *msg_type,
 			const char *err)
 {
@@ -646,6 +656,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 		include_reflogs = 0;
 	}
 
+	git_config(fsck_config, NULL);
+
 	fsck_head_link();
 	fsck_object_dir(get_object_directory());
 
t/t1450-fsck.sh +11 -0
index d6d3b13..922c346 100755
@@ -287,6 +287,17 @@ test_expect_success 'rev-list --verify-objects with bad sha1' '
 	grep -q "error: sha1 mismatch 63ffffffffffffffffffffffffffffffffffffff" out
 '
 
+test_expect_success 'force fsck to ignore double author' '
+	git cat-file commit HEAD >basis &&
+	sed "s/^author .*/&,&/" <basis | tr , \\n >multiple-authors &&
+	new=$(git hash-object -t commit -w --stdin <multiple-authors) &&
+	test_when_finished "remove_object $new" &&
+	git update-ref refs/heads/bogus "$new" &&
+	test_when_finished "git update-ref -d refs/heads/bogus" &&
+	test_must_fail git fsck &&
+	git -c fsck.multipleauthors=ignore fsck
+'
+
 _bz='\0'
 _bz5="$_bz$_bz$_bz$_bz$_bz"
 _bz20="$_bz5$_bz5$_bz5$_bz5"
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#225 lore raw

PATCH v6 17/19 fsck: Introduce `git fsck --quick`

In reply to Johannes Schindelin

This option avoids unpacking each and all objects, and just verifies the connectivity. In particular with large repositories, this speeds up the operation, at the expense of missing corrupt blobs and ignoring unreachable objects, if any.

---
 Documentation/git-fsck.txt |  7 ++++++-
 builtin/fsck.c             |  7 ++++++-
 t/t1450-fsck.sh            | 22 ++++++++++++++++++++++
 3 files changed, 34 insertions(+), 2 deletions(-)
Documentation/git-fsck.txt +6 -1
index 25c431d..b98fb43 100644
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
-	 [--[no-]full] [--strict] [--verbose] [--lost-found]
+	 [--[no-]full] [--quick] [--strict] [--verbose] [--lost-found]
 	 [--[no-]dangling] [--[no-]progress] [<object>*]
 
 DESCRIPTION
@@ -60,6 +60,11 @@ index file, all SHA-1 references in `refs` namespace, and all reflogs
 	object pools.  This is now default; you can turn it off
 	with --no-full.
 
+--quick::
+	Check only the connectivity of tags, commits and tree objects. By
+	avoiding to unpack blobs, this speeds up the operation, at the
+	expense of missing corrupt objects.
+
 --strict::
 	Enable more strict checking, namely to catch a file mode
 	recorded with g+w bit set, which was created by older
builtin/fsck.c +6 -1
index 6de9f3e..75fcb5f 100644
@@ -23,6 +23,7 @@ static int show_tags;
 static int show_unreachable;
 static int include_reflogs = 1;
 static int check_full = 1;
+static int quick;
 static int check_strict;
 static int keep_cache_objects;
 static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT;
@@ -181,6 +182,8 @@ static void check_reachable_object(struct object *obj)
 	if (!(obj->flags & HAS_OBJ)) {
 		if (has_sha1_pack(obj->sha1))
 			return; /* it is in pack - forget about it */
+		if (quick && has_sha1_file(obj->sha1))
+			return;
 		printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1));
 		errors_found |= ERROR_REACHABLE;
 		return;
@@ -623,6 +626,7 @@ static struct option fsck_opts[] = {
 	OPT_BOOL(0, "cache", &keep_cache_objects, N_("make index objects head nodes")),
 	OPT_BOOL(0, "reflogs", &include_reflogs, N_("make reflogs head nodes (default)")),
 	OPT_BOOL(0, "full", &check_full, N_("also consider packs and alternate objects")),
+	OPT_BOOL(0, "quick", &quick, N_("check only connectivity")),
 	OPT_BOOL(0, "strict", &check_strict, N_("enable more strict checking")),
 	OPT_BOOL(0, "lost-found", &write_lost_and_found,
 				N_("write dangling objects in .git/lost-found")),
@@ -659,7 +663,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 	git_config(fsck_config, NULL);
 
 	fsck_head_link();
-	fsck_object_dir(get_object_directory());
+	if (!quick)
+		fsck_object_dir(get_object_directory());
 
 	prepare_alt_odb();
 	for (alt = alt_odb_list; alt; alt = alt->next) {
t/t1450-fsck.sh +22 -0
index 922c346..2863a8a 100755
@@ -431,4 +431,26 @@ test_expect_success 'fsck notices ref pointing to missing tag' '
 	test_must_fail git -C missing fsck
 '
 
+test_expect_success 'fsck --quick' '
+	rm -rf quick &&
+	git init quick &&
+	(
+		cd quick &&
+		touch empty &&
+		git add empty &&
+		test_commit empty &&
+		empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 &&
+		rm -f $empty &&
+		echo invalid >$empty &&
+		test_must_fail git fsck --strict &&
+		git fsck --strict --quick &&
+		tree=$(git rev-parse HEAD:) &&
+		suffix=${tree#??} &&
+		tree=.git/objects/${tree%$suffix}/$suffix &&
+		rm -f $tree &&
+		echo invalid >$tree &&
+		test_must_fail git fsck --strict --quick
+	)
+'
+
 test_done
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#226 lore raw

Re: [PATCH v6 17/19] fsck: Introduce `git fsck --quick`

Quoted 2 lines · Johannes Schindelin

This option avoids unpacking each and all objects, and just verifies the connectivity.

That sounds like marketing ;-)

"Wow this does not unpack unnecessarily, wait, it needs to unpack and parse 3 out of 4 kinds of objects?"

Jokes aside, given that you should regularly repack your repository anyway, I do not think it is such a big downside that this mode misses a corrupt objects, and the 1 out of 4 kinds of objects, i.e. blobs, occupy major part of the repository storage, so this new mode probably makes sense.

Quoted 21 lines
t/t1450-fsck.sh +13 -0
index 922c346..2863a8a 100755
@@ -431,4 +431,26 @@ test_expect_success 'fsck notices ref pointing to missing tag' '
 	test_must_fail git -C missing fsck
 '
 
+test_expect_success 'fsck --quick' '
+	rm -rf quick &&
+	git init quick &&
+	(
+		cd quick &&
+		touch empty &&
+		git add empty &&
+		test_commit empty &&
+		empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 &&
+		rm -f $empty &&
+		echo invalid >$empty &&
+		test_must_fail git fsck --strict &&
+		git fsck --strict --quick &&

t/t1450-fsck.sh test_expect_success 'fsck notices ref pointing to missing tag' ' · line 456

Quoted 10 lines
t/t1450-fsck.sh +9 -0
+		tree=$(git rev-parse HEAD:) &&
+		suffix=${tree#??} &&
+		tree=.git/objects/${tree%$suffix}/$suffix &&
+		rm -f $tree &&
+		echo invalid >$tree &&
+		test_must_fail git fsck --strict --quick
+	)
+'
+
 test_done

I see a few impedance mismatch here. For --quick, I would have expected that the addition would be in t/perf/, not here.

Also the fact that quickness comes by cheating on blobs is an implementation detail; in the future, perhaps somebody may come up with a way to do a quick fsck while making sure blob corruption is also detected. The new test that expects "--quick" to ignore a corrupt blob forbids such a progress.

If the option name was "--ignore-corrupt-blob", then the above change is 100% justified, though.

#227 lore raw

Re: [PATCH v6 17/19] fsck: Introduce `git fsck --quick`

Hi Junio,

Quoted 9 lines · Junio C Hamano
Quoted 2 lines · Johannes Schindelin

This option avoids unpacking each and all objects, and just verifies the connectivity.

That sounds like marketing ;-)

"Wow this does not unpack unnecessarily, wait, it needs to unpack and parse 3 out of 4 kinds of objects?"

Hah, you caught me there. I wanted to say "blob objects".

Quoted 5 lines

Jokes aside, given that you should regularly repack your repository anyway, I do not think it is such a big downside that this mode misses a corrupt objects, and the 1 out of 4 kinds of objects, i.e. blobs, occupy major part of the repository storage, so this new mode probably makes sense.

It actually makes a ton of sense as a kind of light-weight check ;-) Try it, it is really much, much faster than a full fsck.

Quoted 35 lines
Quoted 21 lines
t/t1450-fsck.sh +13 -0
index 922c346..2863a8a 100755
@@ -431,4 +431,26 @@ test_expect_success 'fsck notices ref pointing to missing tag' '
 	test_must_fail git -C missing fsck
 '
 
+test_expect_success 'fsck --quick' '
+	rm -rf quick &&
+	git init quick &&
+	(
+		cd quick &&
+		touch empty &&
+		git add empty &&
+		test_commit empty &&
+		empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 &&
+		rm -f $empty &&
+		echo invalid >$empty &&
+		test_must_fail git fsck --strict &&
+		git fsck --strict --quick &&

t/t1450-fsck.sh test_expect_success 'fsck notices ref pointing to missing tag' ' · line 456

Quoted 10 lines
t/t1450-fsck.sh +9 -0
+		tree=$(git rev-parse HEAD:) &&
+		suffix=${tree#??} &&
+		tree=.git/objects/${tree%$suffix}/$suffix &&
+		rm -f $tree &&
+		echo invalid >$tree &&
+		test_must_fail git fsck --strict --quick
+	)
+'
+
 test_done

I see a few impedance mismatch here. For --quick, I would have expected that the addition would be in t/perf/, not here.

Quoted 8 lines

Also the fact that quickness comes by cheating on blobs is an implementation detail; in the future, perhaps somebody may come up with a way to do a quick fsck while making sure blob corruption is also detected. The new test that expects "--quick" to ignore a corrupt blob forbids such a progress.

If the option name was "--ignore-corrupt-blob", then the above change is 100% justified, though.

The meaning of "quick" that I was thinking of was not the same as "fast", but more like "just a quick check". As in "quick & dirty" ;-)

The point is not to ignore corrupt blobs, by the way, it is to check the connectivity only, and save substantial amounts of time doing so.

Can you think of a name for the option that is as short as --quick but means the same as --connectivity-only?

Ciao,
Dscho

#228 lore raw

Re: [PATCH v6 17/19] fsck: Introduce `git fsck --quick`

Quoted 2 lines · Johannes Schindelin

Can you think of a name for the option that is as short as --quick but means the same as --connectivity-only?

No I can't. I think --connectivity-only is a very good name that is unfortunately a mouthful, I agree that we need a name that is as short as --xxxxx that means the same as --connectivity-only. I do not think --quick is that word; it does not mean such a thing.

#229 lore raw

Re: [PATCH v6 17/19] fsck: Introduce `git fsck --quick`

Quoted 9 lines · Junio C Hamano
Quoted 2 lines · Johannes Schindelin

Can you think of a name for the option that is as short as --quick but means the same as --connectivity-only?

No I can't. I think --connectivity-only is a very good name that is unfortunately a mouthful, I agree that we need a name that is as short as --xxxxx that means the same as --connectivity-only. I do not think --quick is that word; it does not mean such a thing.

How about --linkage or --links?

Signature · 1 line
Scott Schmit
#230 lore raw

Re: [PATCH v6 17/19] fsck: Introduce `git fsck --quick`

Quoted 6 lines · Scott Schmit
Quoted 5 lines · Junio C Hamano
Quoted 2 lines · Johannes Schindelin

Can you think of a name for the option that is as short as --quick but means the same as --connectivity-only?

Quoted 6 lines
Quoted 4 lines

No I can't. I think --connectivity-only is a very good name that is unfortunately a mouthful, I agree that we need a name that is as short as --xxxxx that means the same as --connectivity-only. I do not think --quick is that word; it does not mean such a thing.

How about --linkage or --links?

Even though "link" may be shorter than "connectivity", the real difficulty is to come up with a phrase that conveys the "-only" part of the fully spelled name, which is more important, without spending 5 letters that take to say "-only".

#231 lore raw

Re: [PATCH v6 17/19] fsck: Introduce `git fsck --quick`

In reply to Junio C Hamano
Quoted 9 lines · Junio C Hamano
Quoted 2 lines · Johannes Schindelin

Can you think of a name for the option that is as short as --quick but means the same as --connectivity-only?

No I can't. I think --connectivity-only is a very good name that is unfortunately a mouthful, I agree that we need a name that is as short as --xxxxx that means the same as --connectivity-only. I do not think --quick is that word; it does not mean such a thing.

--connectivity-only says that "of all the things that fsck can do, skip everything except for the connectivity check". But the switch really affects not the connectivity part of the checks (that part is done in either case), but the blob part. So, if we ignore the length of the option name for a moment, it seems like the options should be something like --check-blob-integrity/--no-check-blob-integrity. The default would remain --check-blob-integrity of course, but

* Someday there might be a config setting that people can use to change the default behavior of fsck to --no-check-blob-integrity.
* Someday there might be other expensive types of checks [1] that we want to turn on/off independent of blob integrity checks.

But now that I'm writing this, a silly question occurs to me: Do we need an overall option like this at all? If I demote all blob-integrity checks to "ignore" via the mechanism that you have added, then shouldn't fsck automatically detect that it doesn't have to open the blobs at all and enable this speedup automatically? So maybe --(no-)?check-blob-integrity is actually a shorthand for turning a few more specific checks on/off at once.

As for thinking of a shorter name for the option: assuming the blob integrity checks can be turned on and off independently as described above, then I think it is reasonable to *also* add a --quick option defined as

--quick: Skip some expensive checks, dramatically reducing the
runtime of git fsck. Currently this is equivalent to --no-check-blob-integrity.

In the future if we invent other expensive checks we might also add them to the list of things that are skipped by --quick.

Michael

[1] For example, if LFS or something like it every became part of standard Git, one could imagine a super-expensive --check-lfs-object-availability check that would would default to OFF but sometimes turn on by hand.

Signature · 2 lines
Michael Haggerty
[email protected]
#232 lore raw

RE: [PATCH v6 17/19] fsck: Introduce `git fsck --quick`

Quoted 6 lines · Michael Haggerty
Quoted 5 lines · Junio C Hamano
Quoted 2 lines · Johannes Schindelin

Can you think of a name for the option that is as short as --quick but means the same as --connectivity-only?

Quoted 6 lines
Quoted 4 lines

No I can't. I think --connectivity-only is a very good name that is unfortunately a mouthful, I agree that we need a name that is as short as --xxxxx that means the same as --connectivity-only. I do not think --quick is that word; it does not mean such a thing.

--connectivity-only says that "of all the things that fsck can do, skip

everything

Quoted 2 lines

except for the connectivity check". But the switch really affects not the connectivity part of the checks (that part is done in either case), but

the blob

Quoted 1 line

part. So, if we ignore the length of the option name for a moment, it

seems like

Quoted 1 line

the options should be something like

--check-blob-integrity/`--no-check-blob-

Quoted 1 line

integrity. The default would remain --check-blob-integrity` of course,

but

Quoted 2 lines

* Someday there might be a config setting that people can use to change

the

Quoted 2 lines

default behavior of fsck to --no-check-blob-integrity.
* Someday there might be other expensive types of checks [1] that we want

to

Quoted 3 lines

turn on/off independent of blob integrity checks.

But now that I'm writing this, a silly question occurs to me: Do we need

an

Quoted 1 line

overall option like this at all? If I demote all blob-integrity checks to

"ignore"

Quoted 2 lines

via the mechanism that you have added, then shouldn't fsck automatically detect that it doesn't have to open the blobs at all and enable this

speedup

Quoted 1 line

automatically? So maybe --(no-)?check-blob-integrity is actually a

shorthand

Quoted 3 lines

for turning a few more specific checks on/off at once.

As for thinking of a shorter name for the option: assuming the blob

integrity

Quoted 1 line

checks can be turned on and off independently as described above, then I

think

Quoted 7 lines

it is reasonable to *also* add a --quick option defined as

--quick: Skip some expensive checks, dramatically reducing the
runtime of git fsck. Currently this is equivalent to --no-check-blob-integrity.

In the future if we invent other expensive checks we might also add them

to the

Quoted 1 line

list of things that are skipped by --quick.

Synonym suggestions: --links or --relations
I was going to include --refs but that may be ambiguous. Links also has meaning so it's probably out and --hitch may just be silly and needlessly introducing a new term.

Cheers,
Randall

-- Brief whoami: NonStop&UNIX developer since approximately UNIX(421664400)/NonStop(211288444200000000)
-- In my real life, I talk too much.

#233 lore raw

RE: [PATCH v6 17/19] fsck: Introduce `git fsck --quick`

Hi Randall,

Quoted 10 lines · Randall S. Becker
Quoted 8 lines · Michael Haggerty

As for thinking of a shorter name for the option: assuming the blob integrity checks can be turned on and off independently as described above, then I think it is reasonable to *also* add a --quick option defined as

--quick: Skip some expensive checks, dramatically reducing the
runtime of git fsck. Currently this is equivalent to --no-check-blob-integrity.

Quoted 7 lines
Quoted 2 lines

In the future if we invent other expensive checks we might also add them to the list of things that are skipped by --quick.

Synonym suggestions: --links or --relations
I was going to include --refs but that may be ambiguous. Links also has meaning so it's probably out and --hitch may just be silly and needlessly introducing a new term.

I appreciate your input, but I think in this case, "links" and "relations" would just add new terminology, and I would like to keep using existing terminology as much as possible (because we already have a confusingly large glossary). I also see "link" as a problematic term because it resembles "gitlink" -- which means something entirely different.

My favorite is still --quick because in contrast to Junio, to me it *has* a connotation of "less thoroughly". "Get rich quick" just does not mean "Earn a lot of money by doing a thorough job, just faster than you usually would".

If Junio insists, I will of course rename it to --skip-blobs because that is really what we do. However, it has been my experience over and over again that letting implementation details bleed through to the user interface always comes back to haunt you[*1*]. In this case, the purpose of the option really just was to cut a few corners to run git fsck more quickly. The fact that the corner I cut here is to skip unpacking of the blobs just happens to be the implementation detail.

So, Junio, what is it: keep --quick and clarify in the documentation that we cut corners (and which corners), or rename it to --skip-blobs? Your call.

Ciao,
Dscho

Footnote *1*: You would not believe how often I had to apologize for renaming the edit-patch-series script to interactive rebase. You see, technically it is correct to call it an interactive rebase: it really is that, from a purely technical, soul-less point of view. From the users' point of view, however, the name edit-patch-series would relate exactly what the command is *about*, as opposed to *how* it works. To most users, calling it "rebase -i" is as understandable as "sympodial fasciculation and regrafting of disconnate vernates" (and don't ask me what that even means).

#234 lore raw

Re: [PATCH v6 17/19] fsck: Introduce `git fsck --quick`

In reply to Michael Haggerty

Hi Michael,

Quoted 11 lines · Michael Haggerty
Quoted 9 lines · Junio C Hamano
Quoted 2 lines · Johannes Schindelin

Can you think of a name for the option that is as short as --quick but means the same as --connectivity-only?

No I can't. I think --connectivity-only is a very good name that is unfortunately a mouthful, I agree that we need a name that is as short as --xxxxx that means the same as --connectivity-only. I do not think --quick is that word; it does not mean such a thing.

Quoted 4 lines

--connectivity-only says that "of all the things that fsck can do, skip everything except for the connectivity check". But the switch really affects not the connectivity part of the checks (that part is done in either case), but the blob part.

Right, so --skip-blobs would be a better name, I guess, if you follow Junio's reasoning.

But...

Quoted 9 lines

[...]
As for thinking of a shorter name for the option: assuming the blob integrity checks can be turned on and off independently as described above, then I think it is reasonable to *also* add a --quick option defined as

--quick: Skip some expensive checks, dramatically reducing the
runtime of git fsck. Currently this is equivalent to --no-check-blob-integrity.

This was my idea, without bothering to introduce the --no-check-blob-integrity. I was really thinking along the lines: If you just want to check quickly whether your repository is in good shape, without wanting to check too deeply, then --quick is your friend. I just *happened* to think of skipping blobs as a way to trade off accuracy for speed, but really, the reason why I introduced --quick was to have a way to check much faster if somewhat less thoroughly.

Ciao,
Dscho

#235 lore raw

Re: [PATCH v6 17/19] fsck: Introduce `git fsck --quick`

In reply to Michael Haggerty
Quoted 5 lines · Michael Haggerty

But now that I'm writing this, a silly question occurs to me: Do we need an overall option like this at all? If I demote all blob-integrity checks to "ignore" via the mechanism that you have added, then shouldn't fsck automatically detect that it doesn't have to open the blobs at all and enable this speedup automatically?

That's brilliant.

Just to make sure I am reading you correctly, you mean the current overall structure:

	if (! "is the blob loadable and well-formed?") {
		report("BAD BLOB");
                ... which is equivalent to ...
                if ("is bad_blob ignored?")
			; /* no-op */
		else {
			output "BAD BLOB";
                        if ("is bad_blob an error?")
				return 1; /* error */
		}
	}
        ... other checks ...

can be turned into this structure:

        if ("is bad_blob ignored?")
		;
	else if (! "is the blob loadable and well-formed?") {
		report("BAD BLOB");
                ... which would be equivalent to ...
		output "BAD BLOB";
                if ("is bad_blob an error?")
			return 1; /* error */
	}
        ... other checks ...

I think that makes tons of sense. With one minor caveat. In the above "rewrite" I deliberately described report() in the updated flow to always output, but that would force all checkers to adopt "do not unconditionally check; if we do not report, do not even bother checking", which (1) would be a large change to what Dscho currently have, and (2) might not apply to certain kinds of error conditions.

But that minor caveat is easily addressed by keeping the "if we are set to ignore this error, just return 0" in report(). Some codepaths (like the "BAD BLOB" above) may not exercise it by bypassing the call to report() upfront and that is perfectly fine.

I like that idea.

Quoted 9 lines

So maybe
--(no-)?check-blob-integrity is actually a shorthand for turning a few more specific checks on/off at once.

As for thinking of a shorter name for the option: assuming the blob integrity checks can be turned on and off independently as described above, then I think it is reasonable to *also* add a --quick option defined as

Quoted 6 lines

--quick: Skip some expensive checks, dramatically reducing the
runtime of git fsck. Currently this is equivalent to --no-check-blob-integrity.

In the future if we invent other expensive checks we might also add them to the list of things that are skipped by --quick.

Yes, that is doubly brilliant. Taken together with the auto-skipping of the checks based on the report settings, it makes it unnecessary to even introduce --[no-]check-blob-integrity or any other new knobs.

Very well analysed. I am happy with the "--quick" with that definition.

Thanks.

#236 lore raw

Re: [PATCH v6 17/19] fsck: Introduce `git fsck --quick`

Hi Junio,

Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Michael Haggerty

But now that I'm writing this, a silly question occurs to me: Do we need an overall option like this at all? If I demote all blob-integrity checks to "ignore" via the mechanism that you have added, then shouldn't fsck automatically detect that it doesn't have to open the blobs at all and enable this speedup automatically?

Quoted 6 lines

That's brilliant.

Just to make sure I am reading you correctly, you mean the current overall structure:

[...]

The way I read Michael's mail, he actually meant something different: if all of the blob-related errors/warnings are switched to "ignore", simply skip unpacking the blobs. If I read this correctly, I would like to point out that introducing a future blob-related check would require scripts to be changed to benefit from the speed-up, unless the --quick option is *also* introduced.

The way I read your suggestion, however, was to introduce *yet another* message ID: BAD_BLOB. If that one is turned to "ignore", we simply won't look at blobs' contents at all.

I like that idea, together with:

Quoted 3 lines
Quoted 3 lines

--quick: Skip some expensive checks, dramatically reducing the
runtime of git fsck. Currently this is equivalent to --no-check-blob-integrity.

... where this would become -c fsck.badBlob=ignore.

Quoted 10 lines
Quoted 2 lines

In the future if we invent other expensive checks we might also add them to the list of things that are skipped by --quick.

Yes, that is doubly brilliant. Taken together with the auto-skipping of the checks based on the report settings, it makes it unnecessary to even introduce --[no-]check-blob-integrity or any other new knobs.

Very well analysed. I am happy with the "--quick" with that definition.

Did I understand you correctly? If so, I will gladly implement this tomorrow and send out v7.

Ciao,
Dscho

#237 lore raw

Re: [PATCH v6 17/19] fsck: Introduce `git fsck --quick`

Quoted 4 lines · Johannes Schindelin
Quoted 2 lines · On 2015-06-21 19:15, Junio C Hamano wrote: Michael Haggerty…

That's brilliant.

Quoted 8 lines
Quoted 4 lines

Just to make sure I am reading you correctly, you mean the current overall structure:

[...]

The way I read Michael's mail, he actually meant something different:
if all of the blob-related errors/warnings are switched to "ignore", simply skip unpacking the blobs.

That is how I read his mail, too.

But because IIRC we do not check anything special with blob other than we can read it correctly, my description of "overall structure" stayed at a very high conceptual level. The unpacking may happen at a much higher level in the code, i.e. it comes way before this part of the logic flow:

        if ("is bad_blob ignored?")
		;
	else if (! "is the blob loadable and well-formed?") {

in which case "is bad blobs ignored?" check may have to happen before we unpack the object.

And I do not suggest introducing yet another BAD_BLOB error class; I would have guessed that you already have an error class for objects that are not stored correctly (be it truncated loose object, checksum mismatch in the packed base object, or corrupt delta in pack).

It so happens that blob is the only type of object that does not have outgoing links that is needed for connectivity check, so even if you allow to ignore "error class for objects that are not stored correctly", you would still have to read trees, commits and tags; it would be a natural consequence of ignoring that class of errors that you would get a quick-and-dirty fsck by not unpacking blobs.

Of course, that assumes that you can tell an object is a blob without unpacking. If a tree entry mentions an object to be a blob by having 100644 as its mode, unless you unpack the object pointed at by that tree entry to make sure it is a blob, you wouldn't be able to detect a case where a non-blob object is stored with 100644 mode, which would be an error in the containing tree object that we may want to detect. I am not sure if "skipping inflation of blobs, but still ensure connectivity and tree integrity" is really a viable mode of quick-and-dirty operation. I would imagine you would need to lose a bit more than "we don't bother reading blobs" (which is OK by me, but I am just pointing out that (1) I do not mean to say we should add BAD_BLOB as a new class, and (2) the automatic bypass Michael's --quick skips may not be limited to suppressing "we cannot read this blob object" class, but also need to suppress checks for some form of tree integrity violation).

Thanks.

#238 lore raw

Re: [PATCH v6 17/19] fsck: Introduce `git fsck --quick`

Quoted 7 lines · Junio C Hamano

Of course, that assumes that you can tell an object is a blob without unpacking. If a tree entry mentions an object to be a blob by having 100644 as its mode, unless you unpack the object pointed at by that tree entry to make sure it is a blob, you wouldn't be able to detect a case where a non-blob object is stored with 100644 mode, which would be an error in the containing tree object that we may want to detect.

Heh, I was being stupid here. Of course, you can tell an object is a blob without fully inflating it (we should already be doing that in sha1_object_info(), inflating only the object header in loose objects or inflating only the early parts of delta in packs to follow the delta chain to learn the type of the object), and that would certainly save us substantial zlib cost.

Sorry about the noise.

#239 lore raw

Re: [PATCH v6 17/19] fsck: Introduce `git fsck --quick`

In reply to Junio C Hamano

Hi Junio,

Quoted 27 lines · Junio C Hamano
Quoted 4 lines · Johannes Schindelin
Quoted 2 lines · On 2015-06-21 19:15, Junio C Hamano wrote: Michael Haggerty…

That's brilliant.

Quoted 8 lines
Quoted 4 lines

Just to make sure I am reading you correctly, you mean the current overall structure:

[...]

The way I read Michael's mail, he actually meant something different:
if all of the blob-related errors/warnings are switched to "ignore", simply skip unpacking the blobs.

That is how I read his mail, too.

But because IIRC we do not check anything special with blob other than we can read it correctly, my description of "overall structure" stayed at a very high conceptual level. The unpacking may happen at a much higher level in the code, i.e. it comes way before this part of the logic flow:

        if ("is bad_blob ignored?")
		;
	else if (! "is the blob loadable and well-formed?") {
Quoted 7 lines

in which case "is bad blobs ignored?" check may have to happen before we unpack the object.

And I do not suggest introducing yet another BAD_BLOB error class; I would have guessed that you already have an error class for objects that are not stored correctly (be it truncated loose object, checksum mismatch in the packed base object, or corrupt delta in pack).

Sadly, there is no BAD_BLOB class. The reason is that we actually perform no test on blobs, as you pointed out, except for the implicit one: read it as a blob object.

And reading them even only partially would still imply a lot of I/O, taking away much of the performance improvement I wanted to achieve here.

Further, please note that the --quick option *solely* impacts git fsck, not git receive-pack, because we actually really skipped everything except the connectivity test.

To allow this discussion to be resolved without further ado, I therefore renamed the --quick option to --connectivity-only, as even I realize that there is not much of a check left if not even author or committer lines are tested.

Ciao,
Dscho

#240 lore raw

Re: [PATCH v6 17/19] fsck: Introduce `git fsck --quick`

In reply to Johannes Schindelin
Quoted 7 lines · Johannes Schindelin
Quoted 5 lines

Jokes aside, given that you should regularly repack your repository anyway, I do not think it is such a big downside that this mode misses a corrupt objects, and the 1 out of 4 kinds of objects, i.e. blobs, occupy major part of the repository storage, so this new mode probably makes sense.

It actually makes a ton of sense as a kind of light-weight check ;-)

Yes, didn't I agree that it makes sense already?

Quoted 2 lines

The meaning of "quick" that I was thinking of was not the same as "fast", but more like "just a quick check". As in "quick & dirty" ;-)

Sure.

Quoted 2 lines

The point is not to ignore corrupt blobs, by the way, it is to check the connectivity only, and save substantial amounts of time doing so.

Yeah, I understand that; after all, that is exactly why I said "make sure it does not notice corrupt blobs" is not a good test.

On the other hand, you are also checking that it notices a broken tree (which makes it impossible to complete connectivity check), which is a good test.

#241 lore raw

PATCH v6 18/19 fsck: git receive-pack: support excluding objects from fsck'ing

In reply to Johannes Schindelin

The optional new config option receive.fsck.skiplist specifies the path to a file listing the names, i.e. SHA-1s, one per line, of objects that are to be ignored by git receive-pack when receive.fsckObjects = true.

This is extremely handy in case of legacy repositories where it would cause more pain to change incorrect objects than to live with them (e.g. a duplicate 'author' line in an early commit object).

The intended use case is for server administrators to inspect objects that are reported by git push as being too problematic to enter the repository, and to add the objects' SHA-1 to a (preferably sorted) file when the objects are legitimate, i.e. when it is determined that those problematic objects should be allowed to enter the server.

---
 Documentation/config.txt        |  7 ++++++
 builtin/receive-pack.c          |  8 ++++++
 fsck.c                          | 54 +++++++++++++++++++++++++++++++++++++++++
 fsck.h                          |  1 +
 t/t5504-fetch-receive-strict.sh | 12 +++++++++
 5 files changed, 82 insertions(+)
Documentation/config.txt +7 -0
index 41fd460..5f45115 100644
@@ -2230,6 +2230,13 @@ which would not pass pushing when `receive.fsckObjects = true`, allowing
 the host to accept repositories with certain known issues but still catch
 other issues.
 
+receive.fsck.skipList::
+	The path to a sorted list of object names (i.e. one SHA-1 per
+	line) that are known to be broken in a non-fatal way and should
+	be ignored. This feature is useful when an established project
+	should be accepted despite early commits containing errors that
+	can be safely ignored such as invalid committer email addresses.
+
 receive.unpackLimit::
 	If the number of objects received in a push is below this
 	limit then the objects will be unpacked into loose object
builtin/receive-pack.c +8 -0
index 3afe8f8..80574f9 100644
@@ -117,6 +117,14 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if (strcmp(var, "receive.fsck.skiplist") == 0) {
+		const char *path = is_absolute_path(value) ?
+			value : git_path("%s", value);
+		strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
+			fsck_msg_types.len ? ',' : '=', path);
+		return 0;
+	}
+
 	if (skip_prefix(var, "receive.fsck.", &var)) {
 		if (is_valid_msg_type(var, value))
 			strbuf_addf(&fsck_msg_types, "%c%s=%s",
fsck.c +54 -0

78 lines not on this page · raw message

fsck.h +1 -0
index 7e49372..cab9c65 100644
@@ -33,6 +33,7 @@ struct fsck_options {
 	fsck_error error_func;
 	unsigned strict:1;
 	int *msg_type;
+	struct sha1_array *skiplist;
 };
 
 #define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL }
t/t5504-fetch-receive-strict.sh +12 -0
index cb077b7..1ada54c 100755
@@ -123,6 +123,18 @@ committer Bugs Bunny <[email protected]> 1234567890 +0000
 This commit object intentionally broken
 EOF
 
+test_expect_success 'push with receive.fsck.skiplist' '
+	commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
+	git push . $commit:refs/heads/bogus &&
+	rm -rf dst &&
+	git init dst &&
+	git --git-dir=dst/.git config receive.fsckobjects true &&
+	test_must_fail git push --porcelain dst bogus &&
+	git --git-dir=dst/.git config receive.fsck.skiplist SKIP &&
+	echo $commit >dst/.git/SKIP &&
+	git push --porcelain dst bogus
+'
+
 test_expect_success 'push with receive.fsck.missingemail=warn' '
 	commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
 	git push . $commit:refs/heads/bogus &&
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#242 lore raw

Re: [PATCH v6 18/19] fsck: git receive-pack: support excluding objects from fsck'ing

builtin/receive-pack.c static int receive_pack_config(const char *var, const char *value, void *cb) · line 122

Quoted 3 lines · Johannes Schindelin
builtin/receive-pack.c +3 -0
+	if (strcmp(var, "receive.fsck.skiplist") == 0) {
+		const char *path = is_absolute_path(value) ?
+			value : git_path("%s", value);

This "either absolute or inside $GIT_DIR" looks somewhat strange to me. Shouldn't we mimick what "git config --path" does instead?

#243 lore raw

Re: [PATCH v6 18/19] fsck: git receive-pack: support excluding objects from fsck'ing

Hi Junio,

Quoted 8 lines · Junio C Hamano

Review

Quoted 3 lines · Johannes Schindelin
(quoted diff) +3 -0
+	if (strcmp(var, "receive.fsck.skiplist") == 0) {
+		const char *path = is_absolute_path(value) ?
+			value : git_path("%s", value);

This "either absolute or inside $GIT_DIR" looks somewhat strange to me. Shouldn't we mimick what "git config --path" does instead?

Okay. That would also support user paths.

There is a problem, though: git_config_pathname() accepts a const char ** parameter to set the path, yet I need to free() that pointer afterwards because it has been obtained through expand_user_path() which detaches that buffer from a strbuf.

In regular use cases, that does not matter much because the path obtained via git_config_pathname() is typically stored in a global variable, but in my case, I append it to a global variable.

Of course I could cast the value to a char * and free() it, but that would assume too much about the implementation detail of git_config_pathname() for my taste.

The easiest cop out would be to recapitulate the code in git_config_pathname(), but I think the correct solution would be to change the signature of git_config_pathname() to accept a char ** instead. Do you agree? However, the diff looks really ugly:

-- snipsnap --

builtin/commit.c +1 -1
index 254477f..946b31b 100644
@@ -1494,7 +1494,7 @@ static int git_commit_config(const char *k, const char *v, void *cb)
 	int status;
 
 	if (!strcmp(k, "commit.template"))
-		return git_config_pathname(&template_file, k, v);
+		return git_config_pathname((char **)&template_file, k, v);
 	if (!strcmp(k, "commit.status")) {
 		include_status = git_config_bool(k, v);
 		return 0;
builtin/config.c +1 -1
index 7188405..a249faa 100644
@@ -130,7 +130,7 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value
 		else
 			sprintf(value, "%d", v);
 	} else if (types == TYPE_PATH) {
-		if (git_config_pathname(&vptr, key_, value_) < 0)
+		if (git_config_pathname((char **)&vptr, key_, value_) < 0)
 			return -1;
 		must_free_vptr = 1;
 	} else if (value_) {
builtin/init-db.c +2 -1
index 4335738..0572cae 100644
@@ -177,7 +177,8 @@ free_return:
 static int git_init_db_config(const char *k, const char *v, void *cb)
 {
 	if (!strcmp(k, "init.templatedir"))
-		return git_config_pathname(&init_db_template_dir, k, v);
+		return git_config_pathname((char **)&init_db_template_dir,
+				k, v);
 
 	return 0;
 }
builtin/log.c +2 -1
index 8781049..8751173 100644
@@ -743,7 +743,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
 	if (!strcmp(var, "format.signature"))
 		return git_config_string(&signature, var, value);
 	if (!strcmp(var, "format.signaturefile"))
-		return git_config_pathname(&signature_file, var, value);
+		return git_config_pathname((char **)&signature_file,
+				var, value);
 	if (!strcmp(var, "format.coverletter")) {
 		if (value && !strcasecmp(value, "auto")) {
 			config_cover_letter = COVER_AUTO;
cache.h +1 -1
index 4f55466..19af52e 100644
@@ -1442,7 +1442,7 @@ extern int git_config_bool_or_int(const char *, const char *, int *);
 extern int git_config_bool(const char *, const char *);
 extern int git_config_maybe_bool(const char *, const char *);
 extern int git_config_string(const char **, const char *, const char *);
-extern int git_config_pathname(const char **, const char *, const char *);
+extern int git_config_pathname(char **, const char *, const char *);
 extern int git_config_set_in_file(const char *, const char *, const char *);
 extern int git_config_set(const char *, const char *);
 extern int git_config_parse_key(const char *, char **, int *);
config.c +7 -5
index 29fa012..51781b8 100644
@@ -670,7 +670,7 @@ int git_config_string(const char **dest, const char *var, const char *value)
 	return 0;
 }
 
-int git_config_pathname(const char **dest, const char *var, const char *value)
+int git_config_pathname(char **dest, const char *var, const char *value)
 {
 	if (!value)
 		return config_error_nonbool(var);
@@ -714,7 +714,8 @@ static int git_default_core_config(const char *var, const char *value)
 	}
 
 	if (!strcmp(var, "core.attributesfile"))
-		return git_config_pathname(&git_attributes_file, var, value);
+		return git_config_pathname((char **)&git_attributes_file,
+				var, value);
 
 	if (!strcmp(var, "core.bare")) {
 		is_bare_repository_cfg = git_config_bool(var, value);
@@ -862,7 +863,7 @@ static int git_default_core_config(const char *var, const char *value)
 		return git_config_string(&askpass_program, var, value);
 
 	if (!strcmp(var, "core.excludesfile"))
-		return git_config_pathname(&excludes_file, var, value);
+		return git_config_pathname((char **)&excludes_file, var, value);
 
 	if (!strcmp(var, "core.whitespace")) {
 		if (!value)
@@ -989,7 +990,8 @@ static int git_default_push_config(const char *var, const char *value)
 static int git_default_mailmap_config(const char *var, const char *value)
 {
 	if (!strcmp(var, "mailmap.file"))
-		return git_config_pathname(&git_mailmap_file, var, value);
+		return git_config_pathname((char **)&git_mailmap_file,
+				var, value);
 	if (!strcmp(var, "mailmap.blob"))
 		return git_config_string(&git_mailmap_blob, var, value);
 
@@ -1506,7 +1508,7 @@ int git_configset_get_pathname(struct config_set *cs, const char *key, const cha
 {
 	const char *value;
 	if (!git_configset_get_value(cs, key, &value))
-		return git_config_pathname(dest, key, value);
+		return git_config_pathname((char **)dest, key, value);
 	else
 		return 1;
 }
diff.c +2 -1
index 87b16d5..e029b75 100644
@@ -204,7 +204,8 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
 	if (!strcmp(var, "diff.wordregex"))
 		return git_config_string(&diff_word_regex_cfg, var, value);
 	if (!strcmp(var, "diff.orderfile"))
-		return git_config_pathname(&diff_order_file_cfg, var, value);
+		return git_config_pathname((char **)&diff_order_file_cfg,
+				var, value);
 
 	if (!strcmp(var, "diff.ignoresubmodules"))
 		handle_ignore_submodules_arg(&default_diff_options, value);
#244 lore raw

Re: [PATCH v6 18/19] fsck: git receive-pack: support excluding objects from fsck'ing

Quoted 4 lines · Johannes Schindelin

There is a problem, though: git_config_pathname() accepts a const char ** parameter to set the path, yet I need to free() that pointer afterwards because it has been obtained through expand_user_path() which detaches that buffer from a strbuf.

"I have 'const char *' because I do not ever change the string myself after getting it from an API function, but free() does not want to free a const pointer" occurs sometimes in our codebase and it is OK to cast the constness away (many callsites to free() already do so).

#245 lore raw

Re: [PATCH v6 18/19] fsck: git receive-pack: support excluding objects from fsck'ing

In reply to Johannes Schindelin

fsck.c static int report(struct fsck_options *options, struct object *object, · line 286

Quoted 12 lines · Johannes Schindelin
fsck.c +4 -0
@@ -227,6 +277,10 @@ static int report(struct fsck_options *options, struct object *object,
        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)

I just double checked this patch because I wanted to make sure this was applied in the
report() function (i.e. behave as if FSCK_IGNORE was specified for specific objects on
the skip list), and I am happy to see that it indeed is the case.

That was because I briefly feared that skip could be done before going through the usual
verification chain, which would have been very wrong (e.g. we may want not to hear about
missing tagger in v2.6.11-tree tag, but nevertheless we would want to check all the tree
contents pointed at by that tag, as that tree may not be reachable by any other way).

So this one looks good.

#246 lore raw

Re: [PATCH v6 18/19] fsck: git receive-pack: support excluding objects from fsck'ing

Hi Junio,

Quoted 21 lines · Junio C Hamano

fsck.c static int report(struct fsck_options *options, struct object *object, · line 286

Quoted 12 lines · Johannes Schindelin
fsck.c +4 -0
@@ -227,6 +277,10 @@ static int report(struct fsck_options *options, struct object *object,
        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)

I just double checked this patch because I wanted to make sure this was applied in the
report() function (i.e. behave as if FSCK_IGNORE was specified for specific objects on
the skip list), and I am happy to see that it indeed is the case.

Quoted 8 lines

That was because I briefly feared that skip could be done before going through the usual
verification chain, which would have been very wrong (e.g. we may want not to hear about
missing tagger in v2.6.11-tree tag, but nevertheless we would want to check all the tree
contents pointed at by that tag, as that tree may not be reachable by any other way).

To be honest, an earlier iteration actually did have that test much earlier in the call chain, but I had changed it to the current location in v5.

My rationale was slightly different from yours: I wanted to affect the performance as little as possible. So looking up each and every object in the skip list (which I expect to be relatively small) seemed to be wasteful. And then it occurred to me that it would make much more sense to just make the skip-list functionality equivalent to the "ignore" message type.

It just occurred to me, however, that one thing is possibly surprising with either version of the skip list functionality: if a certain object is corrupt on disk, it cannot be skipped via the skip-list, as the object is *still* unpacked (which would fail in the case of a corrupt object).

I will document that in the man page.

Ciao,
Dscho

#247 lore raw

PATCH v6 19/19 fsck: support ignoring objects in `git fsck` via fsck.skiplist

In reply to Johannes Schindelin

Identical to support in git receive-pack for the config option receive.fsck.skiplist, we now support ignoring given objects in git fsck via fsck.skiplist` altogether.

This is extremely handy in case of legacy repositories where it would cause more pain to change incorrect objects than to live with them (e.g. a duplicate 'author' line in an early commit object).

---
 Documentation/config.txt |  7 +++++++
 builtin/fsck.c           | 10 ++++++++++
 2 files changed, 17 insertions(+)
Documentation/config.txt +7 -0
index 5f45115..5aba63a 100644
@@ -1261,6 +1261,13 @@ that setting `fsck.missingemail = ignore` will hide that issue.
 This feature is intended to support working with legacy repositories
 which cannot be repaired without disruptive changes.
 
+fsck.skipList::
+	The path to a sorted list of object names (i.e. one SHA-1 per
+	line) that are known to be broken in a non-fatal way and should
+	be ignored. This feature is useful when an established project
+	should be accepted despite early commits containing errors that
+	can be safely ignored such as invalid committer email addresses.
+
 gc.aggressiveDepth::
 	The depth parameter used in the delta compression
 	algorithm used by 'git gc --aggressive'.  This defaults
builtin/fsck.c +10 -0
index 75fcb5f..ce538ac 100644
@@ -54,6 +54,16 @@ static int fsck_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if (strcmp(var, "fsck.skiplist") == 0) {
+		const char *path = is_absolute_path(value) ?
+			value : git_path("%s", value);
+		struct strbuf sb = STRBUF_INIT;
+		strbuf_addf(&sb, "skiplist=%s", path);
+		fsck_set_msg_types(&fsck_obj_options, sb.buf);
+		strbuf_release(&sb);
+		return 0;
+	}
+
 	return git_default_config(var, value, cb);
 }
 
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#248 lore raw

Re: [PATCH v6 19/19] fsck: support ignoring objects in `git fsck` via fsck.skiplist

builtin/fsck.c static int fsck_config(const char *var, const char *value, void *cb) · line 59

Quoted 3 lines · Johannes Schindelin
builtin/fsck.c +3 -0
+	if (strcmp(var, "fsck.skiplist") == 0) {
+		const char *path = is_absolute_path(value) ?
+			value : git_path("%s", value);

Same comment as 18/19.

#249 lore raw

v7 cover Introduce an internal API to interact with the fsck machinery

In reply to Johannes Schindelin

At the moment, the git-fsck's integrity checks are targeted toward the end user, i.e. the error messages are really just messages, intended for human consumption.

Under certain circumstances, some of those errors should be allowed to be turned into mere warnings, though, because the cost of fixing the issues might well be larger than the cost of carrying those flawed objects. For example, when an already-public repository contains a commit object with two authors for years, it does not make sense to force the maintainer to rewrite the history, affecting all contributors negatively by forcing them to update.

This branch introduces an internal fsck API to be able to turn some of the errors into warnings, and to make it easier to call the fsck machinery from elsewhere in general.

I am proud to report that this work has been sponsored by GitHub.

Changes since v6:

- camelCased message IDs

- multiple author checking now as suggested by Junio

- renamed --quick to --connectivity-only, better commit message

- fsck.skipList is now handled correctly (and not mistaken for a message type setting)

- fsck.skipList can handle user paths now

- index-pack configures the walk function in a more logical place now

- simplified code by avoiding working on partial strings (i.e. removed substrcmp()). This saves 10 lines. To accomodate parsing config variables directly, we now work on lowercased message IDs; unfortunately this means that we cannot use them in append_msg_id() because that function wants to append camelCased message IDs.

Interdiff below diffstat.

Johannes Schindelin (19):
fsck: Introduce fsck options
fsck: Introduce identifiers for fsck messages
fsck: Provide a function to parse fsck message IDs
fsck: Offer a function to demote fsck errors to warnings fsck (receive-pack): Allow demoting errors to warnings
fsck: Report the ID of the error/warning
fsck: Make fsck_ident() warn-friendly
fsck: Make fsck_commit() warn-friendly
fsck: Handle multiple authors in commits specially
fsck: Make fsck_tag() warn-friendly
fsck: Add a simple test for receive.fsck.<msg-id>
fsck: Disallow demoting grave fsck errors to warnings
fsck: Optionally ignore specific fsck issues completely
fsck: Allow upgrading fsck warnings to errors
fsck: Document the new receive.fsck.<msg-id> options
fsck: Support demoting errors to warnings
fsck: Introduce git fsck --connectivity-only
fsck: git receive-pack: support excluding objects from fsck'ing
fsck: support ignoring objects in git fsck via fsck.skiplist

 Documentation/config.txt        |  41 +++
 Documentation/git-fsck.txt      |   7 +-
 builtin/fsck.c                  |  78 ++++--
 builtin/index-pack.c            |  13 +-
 builtin/receive-pack.c          |  28 +-
 builtin/unpack-objects.c        |  16 +-
 fsck.c                          | 554 +++++++++++++++++++++++++++++++---------
 fsck.h                          |  30 ++-
 t/t1450-fsck.sh                 |  37 ++-
 t/t5302-pack-index.sh           |   2 +-
 t/t5504-fetch-receive-strict.sh |  51 ++++
 11 files changed, 692 insertions(+), 165 deletions(-)
Documentation/config.txt +7 -5
index 5aba63a..69dda93 100644
@@ -1252,11 +1252,11 @@ filter.<driver>.smudge::
 
 fsck.<msg-id>::
 	Allows overriding the message type (error, warn or ignore) of a
-	specific message ID such as `missingemail`.
+	specific message ID such as `missingEmail`.
 +
 For convenience, fsck prefixes the error/warning with the message ID,
-e.g.  "missingemail: invalid author/committer line - missing email" means
-that setting `fsck.missingemail = ignore` will hide that issue.
+e.g.  "missingEmail: invalid author/committer line - missing email" means
+that setting `fsck.missingEmail = ignore` will hide that issue.
 +
 This feature is intended to support working with legacy repositories
 which cannot be repaired without disruptive changes.
@@ -1267,6 +1267,7 @@ fsck.skipList::
 	be ignored. This feature is useful when an established project
 	should be accepted despite early commits containing errors that
 	can be safely ignored such as invalid committer email addresses.
+	Note: corrupt objects cannot be skipped with this setting.
 
 gc.aggressiveDepth::
 	The depth parameter used in the delta compression
@@ -2228,9 +2229,9 @@ receive.fsck.<msg-id>::
 	to warnings and vice versa by configuring the `receive.fsck.<msg-id>`
 	setting where the `<msg-id>` is the fsck message ID and the value
 	is one of `error`, `warn` or `ignore`. For convenience, fsck prefixes
-	the error/warning with the message ID, e.g. "missingemail: invalid
+	the error/warning with the message ID, e.g. "missingEmail: invalid
 	author/committer line - missing email" means that setting
-	`receive.fsck.missingemail = ignore` will hide that issue.
+	`receive.fsck.missingEmail = ignore` will hide that issue.
 +
 This feature is intended to support working with legacy repositories
 which would not pass pushing when `receive.fsckObjects = true`, allowing
@@ -2243,6 +2244,7 @@ receive.fsck.skipList::
 	be ignored. This feature is useful when an established project
 	should be accepted despite early commits containing errors that
 	can be safely ignored such as invalid committer email addresses.
+	Note: corrupt objects cannot be skipped with this setting.
 
 receive.unpackLimit::
 	If the number of objects received in a push is below this
Documentation/git-fsck.txt +4 -4
index b98fb43..84ee92e 100644
@@ -10,8 +10,8 @@ SYNOPSIS
 --------
 [verse]
 'git fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
-	 [--[no-]full] [--quick] [--strict] [--verbose] [--lost-found]
-	 [--[no-]dangling] [--[no-]progress] [<object>*]
+	 [--[no-]full] [--strict] [--verbose] [--lost-found]
+	 [--[no-]dangling] [--[no-]progress] [--connectivity-only] [<object>*]
 
 DESCRIPTION
 -----------
@@ -60,10 +60,10 @@ index file, all SHA-1 references in `refs` namespace, and all reflogs
 	object pools.  This is now default; you can turn it off
 	with --no-full.
 
---quick::
+--connectivity-only::
 	Check only the connectivity of tags, commits and tree objects. By
 	avoiding to unpack blobs, this speeds up the operation, at the
-	expense of missing corrupt objects.
+	expense of missing corrupt objects or other problematic issues.
 
 --strict::
 	Enable more strict checking, namely to catch a file mode
builtin/fsck.c +14 -11
index ce538ac..7e3df20 100644
@@ -23,7 +23,7 @@ static int show_tags;
 static int show_unreachable;
 static int include_reflogs = 1;
 static int check_full = 1;
-static int quick;
+static int connectivity_only;
 static int check_strict;
 static int keep_cache_objects;
 static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT;
@@ -49,21 +49,24 @@ static int show_dangling = 1;
 
 static int fsck_config(const char *var, const char *value, void *cb)
 {
-	if (skip_prefix(var, "fsck.", &var)) {
-		fsck_set_msg_type(&fsck_obj_options, var, -1, value, -1);
-		return 0;
-	}
-
 	if (strcmp(var, "fsck.skiplist") == 0) {
-		const char *path = is_absolute_path(value) ?
-			value : git_path("%s", value);
+		const char *path;
 		struct strbuf sb = STRBUF_INIT;
+
+		if (git_config_pathname(&path, var, value))
+			return 1;
 		strbuf_addf(&sb, "skiplist=%s", path);
+		free((char *) path);
 		fsck_set_msg_types(&fsck_obj_options, sb.buf);
 		strbuf_release(&sb);
 		return 0;
 	}
 
+	if (skip_prefix(var, "fsck.", &var)) {
+		fsck_set_msg_type(&fsck_obj_options, var, value);
+		return 0;
+	}
+
 	return git_default_config(var, value, cb);
 }
 
@@ -192,7 +195,7 @@ static void check_reachable_object(struct object *obj)
 	if (!(obj->flags & HAS_OBJ)) {
 		if (has_sha1_pack(obj->sha1))
 			return; /* it is in pack - forget about it */
-		if (quick && has_sha1_file(obj->sha1))
+		if (connectivity_only && has_sha1_file(obj->sha1))
 			return;
 		printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1));
 		errors_found |= ERROR_REACHABLE;
@@ -636,7 +639,7 @@ static struct option fsck_opts[] = {
 	OPT_BOOL(0, "cache", &keep_cache_objects, N_("make index objects head nodes")),
 	OPT_BOOL(0, "reflogs", &include_reflogs, N_("make reflogs head nodes (default)")),
 	OPT_BOOL(0, "full", &check_full, N_("also consider packs and alternate objects")),
-	OPT_BOOL(0, "quick", &quick, N_("check only connectivity")),
+	OPT_BOOL(0, "connectivity-only", &connectivity_only, N_("check only connectivity")),
 	OPT_BOOL(0, "strict", &check_strict, N_("enable more strict checking")),
 	OPT_BOOL(0, "lost-found", &write_lost_and_found,
 				N_("write dangling objects in .git/lost-found")),
@@ -673,7 +676,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 	git_config(fsck_config, NULL);
 
 	fsck_head_link();
-	if (!quick)
+	if (!connectivity_only)
 		fsck_object_dir(get_object_directory());
 
 	prepare_alt_odb();
builtin/index-pack.c +1 -1
index 98e14fe..f0d283b 100644
@@ -841,7 +841,6 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 			if (do_fsck_object &&
 			    fsck_object(obj, buf, size, &fsck_options))
 				die(_("Error in object"));
-			fsck_options.walk = mark_link;
 			if (fsck_walk(obj, NULL, &fsck_options))
 				die(_("Not all child objects of %s are reachable"), sha1_to_hex(obj->sha1));
 
@@ -1616,6 +1615,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 		usage(index_pack_usage);
 
 	check_replace_refs = 0;
+	fsck_options.walk = mark_link;
 
 	reset_pack_idx_option(&opts);
 	git_config(git_index_pack_config, &opts);
builtin/receive-pack.c +5 -2
index 80574f9..3fbed23 100644
@@ -118,10 +118,13 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
 	}
 
 	if (strcmp(var, "receive.fsck.skiplist") == 0) {
-		const char *path = is_absolute_path(value) ?
-			value : git_path("%s", value);
+		const char *path;
+
+		if (git_config_pathname(&path, var, value))
+			return 1;
 		strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
 			fsck_msg_types.len ? ',' : '=', path);
+		free((char *) path);
 		return 0;
 	}
 
fsck.c +68 -71

225 lines not on this page · raw message

fsck.h +1 -2
index cab9c65..dded84b 100644
@@ -8,8 +8,7 @@
 struct fsck_options;
 
 void fsck_set_msg_type(struct fsck_options *options,
-		const char *msg_id, int msg_id_len,
-		const char *msg_type, int msg_type_len);
+		const char *msg_id, const char *msg_type);
 void fsck_set_msg_types(struct fsck_options *options, const char *values);
 int is_valid_msg_type(const char *msg_id, const char *msg_type);
 
t/t1450-fsck.sh +9 -9
index 2863a8a..956673b 100755
@@ -231,8 +231,8 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
 	git fsck --tags 2>out &&
 
 	cat >expect <<-EOF &&
-	warning in tag $tag: badtagname: invalid '\''tag'\'' name: wrong name format
-	warning in tag $tag: missingtaggerentry: invalid format - expected '\''tagger'\'' line
+	warning in tag $tag: badTagName: invalid '\''tag'\'' name: wrong name format
+	warning in tag $tag: missingTaggerEntry: invalid format - expected '\''tagger'\'' line
 	EOF
 	test_cmp expect out
 '
@@ -295,7 +295,7 @@ test_expect_success 'force fsck to ignore double author' '
 	git update-ref refs/heads/bogus "$new" &&
 	test_when_finished "git update-ref -d refs/heads/bogus" &&
 	test_must_fail git fsck &&
-	git -c fsck.multipleauthors=ignore fsck
+	git -c fsck.multipleAuthors=ignore fsck
 '
 
 _bz='\0'
@@ -431,11 +431,11 @@ test_expect_success 'fsck notices ref pointing to missing tag' '
 	test_must_fail git -C missing fsck
 '
 
-test_expect_success 'fsck --quick' '
-	rm -rf quick &&
-	git init quick &&
+test_expect_success 'fsck --connectivity-only' '
+	rm -rf connectivity-only &&
+	git init connectivity-only &&
 	(
-		cd quick &&
+		cd connectivity-only &&
 		touch empty &&
 		git add empty &&
 		test_commit empty &&
@@ -443,13 +443,13 @@ test_expect_success 'fsck --quick' '
 		rm -f $empty &&
 		echo invalid >$empty &&
 		test_must_fail git fsck --strict &&
-		git fsck --strict --quick &&
+		git fsck --strict --connectivity-only &&
 		tree=$(git rev-parse HEAD:) &&
 		suffix=${tree#??} &&
 		tree=.git/objects/${tree%$suffix}/$suffix &&
 		rm -f $tree &&
 		echo invalid >$tree &&
-		test_must_fail git fsck --strict --quick
+		test_must_fail git fsck --strict --connectivity-only
 	)
 '
 
t/t5504-fetch-receive-strict.sh +10 -10
index 1ada54c..6a1f89e 100755
@@ -123,19 +123,19 @@ committer Bugs Bunny <[email protected]> 1234567890 +0000
 This commit object intentionally broken
 EOF
 
-test_expect_success 'push with receive.fsck.skiplist' '
+test_expect_success 'push with receive.fsck.skipList' '
 	commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
 	git push . $commit:refs/heads/bogus &&
 	rm -rf dst &&
 	git init dst &&
-	git --git-dir=dst/.git config receive.fsckobjects true &&
+	git --git-dir=dst/.git config receive.fsckObjects true &&
 	test_must_fail git push --porcelain dst bogus &&
-	git --git-dir=dst/.git config receive.fsck.skiplist SKIP &&
+	git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
 	echo $commit >dst/.git/SKIP &&
 	git push --porcelain dst bogus
 '
 
-test_expect_success 'push with receive.fsck.missingemail=warn' '
+test_expect_success 'push with receive.fsck.missingEmail=warn' '
 	commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
 	git push . $commit:refs/heads/bogus &&
 	rm -rf dst &&
@@ -143,20 +143,20 @@ test_expect_success 'push with receive.fsck.missingemail=warn' '
 	git --git-dir=dst/.git config receive.fsckobjects true &&
 	test_must_fail git push --porcelain dst bogus &&
 	git --git-dir=dst/.git config \
-		receive.fsck.missingemail warn &&
+		receive.fsck.missingEmail warn &&
 	git push --porcelain dst bogus >act 2>&1 &&
-	grep "missingemail" act &&
+	grep "missingEmail" act &&
 	git --git-dir=dst/.git branch -D bogus &&
 	git  --git-dir=dst/.git config --add \
-		receive.fsck.missingemail ignore &&
+		receive.fsck.missingEmail ignore &&
 	git  --git-dir=dst/.git config --add \
-		receive.fsck.baddate warn &&
+		receive.fsck.badDate warn &&
 	git push --porcelain dst bogus >act 2>&1 &&
-	test_must_fail grep "missingemail" act
+	test_must_fail grep "missingEmail" act
 '
 
 test_expect_success \
-	'receive.fsck.unterminatedheader=warn triggers error' '
+	'receive.fsck.unterminatedHeader=warn triggers error' '
 	rm -rf dst &&
 	git init dst &&
 	git --git-dir=dst/.git config receive.fsckobjects true &&
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#250 lore raw

PATCH v7 1/19 fsck: Introduce fsck options

Just like the diff machinery, we are about to introduce more settings, therefore it makes sense to carry them around as a (pointer to a) struct containing all of them.

---
 builtin/fsck.c           |  20 +++++--
 builtin/index-pack.c     |   9 +--
 builtin/unpack-objects.c |  11 ++--
 fsck.c                   | 150 +++++++++++++++++++++++------------------------
 fsck.h                   |  17 +++++-
 5 files changed, 114 insertions(+), 93 deletions(-)
builtin/fsck.c +14 -6
index 2679793..981dca5 100644
@@ -25,6 +25,8 @@ static int include_reflogs = 1;
 static int check_full = 1;
 static int check_strict;
 static int keep_cache_objects;
+static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT;
+static struct fsck_options fsck_obj_options = FSCK_OPTIONS_DEFAULT;
 static struct object_id head_oid;
 static const char *head_points_at;
 static int errors_found;
@@ -76,7 +78,7 @@ static int fsck_error_func(struct object *obj, int type, const char *err, ...)
 
 static struct object_array pending;
 
-static int mark_object(struct object *obj, int type, void *data)
+static int mark_object(struct object *obj, int type, void *data, struct fsck_options *options)
 {
 	struct object *parent = data;
 
@@ -119,7 +121,7 @@ static int mark_object(struct object *obj, int type, void *data)
 
 static void mark_object_reachable(struct object *obj)
 {
-	mark_object(obj, OBJ_ANY, NULL);
+	mark_object(obj, OBJ_ANY, NULL, NULL);
 }
 
 static int traverse_one_object(struct object *obj)
@@ -132,7 +134,7 @@ static int traverse_one_object(struct object *obj)
 		if (parse_tree(tree) < 0)
 			return 1; /* error already displayed */
 	}
-	result = fsck_walk(obj, mark_object, obj);
+	result = fsck_walk(obj, obj, &fsck_walk_options);
 	if (tree)
 		free_tree_buffer(tree);
 	return result;
@@ -158,7 +160,7 @@ static int traverse_reachable(void)
 	return !!result;
 }
 
-static int mark_used(struct object *obj, int type, void *data)
+static int mark_used(struct object *obj, int type, void *data, struct fsck_options *options)
 {
 	if (!obj)
 		return 1;
@@ -296,9 +298,9 @@ static int fsck_obj(struct object *obj)
 		fprintf(stderr, "Checking %s %s\n",
 			typename(obj->type), sha1_to_hex(obj->sha1));
 
-	if (fsck_walk(obj, mark_used, NULL))
+	if (fsck_walk(obj, NULL, &fsck_obj_options))
 		objerror(obj, "broken links");
-	if (fsck_object(obj, NULL, 0, check_strict, fsck_error_func))
+	if (fsck_object(obj, NULL, 0, &fsck_obj_options))
 		return -1;
 
 	if (obj->type == OBJ_TREE) {
@@ -638,6 +640,12 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 
 	argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
 
+	fsck_walk_options.walk = mark_object;
+	fsck_obj_options.walk = mark_used;
+	fsck_obj_options.error_func = fsck_error_func;
+	if (check_strict)
+		fsck_obj_options.strict = 1;
+
 	if (show_progress == -1)
 		show_progress = isatty(2);
 	if (verbose)
builtin/index-pack.c +5 -4
index 48fa472..f8b0c64 100644
@@ -75,6 +75,7 @@ static int nr_threads;
 static int from_stdin;
 static int strict;
 static int do_fsck_object;
+static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
 static int verbose;
 static int show_stat;
 static int check_self_contained_and_connected;
@@ -192,7 +193,7 @@ static void cleanup_thread(void)
 #endif
 
 
-static int mark_link(struct object *obj, int type, void *data)
+static int mark_link(struct object *obj, int type, void *data, struct fsck_options *options)
 {
 	if (!obj)
 		return -1;
@@ -838,10 +839,9 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 			if (!obj)
 				die(_("invalid %s"), typename(type));
 			if (do_fsck_object &&
-			    fsck_object(obj, buf, size, 1,
-				    fsck_error_function))
+			    fsck_object(obj, buf, size, &fsck_options))
 				die(_("Error in object"));
-			if (fsck_walk(obj, mark_link, NULL))
+			if (fsck_walk(obj, NULL, &fsck_options))
 				die(_("Not all child objects of %s are reachable"), sha1_to_hex(obj->sha1));
 
 			if (obj->type == OBJ_TREE) {
@@ -1615,6 +1615,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 		usage(index_pack_usage);
 
 	check_replace_refs = 0;
+	fsck_options.walk = mark_link;
 
 	reset_pack_idx_option(&opts);
 	git_config(git_index_pack_config, &opts);
builtin/unpack-objects.c +6 -5
index ac66672..6d17040 100644
@@ -20,6 +20,7 @@ static unsigned char buffer[4096];
 static unsigned int offset, len;
 static off_t consumed_bytes;
 static git_SHA_CTX ctx;
+static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
 
 /*
  * When running under --strict mode, objects whose reachability are
@@ -178,7 +179,7 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
  * that have reachability requirements and calls this function.
  * Verify its reachability and validity recursively and write it out.
  */
-static int check_object(struct object *obj, int type, void *data)
+static int check_object(struct object *obj, int type, void *data, struct fsck_options *options)
 {
 	struct obj_buffer *obj_buf;
 
@@ -203,10 +204,10 @@ static int check_object(struct object *obj, int type, void *data)
 	obj_buf = lookup_object_buffer(obj);
 	if (!obj_buf)
 		die("Whoops! Cannot find object '%s'", sha1_to_hex(obj->sha1));
-	if (fsck_object(obj, obj_buf->buffer, obj_buf->size, 1,
-			fsck_error_function))
+	if (fsck_object(obj, obj_buf->buffer, obj_buf->size, &fsck_options))
 		die("Error in object");
-	if (fsck_walk(obj, check_object, NULL))
+	fsck_options.walk = check_object;
+	if (fsck_walk(obj, NULL, &fsck_options))
 		die("Error on reachable objects of %s", sha1_to_hex(obj->sha1));
 	write_cached_object(obj, obj_buf);
 	return 0;
@@ -217,7 +218,7 @@ static void write_rest(void)
 	unsigned i;
 	for (i = 0; i < nr_objects; i++) {
 		if (obj_list[i].obj)
-			check_object(obj_list[i].obj, OBJ_ANY, NULL);
+			check_object(obj_list[i].obj, OBJ_ANY, NULL, NULL);
 	}
 }
 
fsck.c +75 -75

392 lines not on this page · raw message

fsck.h +14 -3
index d1e6387..07d0ab2 100644
@@ -4,6 +4,8 @@
 #define FSCK_ERROR 1
 #define FSCK_WARN 2
 
+struct fsck_options;
+
 /*
  * callback function for fsck_walk
  * type is the expected type of the object or OBJ_ANY
@@ -12,7 +14,7 @@
  *     <0	error signaled and abort
  *     >0	error signaled and do not abort
  */
-typedef int (*fsck_walk_func)(struct object *obj, int type, void *data);
+typedef int (*fsck_walk_func)(struct object *obj, int type, void *data, struct fsck_options *options);
 
 /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
 typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...);
@@ -20,6 +22,15 @@ typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...);
 __attribute__((format (printf, 3, 4)))
 int fsck_error_function(struct object *obj, int type, const char *fmt, ...);
 
+struct fsck_options {
+	fsck_walk_func walk;
+	fsck_error error_func;
+	unsigned strict:1;
+};
+
+#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0 }
+#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1 }
+
 /* descend in all linked child objects
  * the return value is:
  *    -1	error in processing the object
@@ -27,9 +38,9 @@ int fsck_error_function(struct object *obj, int type, const char *fmt, ...);
  *    >0	return value of the first signaled error >0 (in the case of no other errors)
  *    0		everything OK
  */
-int fsck_walk(struct object *obj, fsck_walk_func walk, void *data);
+int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
 /* If NULL is passed for data, we assume the object is local and read it. */
 int fsck_object(struct object *obj, void *data, unsigned long size,
-	int strict, fsck_error error_func);
+	struct fsck_options *options);
 
 #endif
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#251 lore raw

PATCH v7 2/19 fsck: Introduce identifiers for fsck messages

In reply to Johannes Schindelin

Instead of specifying whether a message by the fsck machinery constitutes an error or a warning, let's specify an identifier relating to the concrete problem that was encountered. This is necessary for upcoming support to be able to demote certain errors to warnings.

In the process, simplify the requirements on the calling code: instead of having to handle full-blown varargs in every callback, we now send a string buffer ready to be used by the callback.

We could use a simple enum for the message IDs here, but we want to guarantee that the enum values are associated with the appropriate message types (i.e. error or warning?). Besides, we want to introduce a parser in the next commit that maps the string representation to the enum value, hence we use the slightly ugly preprocessor construct that is extensible for use with said parser.

---
 builtin/fsck.c |  26 +++-----
 fsck.c         | 201 +++++++++++++++++++++++++++++++++++++++++----------------
 fsck.h         |   5 +-
 3 files changed, 154 insertions(+), 78 deletions(-)
builtin/fsck.c +8 -18
index 981dca5..fff38fe 100644
@@ -46,33 +46,23 @@ static int show_dangling = 1;
 #define DIRENT_SORT_HINT(de) ((de)->d_ino)
 #endif
 
-static void objreport(struct object *obj, const char *severity,
-                      const char *err, va_list params)
+static void objreport(struct object *obj, const char *msg_type,
+			const char *err)
 {
-	fprintf(stderr, "%s in %s %s: ",
-	        severity, typename(obj->type), sha1_to_hex(obj->sha1));
-	vfprintf(stderr, err, params);
-	fputs("\n", stderr);
+	fprintf(stderr, "%s in %s %s: %s\n",
+		msg_type, typename(obj->type), sha1_to_hex(obj->sha1), err);
 }
 
-__attribute__((format (printf, 2, 3)))
-static int objerror(struct object *obj, const char *err, ...)
+static int objerror(struct object *obj, const char *err)
 {
-	va_list params;
-	va_start(params, err);
 	errors_found |= ERROR_OBJECT;
-	objreport(obj, "error", err, params);
-	va_end(params);
+	objreport(obj, "error", err);
 	return -1;
 }
 
-__attribute__((format (printf, 3, 4)))
-static int fsck_error_func(struct object *obj, int type, const char *err, ...)
+static int fsck_error_func(struct object *obj, int type, const char *message)
 {
-	va_list params;
-	va_start(params, err);
-	objreport(obj, (type == FSCK_WARN) ? "warning" : "error", err, params);
-	va_end(params);
+	objreport(obj, (type == FSCK_WARN) ? "warning" : "error", message);
 	return (type == FSCK_WARN) ? 0 : 1;
 }
 
fsck.c +144 -57

356 lines not on this page · raw message

fsck.h +2 -3
index 07d0ab2..f6f268a 100644
@@ -17,10 +17,9 @@ struct fsck_options;
 typedef int (*fsck_walk_func)(struct object *obj, int type, void *data, struct fsck_options *options);
 
 /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
-typedef int (*fsck_error)(struct object *obj, int type, const char *err, ...);
+typedef int (*fsck_error)(struct object *obj, int type, const char *message);
 
-__attribute__((format (printf, 3, 4)))
-int fsck_error_function(struct object *obj, int type, const char *fmt, ...);
+int fsck_error_function(struct object *obj, int type, const char *message);
 
 struct fsck_options {
 	fsck_walk_func walk;
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#252 lore raw

PATCH v7 3/19 fsck: Provide a function to parse fsck message IDs

In reply to Johannes Schindelin

These functions will be used in the next commits to allow the user to ask fsck to handle specific problems differently, e.g. demoting certain errors to warnings. The upcoming fsck_set_msg_types() function has to handle partial strings because we would like to be able to parse, say, 'missingemail=warn,missingtaggerentry=warn' command line parameters (which will be passed by receive-pack to index-pack and unpack-objects).

To make the parsing robust, we generate strings from the enum keys, and using these keys, we match up strings without dashes case-insensitively to the corresponding enum values.

---
 fsck.c | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)
fsck.c +34 -2
index ab24618..1a3f7ce 100644
@@ -63,15 +63,47 @@ enum fsck_msg_id {
 };
 #undef MSG_ID
 
-#define MSG_ID(id, msg_type) { FSCK_##msg_type },
+#define STR(x) #x
+#define MSG_ID(id, msg_type) { STR(id), FSCK_##msg_type },
 static struct {
+	const char *id_string;
 	int msg_type;
 } msg_id_info[FSCK_MSG_MAX + 1] = {
 	FOREACH_MSG_ID(MSG_ID)
-	{ -1 }
+	{ NULL, -1 }
 };
 #undef MSG_ID
 
+static int parse_msg_id(const char *text)
+{
+	static char **lowercased;
+	int i;
+
+	if (!lowercased) {
+		/* convert id_string to lower case, without underscores. */
+		lowercased = xmalloc(FSCK_MSG_MAX * sizeof(*lowercased));
+		for (i = 0; i < FSCK_MSG_MAX; i++) {
+			const char *p = msg_id_info[i].id_string;
+			int len = strlen(p);
+			char *q = xmalloc(len);
+
+			lowercased[i] = q;
+			while (*p)
+				if (*p == '_')
+					p++;
+				else
+					*(q)++ = tolower(*(p)++);
+			*q = '\0';
+		}
+	}
+
+	for (i = 0; i < FSCK_MSG_MAX; i++)
+		if (!strcmp(text, lowercased[i]))
+			return i;
+
+	return -1;
+}
+
 static int fsck_msg_type(enum fsck_msg_id msg_id,
 	struct fsck_options *options)
 {
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#253 lore raw

PATCH v7 4/19 fsck: Offer a function to demote fsck errors to warnings

In reply to Johannes Schindelin

There are legacy repositories out there whose older commits and tags have issues that prevent pushing them when 'receive.fsckObjects' is set. One real-life example is a commit object that has been hand-crafted to list two authors.

Often, it is not possible to fix those issues without disrupting the work with said repositories, yet it is still desirable to perform checks by setting receive.fsckObjects = true. This commit is the first step to allow demoting specific fsck issues to mere warnings.

The fsck_set_msg_types() function added by this commit parses a list of settings in the form:

missingemail=warn,badname=warn,...

Unfortunately, the FSCK_WARN/FSCK_ERROR flag is only really heeded by git fsck so far, but other call paths (e.g. git index-pack --strict) error out *always* no matter what type was specified. Therefore, we need to take extra care to set all message types to FSCK_ERROR by default in those cases.

---
 fsck.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
 fsck.h |  9 +++++--
 2 files changed, 85 insertions(+), 12 deletions(-)
fsck.c +78 -10
index 1a3f7ce..e81a342 100644
@@ -64,30 +64,29 @@ enum fsck_msg_id {
 #undef MSG_ID
 
 #define STR(x) #x
-#define MSG_ID(id, msg_type) { STR(id), FSCK_##msg_type },
+#define MSG_ID(id, msg_type) { STR(id), NULL, FSCK_##msg_type },
 static struct {
 	const char *id_string;
+	const char *lowercased;
 	int msg_type;
 } msg_id_info[FSCK_MSG_MAX + 1] = {
 	FOREACH_MSG_ID(MSG_ID)
-	{ NULL, -1 }
+	{ NULL, NULL, -1 }
 };
 #undef MSG_ID
 
 static int parse_msg_id(const char *text)
 {
-	static char **lowercased;
 	int i;
 
-	if (!lowercased) {
+	if (!msg_id_info[0].lowercased) {
 		/* convert id_string to lower case, without underscores. */
-		lowercased = xmalloc(FSCK_MSG_MAX * sizeof(*lowercased));
 		for (i = 0; i < FSCK_MSG_MAX; i++) {
 			const char *p = msg_id_info[i].id_string;
 			int len = strlen(p);
 			char *q = xmalloc(len);
 
-			lowercased[i] = q;
+			msg_id_info[i].lowercased = q;
 			while (*p)
 				if (*p == '_')
 					p++;
@@ -98,7 +97,7 @@ static int parse_msg_id(const char *text)
 	}
 
 	for (i = 0; i < FSCK_MSG_MAX; i++)
-		if (!strcmp(text, lowercased[i]))
+		if (!strcmp(text, msg_id_info[i].lowercased))
 			return i;
 
 	return -1;
@@ -109,13 +108,78 @@ static int fsck_msg_type(enum fsck_msg_id msg_id,
 {
 	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);
+}
+
+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);
+}
+
 __attribute__((format (printf, 4, 5)))
 static int report(struct fsck_options *options, struct object *object,
 	enum fsck_msg_id id, const char *fmt, ...)
@@ -605,6 +669,10 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
 
 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;
 }
fsck.h +7 -2
index f6f268a..af3c84e 100644
@@ -6,6 +6,10 @@
 
 struct fsck_options;
 
+void fsck_set_msg_type(struct fsck_options *options,
+		const char *msg_id, const char *msg_type);
+void fsck_set_msg_types(struct fsck_options *options, const char *values);
+
 /*
  * callback function for fsck_walk
  * type is the expected type of the object or OBJ_ANY
@@ -25,10 +29,11 @@ struct fsck_options {
 	fsck_walk_func walk;
 	fsck_error error_func;
 	unsigned strict:1;
+	int *msg_type;
 };
 
-#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0 }
-#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1 }
+#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL }
+#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL }
 
 /* descend in all linked child objects
  * the return value is:
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#254 lore raw

Re: [PATCH v7 04/19] fsck: Offer a function to demote fsck errors to warnings

Quoted 41 lines · Johannes Schindelin
fsck.c +5 -6
index 1a3f7ce..e81a342 100644
@@ -64,30 +64,29 @@ enum fsck_msg_id {
 #undef MSG_ID
 
 #define STR(x) #x
-#define MSG_ID(id, msg_type) { STR(id), FSCK_##msg_type },
+#define MSG_ID(id, msg_type) { STR(id), NULL, FSCK_##msg_type },
 static struct {
 	const char *id_string;
+	const char *lowercased;
 	int msg_type;
 } msg_id_info[FSCK_MSG_MAX + 1] = {
 	FOREACH_MSG_ID(MSG_ID)
-	{ NULL, -1 }
+	{ NULL, NULL, -1 }
 };
 #undef MSG_ID
 
 static int parse_msg_id(const char *text)
 {
-	static char **lowercased;
 	int i;
 
-	if (!lowercased) {
+	if (!msg_id_info[0].lowercased) {
 		/* convert id_string to lower case, without underscores. */
-		lowercased = xmalloc(FSCK_MSG_MAX * sizeof(*lowercased));
 		for (i = 0; i < FSCK_MSG_MAX; i++) {
 			const char *p = msg_id_info[i].id_string;
 			int len = strlen(p);
 			char *q = xmalloc(len);
 
-			lowercased[i] = q;
+			msg_id_info[i].lowercased = q;
 			while (*p)
 				if (*p == '_')
 					p++;

fsck.c static int parse_msg_id(const char *text) · line 103

Quoted 8 lines
fsck.c +1 -1
@@ -98,7 +97,7 @@ static int parse_msg_id(const char *text)
 	}
 
 	for (i = 0; i < FSCK_MSG_MAX; i++)
-		if (!strcmp(text, lowercased[i]))
+		if (!strcmp(text, msg_id_info[i].lowercased))
 			return i;
 
 	return -1;

Heh, this was the first thing that came to my mind when I saw 03/19 that lazily prepares downcased version (which is good) but do so in a separately allocated buffer (which is improved by this change) ;-)

IOW, I think all of the above should have been part of 03/19, not "oops I belatedly realized that this way is better" fixup here.

The end result looks good, so let's keep reading.

Quoted 7 lines
fsck.c +7 -0
+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;

fsck.c static int fsck_msg_type(enum fsck_msg_id msg_id, · line 170

Quoted 10 lines
fsck.c +10 -0
+
+		done = !buf[len];
+		if (!len) {
+			buf++;
+			continue;
+		}
+		buf[len] = '\0';
+
+		for (equal = 0; equal < len &&
+				buf[equal] != '=' && buf[equal] != ':'; equal++)

Style. I'd format this more like so:

		for (equal = 0;
                     equal < len && buf[equal] != '=' && buf[equal] != ':';
		     equal++)

fsck.c static int fsck_msg_type(enum fsck_msg_id msg_id, · line 181

Quoted 11 lines
fsck.c +11 -0
+			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);
+}

Overall, the change is good (and it was good in v6, too), and I think it has become simpler to follow the logic with the upfront downcasing.

Thanks.

#255 lore raw

Re: [PATCH v7 04/19] fsck: Offer a function to demote fsck errors to warnings

Hi Junio,

Quoted 50 lines · Junio C Hamano
Quoted 48 lines · Johannes Schindelin
fsck.c +6 -7
index 1a3f7ce..e81a342 100644
@@ -64,30 +64,29 @@ enum fsck_msg_id {
 #undef MSG_ID
 
 #define STR(x) #x
-#define MSG_ID(id, msg_type) { STR(id), FSCK_##msg_type },
+#define MSG_ID(id, msg_type) { STR(id), NULL, FSCK_##msg_type },
 static struct {
 	const char *id_string;
+	const char *lowercased;
 	int msg_type;
 } msg_id_info[FSCK_MSG_MAX + 1] = {
 	FOREACH_MSG_ID(MSG_ID)
-	{ NULL, -1 }
+	{ NULL, NULL, -1 }
 };
 #undef MSG_ID
 
 static int parse_msg_id(const char *text)
 {
-	static char **lowercased;
 	int i;
 
-	if (!lowercased) {
+	if (!msg_id_info[0].lowercased) {
 		/* convert id_string to lower case, without underscores. */
-		lowercased = xmalloc(FSCK_MSG_MAX * sizeof(*lowercased));
 		for (i = 0; i < FSCK_MSG_MAX; i++) {
 			const char *p = msg_id_info[i].id_string;
 			int len = strlen(p);
 			char *q = xmalloc(len);
 
-			lowercased[i] = q;
+			msg_id_info[i].lowercased = q;
 			while (*p)
 				if (*p == '_')
 					p++;
@@ -98,7 +97,7 @@ static int parse_msg_id(const char *text)
 	}
 
 	for (i = 0; i < FSCK_MSG_MAX; i++)
-		if (!strcmp(text, lowercased[i]))
+		if (!strcmp(text, msg_id_info[i].lowercased))
 			return i;
 
Quoted 8 lines

fsck.c static int parse_msg_id(const char *text) · line 103

Quoted 1 line
fsck.c +0 -0
 	return -1;

Heh, this was the first thing that came to my mind when I saw 03/19 that lazily prepares downcased version (which is good) but do so in a separately allocated buffer (which is improved by this change) ;-)

IOW, I think all of the above should have been part of 03/19, not "oops I belatedly realized that this way is better" fixup here.

Gaaaah. Wrong commit fixed up. Sorry. Will be fixed in v8.

Quoted 20 lines
Quoted 7 lines
fsck.c +7 -0
+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;

fsck.c static int fsck_msg_type(enum fsck_msg_id msg_id, · line 170

Quoted 10 lines
fsck.c +10 -0
+
+		done = !buf[len];
+		if (!len) {
+			buf++;
+			continue;
+		}
+		buf[len] = '\0';
+
+		for (equal = 0; equal < len &&
+				buf[equal] != '=' && buf[equal] != ':'; equal++)

Style. I'd format this more like so:

Quoted 3 lines
		for (equal = 0;
                     equal < len && buf[equal] != '=' && buf[equal] != ':';
		     equal++)

Will be fixed.

Quoted 7 lines
Quoted 7 lines
fsck.c +7 -0
+			buf[equal] = tolower(buf[equal]);
+		buf[equal] = '\0';
+
+		if (equal == len)
+			die("Missing '=': '%s'", buf);
+
+		fsck_set_msg_type(options, buf, buf + equal + 1);
Quoted 8 lines

fsck.c static int fsck_msg_type(enum fsck_msg_id msg_id, · line 181

Quoted 4 lines
fsck.c +4 -0
+		buf += len + 1;
+	}
+	free(to_free);
+}

Overall, the change is good (and it was good in v6, too), and I think it has become simpler to follow the logic with the upfront downcasing.

Yep, I agree. I did not expect that, but it was worth the effort to compare the two versions.

Ciao,
Dscho

#256 lore raw

PATCH v7 5/19 fsck (receive-pack): Allow demoting errors to warnings

In reply to Johannes Schindelin

For example, missing emails in commit and tag objects can be demoted to mere warnings with

git config receive.fsck.missingemail=warn

The value is actually a comma-separated list.

In case that the same key is listed in multiple receive.fsck.<msg-id> lines in the config, the latter configuration wins (this can happen for example when both $HOME/.gitconfig and .git/config contain message type settings).

As git receive-pack does not actually perform the checks, it hands off the setting to index-pack or unpack-objects in the form of an optional argument to the --strict option.

---
 builtin/index-pack.c     |  4 ++++
 builtin/receive-pack.c   | 17 +++++++++++++++--
 builtin/unpack-objects.c |  5 +++++
 fsck.c                   |  8 ++++++++
 fsck.h                   |  1 +
 5 files changed, 33 insertions(+), 2 deletions(-)
builtin/index-pack.c +4 -0
index f8b0c64..f0d283b 100644
@@ -1633,6 +1633,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 			} else if (!strcmp(arg, "--strict")) {
 				strict = 1;
 				do_fsck_object = 1;
+			} else if (skip_prefix(arg, "--strict=", &arg)) {
+				strict = 1;
+				do_fsck_object = 1;
+				fsck_set_msg_types(&fsck_options, arg);
 			} else if (!strcmp(arg, "--check-self-contained-and-connected")) {
 				strict = 1;
 				check_self_contained_and_connected = 1;
builtin/receive-pack.c +15 -2
index 94d0571..3afe8f8 100644
@@ -19,6 +19,7 @@
 #include "tag.h"
 #include "gpg-interface.h"
 #include "sigchain.h"
+#include "fsck.h"
 
 static const char receive_pack_usage[] = "git receive-pack <git-dir>";
 
@@ -36,6 +37,7 @@ static enum deny_action deny_current_branch = DENY_UNCONFIGURED;
 static enum deny_action deny_delete_current = DENY_UNCONFIGURED;
 static int receive_fsck_objects = -1;
 static int transfer_fsck_objects = -1;
+static struct strbuf fsck_msg_types = STRBUF_INIT;
 static int receive_unpack_limit = -1;
 static int transfer_unpack_limit = -1;
 static int advertise_atomic_push = 1;
@@ -115,6 +117,15 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if (skip_prefix(var, "receive.fsck.", &var)) {
+		if (is_valid_msg_type(var, value))
+			strbuf_addf(&fsck_msg_types, "%c%s=%s",
+				fsck_msg_types.len ? ',' : '=', var, value);
+		else
+			warning("Skipping unknown msg id '%s'", var);
+		return 0;
+	}
+
 	if (strcmp(var, "receive.fsckobjects") == 0) {
 		receive_fsck_objects = git_config_bool(var, value);
 		return 0;
@@ -1490,7 +1501,8 @@ static const char *unpack(int err_fd, struct shallow_info *si)
 		if (quiet)
 			argv_array_push(&child.args, "-q");
 		if (fsck_objects)
-			argv_array_push(&child.args, "--strict");
+			argv_array_pushf(&child.args, "--strict%s",
+				fsck_msg_types.buf);
 		child.no_stdout = 1;
 		child.err = err_fd;
 		child.git_cmd = 1;
@@ -1508,7 +1520,8 @@ static const char *unpack(int err_fd, struct shallow_info *si)
 		argv_array_pushl(&child.args, "index-pack",
 				 "--stdin", hdr_arg, keep_arg, NULL);
 		if (fsck_objects)
-			argv_array_push(&child.args, "--strict");
+			argv_array_pushf(&child.args, "--strict%s",
+				fsck_msg_types.buf);
 		if (fix_thin)
 			argv_array_push(&child.args, "--fix-thin");
 		child.out = -1;
builtin/unpack-objects.c +5 -0
index 6d17040..7cc086f 100644
@@ -530,6 +530,11 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
 				strict = 1;
 				continue;
 			}
+			if (skip_prefix(arg, "--strict=", &arg)) {
+				strict = 1;
+				fsck_set_msg_types(&fsck_options, arg);
+				continue;
+			}
 			if (starts_with(arg, "--pack_header=")) {
 				struct pack_header *hdr;
 				char *c;
fsck.c +8 -0
index e81a342..02af3ed 100644
@@ -131,6 +131,14 @@ static int parse_msg_type(const char *str)
 		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)
 {
fsck.h +1 -0
index af3c84e..3ef92a3 100644
@@ -9,6 +9,7 @@ struct fsck_options;
 void fsck_set_msg_type(struct fsck_options *options,
 		const char *msg_id, const char *msg_type);
 void fsck_set_msg_types(struct fsck_options *options, const char *values);
+int is_valid_msg_type(const char *msg_id, const char *msg_type);
 
 /*
  * callback function for fsck_walk
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#257 lore raw

PATCH v7 6/19 fsck: Report the ID of the error/warning

In reply to Johannes Schindelin

Some legacy code has objects with non-fatal fsck issues; To enable the user to ignore those issues, let's print out the ID (e.g. when encountering "missingEmail", the user might want to call git config --add receive.fsck.missingEmail=warn).

---
 fsck.c          | 20 ++++++++++++++++++++
 t/t1450-fsck.sh |  4 ++--
 2 files changed, 22 insertions(+), 2 deletions(-)
fsck.c +20 -0
index 02af3ed..0ec02b2 100644
@@ -188,6 +188,24 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
 	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, ...)
@@ -196,6 +214,8 @@ static int report(struct fsck_options *options, struct object *object,
 	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);
t/t1450-fsck.sh +2 -2
index cfb32b6..7c5b3d5 100755
@@ -231,8 +231,8 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
 	git fsck --tags 2>out &&
 
 	cat >expect <<-EOF &&
-	warning in tag $tag: invalid '\''tag'\'' name: wrong name format
-	warning in tag $tag: invalid format - expected '\''tagger'\'' line
+	warning in tag $tag: badTagName: invalid '\''tag'\'' name: wrong name format
+	warning in tag $tag: missingTaggerEntry: invalid format - expected '\''tagger'\'' line
 	EOF
 	test_cmp expect out
 '
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#258 lore raw

PATCH v7 7/19 fsck: Make fsck_ident() warn-friendly

In reply to Johannes Schindelin

When fsck_ident() identifies a problem with the ident, it should still advance the pointer to the next line so that fsck can continue in the case of a mere warning.

---
 fsck.c | 49 +++++++++++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 22 deletions(-)
fsck.c +27 -22
index 0ec02b2..d0a7282 100644
@@ -481,40 +481,45 @@ static int require_end_of_header(const void *data, unsigned long size,
 
 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;
 }
 
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#259 lore raw

PATCH v7 8/19 fsck: Make fsck_commit() warn-friendly

In reply to Johannes Schindelin

When fsck_commit() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.

Note that some problems are too problematic to simply ignore. For example, when the header lines are mixed up, we punt after encountering an incorrect line. Therefore, demoting certain warnings to errors can hide other problems. Example: demoting the missingauthor error to a warning would hide a problematic committer line.

---
 fsck.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
fsck.c +20 -8
index d0a7282..ef3bf68 100644
@@ -536,12 +536,18 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 
 	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++;
 	}
@@ -550,11 +556,17 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 	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");
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#260 lore raw

PATCH v7 9/19 fsck: Handle multiple authors in commits specially

In reply to Johannes Schindelin

This problem has been detected in the wild, and is the primary reason to introduce an option to demote certain fsck errors to warnings. Let's offer to ignore this particular problem specifically.

Technically, we could handle such repositories by setting receive.fsck.<msg-id> to missingCommitter=warn, but that could hide missing tree objects in the same commit because we cannot continue verifying any commit object after encountering a missing committer line, while we can continue in the case of multiple author lines.

---
 fsck.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
fsck.c +13 -4
index ef3bf68..daa07ad 100644
@@ -38,6 +38,7 @@
 	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) \
@@ -528,7 +529,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 {
 	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))
@@ -568,9 +569,17 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 				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))
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#261 lore raw

PATCH v7 10/19 fsck: Make fsck_tag() warn-friendly

In reply to Johannes Schindelin

When fsck_tag() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings.

Just like fsck_commit(), there are certain problems that could hide other issues with the same tag object. For example, if the 'type' line is not encountered in the correct position, the 'tag' line – if there is any – would not be handled at all.

---
 fsck.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fsck.c +2 -1
index daa07ad..3f76f99 100644
@@ -642,7 +642,8 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
 	}
 	if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
 		ret = report(options, &tag->object, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
-		goto done;
+		if (ret)
+			goto done;
 	}
 	buffer += 41;
 
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#262 lore raw

PATCH v7 11/19 fsck: Add a simple test for receive.fsck.<msg-id>

In reply to Johannes Schindelin
---
 t/t5504-fetch-receive-strict.sh | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
t/t5504-fetch-receive-strict.sh +21 -0
index 69ee13c..36024fc 100755
@@ -115,4 +115,25 @@ test_expect_success 'push with transfer.fsckobjects' '
 	test_cmp exp act
 '
 
+cat >bogus-commit <<\EOF
+tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
+author Bugs Bunny 1234567890 +0000
+committer Bugs Bunny <[email protected]> 1234567890 +0000
+
+This commit object intentionally broken
+EOF
+
+test_expect_success 'push with receive.fsck.missingEmail=warn' '
+	commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
+	git push . $commit:refs/heads/bogus &&
+	rm -rf dst &&
+	git init dst &&
+	git --git-dir=dst/.git config receive.fsckobjects true &&
+	test_must_fail git push --porcelain dst bogus &&
+	git --git-dir=dst/.git config \
+		receive.fsck.missingEmail warn &&
+	git push --porcelain dst bogus >act 2>&1 &&
+	grep "missingEmail" act
+'
+
 test_done
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#263 lore raw

PATCH v7 12/19 fsck: Disallow demoting grave fsck errors to warnings

In reply to Johannes Schindelin

Some kinds of errors are intrinsically unrecoverable (e.g. errors while uncompressing objects). It does not make sense to allow demoting them to mere warnings.

---
 fsck.c                          | 13 +++++++++++--
 t/t5504-fetch-receive-strict.sh | 11 +++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)
fsck.c +11 -2
index 3f76f99..85535b1 100644
@@ -9,7 +9,12 @@
 #include "refs.h"
 #include "utf8.h"
 
+#define FSCK_FATAL -1
+
 #define FOREACH_MSG_ID(FUNC) \
+	/* fatal errors */ \
+	FUNC(NUL_IN_HEADER, FATAL) \
+	FUNC(UNTERMINATED_HEADER, FATAL) \
 	/* errors */ \
 	FUNC(BAD_DATE, ERROR) \
 	FUNC(BAD_DATE_OVERFLOW, ERROR) \
@@ -39,11 +44,9 @@
 	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) \
 	FUNC(UNKNOWN_TYPE, ERROR) \
-	FUNC(UNTERMINATED_HEADER, ERROR) \
 	FUNC(ZERO_PADDED_DATE, ERROR) \
 	/* warnings */ \
 	FUNC(BAD_FILEMODE, WARN) \
@@ -149,6 +152,9 @@ void fsck_set_msg_type(struct fsck_options *options,
 		die("Unhandled message id: %s", msg_id);
 	type = parse_msg_type(msg_type);
 
+	if (type != FSCK_ERROR && msg_id_info[id].msg_type == FSCK_FATAL)
+		die("Cannot demote %s to %s", msg_id, msg_type);
+
 	if (!options->msg_type) {
 		int i;
 		int *msg_type = xmalloc(sizeof(int) * FSCK_MSG_MAX);
@@ -215,6 +221,9 @@ static int report(struct fsck_options *options, struct object *object,
 	struct strbuf sb = STRBUF_INIT;
 	int msg_type = fsck_msg_type(id, options), result;
 
+	if (msg_type == FSCK_FATAL)
+		msg_type = FSCK_ERROR;
+
 	append_msg_id(&sb, msg_id_info[id].id_string);
 
 	va_start(ap, fmt);
t/t5504-fetch-receive-strict.sh +11 -0
index 36024fc..f5d6d0d 100755
@@ -136,4 +136,15 @@ test_expect_success 'push with receive.fsck.missingEmail=warn' '
 	grep "missingEmail" act
 '
 
+test_expect_success \
+	'receive.fsck.unterminatedHeader=warn triggers error' '
+	rm -rf dst &&
+	git init dst &&
+	git --git-dir=dst/.git config receive.fsckobjects true &&
+	git --git-dir=dst/.git config \
+		receive.fsck.unterminatedheader warn &&
+	test_must_fail git push --porcelain dst HEAD >act 2>&1 &&
+	grep "Cannot demote unterminatedheader" act
+'
+
 test_done
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#264 lore raw

PATCH v7 13/19 fsck: Optionally ignore specific fsck issues completely

In reply to Johannes Schindelin

An fsck issue in a legacy repository might be so common that one would like not to bother the user with mentioning it at all. With this change, that is possible by setting the respective message type to "ignore".

This change "abuses" the missingEmail=warn test to verify that "ignore" is also accepted and works correctly. And while at it, it makes sure that multiple options work, too (they are passed to unpack-objects or index-pack as a comma-separated list via the --strict=... command-line option).

---
 fsck.c                          | 5 +++++
 fsck.h                          | 1 +
 t/t5504-fetch-receive-strict.sh | 9 ++++++++-
 3 files changed, 14 insertions(+), 1 deletion(-)
fsck.c +5 -0
index 85535b1..cbfff1f 100644
@@ -131,6 +131,8 @@ static int parse_msg_type(const char *str)
 		return FSCK_ERROR;
 	else if (!strcmp(str, "warn"))
 		return FSCK_WARN;
+	else if (!strcmp(str, "ignore"))
+		return FSCK_IGNORE;
 	else
 		die("Unknown fsck message type: '%s'", str);
 }
@@ -221,6 +223,9 @@ static int report(struct fsck_options *options, struct object *object,
 	struct strbuf sb = STRBUF_INIT;
 	int msg_type = fsck_msg_type(id, options), result;
 
+	if (msg_type == FSCK_IGNORE)
+		return 0;
+
 	if (msg_type == FSCK_FATAL)
 		msg_type = FSCK_ERROR;
 
fsck.h +1 -0
index 3ef92a3..1dab276 100644
@@ -3,6 +3,7 @@
 
 #define FSCK_ERROR 1
 #define FSCK_WARN 2
+#define FSCK_IGNORE 3
 
 struct fsck_options;
 
t/t5504-fetch-receive-strict.sh +8 -1
index f5d6d0d..af373ba 100755
@@ -133,7 +133,14 @@ test_expect_success 'push with receive.fsck.missingEmail=warn' '
 	git --git-dir=dst/.git config \
 		receive.fsck.missingEmail warn &&
 	git push --porcelain dst bogus >act 2>&1 &&
-	grep "missingEmail" act
+	grep "missingEmail" act &&
+	git --git-dir=dst/.git branch -D bogus &&
+	git  --git-dir=dst/.git config --add \
+		receive.fsck.missingEmail ignore &&
+	git  --git-dir=dst/.git config --add \
+		receive.fsck.badDate warn &&
+	git push --porcelain dst bogus >act 2>&1 &&
+	test_must_fail grep "missingEmail" act
 '
 
 test_expect_success \
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#265 lore raw

Re: [PATCH v7 13/19] fsck: Optionally ignore specific fsck issues completely

t/t5504-fetch-receive-strict.sh test_expect_success 'push with receive.fsck.missingEmail=warn' ' · line 141

Quoted 5 lines · Johannes Schindelin
t/t5504-fetch-receive-strict.sh +5 -0
+	git --git-dir=dst/.git branch -D bogus &&
+	git  --git-dir=dst/.git config --add \
+		receive.fsck.missingEmail ignore &&
+	git  --git-dir=dst/.git config --add \
+		receive.fsck.badDate warn &&

Funny double-SP (will locally fix).

There are a few other minor style nits (not in this patch but in other patches in the series) like

	s/free((char *) var)/free((char *)var)/;

that I locally added SQUASH, and I may also have tweaked some log messages. Please check what you will see in 'pu' when I push the day's integration out later.

Thanks.

#266 lore raw

Re: [PATCH v7 13/19] fsck: Optionally ignore specific fsck issues completely

Hi Junio,

Quoted 10 lines · Junio C Hamano

t/t5504-fetch-receive-strict.sh test_expect_success 'push with receive.fsck.missingEmail=warn' ' · line 141

Quoted 5 lines · Johannes Schindelin
t/t5504-fetch-receive-strict.sh +5 -0
+	git --git-dir=dst/.git branch -D bogus &&
+	git  --git-dir=dst/.git config --add \
+		receive.fsck.missingEmail ignore &&
+	git  --git-dir=dst/.git config --add \
+		receive.fsck.badDate warn &&

Funny double-SP (will locally fix).

Quoted 6 lines

There are a few other minor style nits (not in this patch but in other patches in the series) like

	s/free((char *) var)/free((char *)var)/;

that I locally added SQUASH,

I fixed all of this locally, ready to push out v8, but...

Quoted 1 line

and I may also have tweaked some log messages. Please check what you will see in 'pu' when I push the day's integration out later.

... I did not see that yet.

For the record, my current state is available at

    https://github.com/dscho/git/compare/fsck-api~19...fsck-api

I could wait for tomorrow to adjust my commit messages... or what do you want me to do?

Ciao,
Dscho

#267 lore raw

PATCH v7 14/19 fsck: Allow upgrading fsck warnings to errors

In reply to Johannes Schindelin

The 'invalid tag name' and 'missing tagger entry' warnings can now be upgraded to errors by specifying invalidTagName and missingTaggerEntry in the receive.fsck.<msg-id> config setting.

Incidentally, the missing tagger warning is now really shown as a warning (as opposed to being reported with the "error:" prefix, as it used to be the case before this commit).

---
 fsck.c                | 24 +++++++++++++++++-------
 t/t5302-pack-index.sh |  2 +-
 2 files changed, 18 insertions(+), 8 deletions(-)
fsck.c +17 -7
index cbfff1f..f6fc384 100644
@@ -10,6 +10,7 @@
 #include "utf8.h"
 
 #define FSCK_FATAL -1
+#define FSCK_INFO -2
 
 #define FOREACH_MSG_ID(FUNC) \
 	/* fatal errors */ \
@@ -50,15 +51,16 @@
 	FUNC(ZERO_PADDED_DATE, ERROR) \
 	/* warnings */ \
 	FUNC(BAD_FILEMODE, WARN) \
-	FUNC(BAD_TAG_NAME, WARN) \
 	FUNC(EMPTY_NAME, WARN) \
 	FUNC(FULL_PATHNAME, WARN) \
 	FUNC(HAS_DOT, WARN) \
 	FUNC(HAS_DOTDOT, WARN) \
 	FUNC(HAS_DOTGIT, WARN) \
-	FUNC(MISSING_TAGGER_ENTRY, WARN) \
 	FUNC(NULL_SHA1, WARN) \
-	FUNC(ZERO_PADDED_FILEMODE, WARN)
+	FUNC(ZERO_PADDED_FILEMODE, WARN) \
+	/* infos (reported as warnings, but ignored by default) */ \
+	FUNC(BAD_TAG_NAME, INFO) \
+	FUNC(MISSING_TAGGER_ENTRY, INFO)
 
 #define MSG_ID(id, msg_type) FSCK_MSG_##id,
 enum fsck_msg_id {
@@ -228,6 +230,8 @@ static int report(struct fsck_options *options, struct object *object,
 
 	if (msg_type == FSCK_FATAL)
 		msg_type = FSCK_ERROR;
+	else if (msg_type == FSCK_INFO)
+		msg_type = FSCK_WARN;
 
 	append_msg_id(&sb, msg_id_info[id].id_string);
 
@@ -686,15 +690,21 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
 		goto done;
 	}
 	strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
-	if (check_refname_format(sb.buf, 0))
-		report(options, &tag->object, FSCK_MSG_BAD_TAG_NAME,
+	if (check_refname_format(sb.buf, 0)) {
+		ret = report(options, &tag->object, FSCK_MSG_BAD_TAG_NAME,
 			   "invalid 'tag' name: %.*s",
 			   (int)(eol - buffer), buffer);
+		if (ret)
+			goto done;
+	}
 	buffer = eol + 1;
 
-	if (!skip_prefix(buffer, "tagger ", &buffer))
+	if (!skip_prefix(buffer, "tagger ", &buffer)) {
 		/* early tags do not contain 'tagger' lines; warn only */
-		report(options, &tag->object, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
+		ret = report(options, &tag->object, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
+		if (ret)
+			goto done;
+	}
 	else
 		ret = fsck_ident(&buffer, &tag->object, options);
 
t/t5302-pack-index.sh +1 -1
index 61bc8da..3dc5ec4 100755
@@ -259,7 +259,7 @@ EOF
     thirtyeight=${tag#??} &&
     rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight &&
     git index-pack --strict tag-test-${pack1}.pack 2>err &&
-    grep "^error:.* expected .tagger. line" err
+    grep "^warning:.* expected .tagger. line" err
 '
 
 test_done
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#268 lore raw

PATCH v7 15/19 fsck: Document the new receive.fsck.<msg-id> options

In reply to Johannes Schindelin
---
 Documentation/config.txt | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/config.txt +14 -0
index 3e37b93..4e5fbea 100644
@@ -2205,6 +2205,20 @@ receive.fsckObjects::
 	Defaults to false. If not set, the value of `transfer.fsckObjects`
 	is used instead.
 
+receive.fsck.<msg-id>::
+	When `receive.fsckObjects` is set to true, errors can be switched
+	to warnings and vice versa by configuring the `receive.fsck.<msg-id>`
+	setting where the `<msg-id>` is the fsck message ID and the value
+	is one of `error`, `warn` or `ignore`. For convenience, fsck prefixes
+	the error/warning with the message ID, e.g. "missingEmail: invalid
+	author/committer line - missing email" means that setting
+	`receive.fsck.missingEmail = ignore` will hide that issue.
++
+This feature is intended to support working with legacy repositories
+which would not pass pushing when `receive.fsckObjects = true`, allowing
+the host to accept repositories with certain known issues but still catch
+other issues.
+
 receive.unpackLimit::
 	If the number of objects received in a push is below this
 	limit then the objects will be unpacked into loose object
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#269 lore raw

PATCH v7 16/19 fsck: Support demoting errors to warnings

In reply to Johannes Schindelin

We already have support in git receive-pack to deal with some legacy repositories which have non-fatal issues.

Let's make git fsck itself useful with such repositories, too, by allowing users to ignore known issues, or at least demote those issues to mere warnings.

Example: git -c fsck.missingEmail=ignore fsck would hide problems with missing emails in author, committer and tagger lines.

In the same spirit that git receive-pack's usage of the fsck machinery differs from git fsck's – some of the non-fatal warnings in git fsck are fatal with git receive-pack when receive.fsckObjects = true, for example – we strictly separate the fsck.<msg-id> from the receive.fsck.<msg-id> settings.

---
 Documentation/config.txt | 11 +++++++++++
 builtin/fsck.c           | 12 ++++++++++++
 t/t1450-fsck.sh          | 11 +++++++++++
 3 files changed, 34 insertions(+)
Documentation/config.txt +11 -0
index 4e5fbea..bfccd2b 100644
@@ -1250,6 +1250,17 @@ filter.<driver>.smudge::
 	object to a worktree file upon checkout.  See
 	linkgit:gitattributes[5] for details.
 
+fsck.<msg-id>::
+	Allows overriding the message type (error, warn or ignore) of a
+	specific message ID such as `missingEmail`.
++
+For convenience, fsck prefixes the error/warning with the message ID,
+e.g.  "missingEmail: invalid author/committer line - missing email" means
+that setting `fsck.missingEmail = ignore` will hide that issue.
++
+This feature is intended to support working with legacy repositories
+which cannot be repaired without disruptive changes.
+
 gc.aggressiveDepth::
 	The depth parameter used in the delta compression
 	algorithm used by 'git gc --aggressive'.  This defaults
builtin/fsck.c +12 -0
index fff38fe..adaa802 100644
@@ -46,6 +46,16 @@ static int show_dangling = 1;
 #define DIRENT_SORT_HINT(de) ((de)->d_ino)
 #endif
 
+static int fsck_config(const char *var, const char *value, void *cb)
+{
+	if (skip_prefix(var, "fsck.", &var)) {
+		fsck_set_msg_type(&fsck_obj_options, var, value);
+		return 0;
+	}
+
+	return git_default_config(var, value, cb);
+}
+
 static void objreport(struct object *obj, const char *msg_type,
 			const char *err)
 {
@@ -646,6 +656,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 		include_reflogs = 0;
 	}
 
+	git_config(fsck_config, NULL);
+
 	fsck_head_link();
 	fsck_object_dir(get_object_directory());
 
t/t1450-fsck.sh +11 -0
index 7c5b3d5..1727129 100755
@@ -287,6 +287,17 @@ test_expect_success 'rev-list --verify-objects with bad sha1' '
 	grep -q "error: sha1 mismatch 63ffffffffffffffffffffffffffffffffffffff" out
 '
 
+test_expect_success 'force fsck to ignore double author' '
+	git cat-file commit HEAD >basis &&
+	sed "s/^author .*/&,&/" <basis | tr , \\n >multiple-authors &&
+	new=$(git hash-object -t commit -w --stdin <multiple-authors) &&
+	test_when_finished "remove_object $new" &&
+	git update-ref refs/heads/bogus "$new" &&
+	test_when_finished "git update-ref -d refs/heads/bogus" &&
+	test_must_fail git fsck &&
+	git -c fsck.multipleAuthors=ignore fsck
+'
+
 _bz='\0'
 _bz5="$_bz$_bz$_bz$_bz$_bz"
 _bz20="$_bz5$_bz5$_bz5$_bz5"
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#270 lore raw

PATCH v7 17/19 fsck: Introduce `git fsck --connectivity-only`

In reply to Johannes Schindelin

This option avoids unpacking each and all blob objects, and just verifies the connectivity. In particular with large repositories, this speeds up the operation, at the expense of missing corrupt blobs, ignoring unreachable objects and other fsck issues, if any.

---
 Documentation/git-fsck.txt |  7 ++++++-
 builtin/fsck.c             |  7 ++++++-
 t/t1450-fsck.sh            | 22 ++++++++++++++++++++++
 3 files changed, 34 insertions(+), 2 deletions(-)
Documentation/git-fsck.txt +6 -1
index 25c431d..84ee92e 100644
@@ -11,7 +11,7 @@ SYNOPSIS
 [verse]
 'git fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
 	 [--[no-]full] [--strict] [--verbose] [--lost-found]
-	 [--[no-]dangling] [--[no-]progress] [<object>*]
+	 [--[no-]dangling] [--[no-]progress] [--connectivity-only] [<object>*]
 
 DESCRIPTION
 -----------
@@ -60,6 +60,11 @@ index file, all SHA-1 references in `refs` namespace, and all reflogs
 	object pools.  This is now default; you can turn it off
 	with --no-full.
 
+--connectivity-only::
+	Check only the connectivity of tags, commits and tree objects. By
+	avoiding to unpack blobs, this speeds up the operation, at the
+	expense of missing corrupt objects or other problematic issues.
+
 --strict::
 	Enable more strict checking, namely to catch a file mode
 	recorded with g+w bit set, which was created by older
builtin/fsck.c +6 -1
index adaa802..2d14298 100644
@@ -23,6 +23,7 @@ static int show_tags;
 static int show_unreachable;
 static int include_reflogs = 1;
 static int check_full = 1;
+static int connectivity_only;
 static int check_strict;
 static int keep_cache_objects;
 static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT;
@@ -181,6 +182,8 @@ static void check_reachable_object(struct object *obj)
 	if (!(obj->flags & HAS_OBJ)) {
 		if (has_sha1_pack(obj->sha1))
 			return; /* it is in pack - forget about it */
+		if (connectivity_only && has_sha1_file(obj->sha1))
+			return;
 		printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1));
 		errors_found |= ERROR_REACHABLE;
 		return;
@@ -623,6 +626,7 @@ static struct option fsck_opts[] = {
 	OPT_BOOL(0, "cache", &keep_cache_objects, N_("make index objects head nodes")),
 	OPT_BOOL(0, "reflogs", &include_reflogs, N_("make reflogs head nodes (default)")),
 	OPT_BOOL(0, "full", &check_full, N_("also consider packs and alternate objects")),
+	OPT_BOOL(0, "connectivity-only", &connectivity_only, N_("check only connectivity")),
 	OPT_BOOL(0, "strict", &check_strict, N_("enable more strict checking")),
 	OPT_BOOL(0, "lost-found", &write_lost_and_found,
 				N_("write dangling objects in .git/lost-found")),
@@ -659,7 +663,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 	git_config(fsck_config, NULL);
 
 	fsck_head_link();
-	fsck_object_dir(get_object_directory());
+	if (!connectivity_only)
+		fsck_object_dir(get_object_directory());
 
 	prepare_alt_odb();
 	for (alt = alt_odb_list; alt; alt = alt->next) {
t/t1450-fsck.sh +22 -0
index 1727129..956673b 100755
@@ -431,4 +431,26 @@ test_expect_success 'fsck notices ref pointing to missing tag' '
 	test_must_fail git -C missing fsck
 '
 
+test_expect_success 'fsck --connectivity-only' '
+	rm -rf connectivity-only &&
+	git init connectivity-only &&
+	(
+		cd connectivity-only &&
+		touch empty &&
+		git add empty &&
+		test_commit empty &&
+		empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 &&
+		rm -f $empty &&
+		echo invalid >$empty &&
+		test_must_fail git fsck --strict &&
+		git fsck --strict --connectivity-only &&
+		tree=$(git rev-parse HEAD:) &&
+		suffix=${tree#??} &&
+		tree=.git/objects/${tree%$suffix}/$suffix &&
+		rm -f $tree &&
+		echo invalid >$tree &&
+		test_must_fail git fsck --strict --connectivity-only
+	)
+'
+
 test_done
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#271 lore raw

PATCH v7 18/19 fsck: git receive-pack: support excluding objects from fsck'ing

In reply to Johannes Schindelin

The optional new config option receive.fsck.skipList specifies the path to a file listing the names, i.e. SHA-1s, one per line, of objects that are to be ignored by git receive-pack when receive.fsckObjects = true.

This is extremely handy in case of legacy repositories where it would cause more pain to change incorrect objects than to live with them (e.g. a duplicate 'author' line in an early commit object).

The intended use case is for server administrators to inspect objects that are reported by git push as being too problematic to enter the repository, and to add the objects' SHA-1 to a (preferably sorted) file when the objects are legitimate, i.e. when it is determined that those problematic objects should be allowed to enter the server.

---
 Documentation/config.txt        |  8 +++++++
 builtin/receive-pack.c          | 11 +++++++++
 fsck.c                          | 50 +++++++++++++++++++++++++++++++++++++++++
 fsck.h                          |  1 +
 t/t5504-fetch-receive-strict.sh | 12 ++++++++++
 5 files changed, 82 insertions(+)
Documentation/config.txt +8 -0
index bfccd2b..ed7f37f 100644
@@ -2230,6 +2230,14 @@ which would not pass pushing when `receive.fsckObjects = true`, allowing
 the host to accept repositories with certain known issues but still catch
 other issues.
 
+receive.fsck.skipList::
+	The path to a sorted list of object names (i.e. one SHA-1 per
+	line) that are known to be broken in a non-fatal way and should
+	be ignored. This feature is useful when an established project
+	should be accepted despite early commits containing errors that
+	can be safely ignored such as invalid committer email addresses.
+	Note: corrupt objects cannot be skipped with this setting.
+
 receive.unpackLimit::
 	If the number of objects received in a push is below this
 	limit then the objects will be unpacked into loose object
builtin/receive-pack.c +11 -0
index 3afe8f8..3fbed23 100644
@@ -117,6 +117,17 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if (strcmp(var, "receive.fsck.skiplist") == 0) {
+		const char *path;
+
+		if (git_config_pathname(&path, var, value))
+			return 1;
+		strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
+			fsck_msg_types.len ? ',' : '=', path);
+		free((char *) path);
+		return 0;
+	}
+
 	if (skip_prefix(var, "receive.fsck.", &var)) {
 		if (is_valid_msg_type(var, value))
 			strbuf_addf(&fsck_msg_types, "%c%s=%s",
fsck.c +50 -0

74 lines not on this page · raw message

fsck.h +1 -0
index 1dab276..dded84b 100644
@@ -32,6 +32,7 @@ struct fsck_options {
 	fsck_error error_func;
 	unsigned strict:1;
 	int *msg_type;
+	struct sha1_array *skiplist;
 };
 
 #define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL }
t/t5504-fetch-receive-strict.sh +12 -0
index af373ba..6a1f89e 100755
@@ -123,6 +123,18 @@ committer Bugs Bunny <[email protected]> 1234567890 +0000
 This commit object intentionally broken
 EOF
 
+test_expect_success 'push with receive.fsck.skipList' '
+	commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
+	git push . $commit:refs/heads/bogus &&
+	rm -rf dst &&
+	git init dst &&
+	git --git-dir=dst/.git config receive.fsckObjects true &&
+	test_must_fail git push --porcelain dst bogus &&
+	git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
+	echo $commit >dst/.git/SKIP &&
+	git push --porcelain dst bogus
+'
+
 test_expect_success 'push with receive.fsck.missingEmail=warn' '
 	commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
 	git push . $commit:refs/heads/bogus &&
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#272 lore raw

PATCH v7 19/19 fsck: support ignoring objects in `git fsck` via fsck.skiplist

In reply to Johannes Schindelin

Identical to support in git receive-pack for the config option receive.fsck.skiplist, we now support ignoring given objects in git fsck via fsck.skiplist` altogether.

This is extremely handy in case of legacy repositories where it would cause more pain to change incorrect objects than to live with them (e.g. a duplicate 'author' line in an early commit object).

---
 Documentation/config.txt |  8 ++++++++
 builtin/fsck.c           | 13 +++++++++++++
 2 files changed, 21 insertions(+)
Documentation/config.txt +8 -0
index ed7f37f..69dda93 100644
@@ -1261,6 +1261,14 @@ that setting `fsck.missingEmail = ignore` will hide that issue.
 This feature is intended to support working with legacy repositories
 which cannot be repaired without disruptive changes.
 
+fsck.skipList::
+	The path to a sorted list of object names (i.e. one SHA-1 per
+	line) that are known to be broken in a non-fatal way and should
+	be ignored. This feature is useful when an established project
+	should be accepted despite early commits containing errors that
+	can be safely ignored such as invalid committer email addresses.
+	Note: corrupt objects cannot be skipped with this setting.
+
 gc.aggressiveDepth::
 	The depth parameter used in the delta compression
 	algorithm used by 'git gc --aggressive'.  This defaults
builtin/fsck.c +13 -0
index 2d14298..7e3df20 100644
@@ -49,6 +49,19 @@ static int show_dangling = 1;
 
 static int fsck_config(const char *var, const char *value, void *cb)
 {
+	if (strcmp(var, "fsck.skiplist") == 0) {
+		const char *path;
+		struct strbuf sb = STRBUF_INIT;
+
+		if (git_config_pathname(&path, var, value))
+			return 1;
+		strbuf_addf(&sb, "skiplist=%s", path);
+		free((char *) path);
+		fsck_set_msg_types(&fsck_obj_options, sb.buf);
+		strbuf_release(&sb);
+		return 0;
+	}
+
 	if (skip_prefix(var, "fsck.", &var)) {
 		fsck_set_msg_type(&fsck_obj_options, var, value);
 		return 0;
Signature · 1 line
2.3.1.windows.1.9.g8c01ab4
#273 lore raw
In reply to Johannes Schindelin
Quoted 15 lines · Johannes Schindelin

Changes since v6:

- camelCased message IDs

- multiple author checking now as suggested by Junio

- renamed --quick to --connectivity-only, better commit message

- fsck.skipList is now handled correctly (and not mistaken for a message type setting)

- fsck.skipList can handle user paths now

- index-pack configures the walk function in a more logical place now

Quoted 7 lines

- simplified code by avoiding working on partial strings (i.e. removed substrcmp()). This saves 10 lines. To accomodate parsing config variables directly, we now work on lowercased message IDs; unfortunately this means that we cannot use them in append_msg_id() because that function wants to append camelCased message IDs.

Interdiff below diffstat.

Except for minor nits I sent separate messages, this round looks very nicely done (I however admit that I haven't read the skiplist parsing code carefully at all, expecting that you wouldn't screw up with something simple like that ;-))

Thanks, will replace what is queued. Let's start thinking about moving it down to 'next' (meaning: we _could_ still accept a reroll, but I think we are in a good shape and minor incremental refinements would suffice), cooking it for the remainder of the cycle and having it graduate to 'master' at the beginning of the next cycle.

Thanks.

#274 lore raw

Hi Junio,

Quoted 30 lines · Junio C Hamano
Quoted 15 lines · Johannes Schindelin

Changes since v6:

- camelCased message IDs

- multiple author checking now as suggested by Junio

- renamed --quick to --connectivity-only, better commit message

- fsck.skipList is now handled correctly (and not mistaken for a message type setting)

- fsck.skipList can handle user paths now

- index-pack configures the walk function in a more logical place now

Quoted 7 lines

- simplified code by avoiding working on partial strings (i.e. removed substrcmp()). This saves 10 lines. To accomodate parsing config variables directly, we now work on lowercased message IDs; unfortunately this means that we cannot use them in append_msg_id() because that function wants to append camelCased message IDs.

Interdiff below diffstat.

Except for minor nits I sent separate messages, this round looks very nicely done (I however admit that I haven't read the skiplist parsing code carefully at all, expecting that you wouldn't screw up with something simple like that ;-))

Quoted 5 lines

Thanks, will replace what is queued. Let's start thinking about moving it down to 'next' (meaning: we _could_ still accept a reroll, but I think we are in a good shape and minor incremental refinements would suffice), cooking it for the remainder of the cycle and having it graduate to 'master' at the beginning of the next cycle.

Let me submit a v8 with the borked fixup fixed (i.e. part of 04/19 moved to 03/19, where it really belongs), the for style fix, the fixed double space and the cast style, too.

Ciao,
Dscho