fsck: disallow demoting grave fsck errors to warnings

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. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jun 22, 2015 at 17:26 UTC f50c44073051820cd368be4ca520ae43f34fdf8b
2 files changed +22 -2
fsck.c
+11 -2
@@ -9,7 +9,12 @@
9 #include "refs.h"
10 #include "utf8.h"
11
12 +#define FSCK_FATAL -1
13 +
14 #define FOREACH_MSG_ID(FUNC) \
15 + /* fatal errors */ \
16 + FUNC(NUL_IN_HEADER, FATAL) \
17 + FUNC(UNTERMINATED_HEADER, FATAL) \
18 /* errors */ \
19 FUNC(BAD_DATE, ERROR) \
20 FUNC(BAD_DATE_OVERFLOW, ERROR) \
@@ -39,11 +44,9 @@
44 FUNC(MISSING_TYPE, ERROR) \
45 FUNC(MISSING_TYPE_ENTRY, ERROR) \
46 FUNC(MULTIPLE_AUTHORS, ERROR) \
42 - FUNC(NUL_IN_HEADER, ERROR) \
47 FUNC(TAG_OBJECT_NOT_TAG, ERROR) \
48 FUNC(TREE_NOT_SORTED, ERROR) \
49 FUNC(UNKNOWN_TYPE, ERROR) \
46 - FUNC(UNTERMINATED_HEADER, ERROR) \
50 FUNC(ZERO_PADDED_DATE, ERROR) \
51 /* warnings */ \
52 FUNC(BAD_FILEMODE, WARN) \
@@ -149,6 +152,9 @@ void fsck_set_msg_type(struct fsck_options *options,
152 die("Unhandled message id: %s", msg_id);
153 type = parse_msg_type(msg_type);
154
155 + if (type != FSCK_ERROR && msg_id_info[id].msg_type == FSCK_FATAL)
156 + die("Cannot demote %s to %s", msg_id, msg_type);
157 +
158 if (!options->msg_type) {
159 int i;
160 int *msg_type = xmalloc(sizeof(int) * FSCK_MSG_MAX);
@@ -216,6 +222,9 @@ static int report(struct fsck_options *options, struct object *object,
222 struct strbuf sb = STRBUF_INIT;
223 int msg_type = fsck_msg_type(id, options), result;
224
225 + if (msg_type == FSCK_FATAL)
226 + msg_type = FSCK_ERROR;
227 +
228 append_msg_id(&sb, msg_id_info[id].id_string);
229
230 va_start(ap, fmt);
t/t5504-fetch-receive-strict.sh
+11
@@ -136,4 +136,15 @@ test_expect_success 'push with receive.fsck.missingEmail=warn' '
136 grep "missingEmail" act
137 '
138
139 +test_expect_success \
140 + 'receive.fsck.unterminatedHeader=warn triggers error' '
141 + rm -rf dst &&
142 + git init dst &&
143 + git --git-dir=dst/.git config receive.fsckobjects true &&
144 + git --git-dir=dst/.git config \
145 + receive.fsck.unterminatedheader warn &&
146 + test_must_fail git push --porcelain dst HEAD >act 2>&1 &&
147 + grep "Cannot demote unterminatedheader" act
148 +'
149 +
150 test_done