fsck: allow upgrading fsck warnings to errors

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). 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 f27d05b17041d6e5c8cedced682709b2f1007ecc
2 files changed +18 -8
fsck.c
+17 -7
@@ -10,6 +10,7 @@
10 #include "utf8.h"
11
12 #define FSCK_FATAL -1
13 +#define FSCK_INFO -2
14
15 #define FOREACH_MSG_ID(FUNC) \
16 /* fatal errors */ \
@@ -50,15 +51,16 @@
51 FUNC(ZERO_PADDED_DATE, ERROR) \
52 /* warnings */ \
53 FUNC(BAD_FILEMODE, WARN) \
53 - FUNC(BAD_TAG_NAME, WARN) \
54 FUNC(EMPTY_NAME, WARN) \
55 FUNC(FULL_PATHNAME, WARN) \
56 FUNC(HAS_DOT, WARN) \
57 FUNC(HAS_DOTDOT, WARN) \
58 FUNC(HAS_DOTGIT, WARN) \
59 - FUNC(MISSING_TAGGER_ENTRY, WARN) \
59 FUNC(NULL_SHA1, WARN) \
61 - FUNC(ZERO_PADDED_FILEMODE, WARN)
60 + FUNC(ZERO_PADDED_FILEMODE, WARN) \
61 + /* infos (reported as warnings, but ignored by default) */ \
62 + FUNC(BAD_TAG_NAME, INFO) \
63 + FUNC(MISSING_TAGGER_ENTRY, INFO)
64
65 #define MSG_ID(id, msg_type) FSCK_MSG_##id,
66 enum fsck_msg_id {
@@ -229,6 +231,8 @@ static int report(struct fsck_options *options, struct object *object,
231
232 if (msg_type == FSCK_FATAL)
233 msg_type = FSCK_ERROR;
234 + else if (msg_type == FSCK_INFO)
235 + msg_type = FSCK_WARN;
236
237 append_msg_id(&sb, msg_id_info[id].id_string);
238
@@ -687,15 +691,21 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
691 goto done;
692 }
693 strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
690 - if (check_refname_format(sb.buf, 0))
691 - report(options, &tag->object, FSCK_MSG_BAD_TAG_NAME,
694 + if (check_refname_format(sb.buf, 0)) {
695 + ret = report(options, &tag->object, FSCK_MSG_BAD_TAG_NAME,
696 "invalid 'tag' name: %.*s",
697 (int)(eol - buffer), buffer);
698 + if (ret)
699 + goto done;
700 + }
701 buffer = eol + 1;
702
696 - if (!skip_prefix(buffer, "tagger ", &buffer))
703 + if (!skip_prefix(buffer, "tagger ", &buffer)) {
704 /* early tags do not contain 'tagger' lines; warn only */
698 - report(options, &tag->object, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
705 + ret = report(options, &tag->object, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
706 + if (ret)
707 + goto done;
708 + }
709 else
710 ret = fsck_ident(&buffer, &tag->object, options);
711
t/t5302-pack-index.sh
+1 -1
@@ -259,7 +259,7 @@ EOF
259 thirtyeight=${tag#??} &&
260 rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight &&
261 git index-pack --strict tag-test-${pack1}.pack 2>err &&
262 - grep "^error:.* expected .tagger. line" err
262 + grep "^warning:.* expected .tagger. line" err
263 '
264
265 test_done