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>
maint
Johannes Schindelin 2015-06-22 17:26:54 +02:00 committed by Junio C Hamano
parent efaba7cc77
commit f27d05b170
2 changed files with 18 additions and 8 deletions

24
fsck.c
View File

@ -10,6 +10,7 @@
#include "utf8.h" #include "utf8.h"


#define FSCK_FATAL -1 #define FSCK_FATAL -1
#define FSCK_INFO -2


#define FOREACH_MSG_ID(FUNC) \ #define FOREACH_MSG_ID(FUNC) \
/* fatal errors */ \ /* fatal errors */ \
@ -50,15 +51,16 @@
FUNC(ZERO_PADDED_DATE, ERROR) \ FUNC(ZERO_PADDED_DATE, ERROR) \
/* warnings */ \ /* warnings */ \
FUNC(BAD_FILEMODE, WARN) \ FUNC(BAD_FILEMODE, WARN) \
FUNC(BAD_TAG_NAME, WARN) \
FUNC(EMPTY_NAME, WARN) \ FUNC(EMPTY_NAME, WARN) \
FUNC(FULL_PATHNAME, WARN) \ FUNC(FULL_PATHNAME, WARN) \
FUNC(HAS_DOT, WARN) \ FUNC(HAS_DOT, WARN) \
FUNC(HAS_DOTDOT, WARN) \ FUNC(HAS_DOTDOT, WARN) \
FUNC(HAS_DOTGIT, WARN) \ FUNC(HAS_DOTGIT, WARN) \
FUNC(MISSING_TAGGER_ENTRY, WARN) \
FUNC(NULL_SHA1, 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, #define MSG_ID(id, msg_type) FSCK_MSG_##id,
enum fsck_msg_id { enum fsck_msg_id {
@ -229,6 +231,8 @@ static int report(struct fsck_options *options, struct object *object,


if (msg_type == FSCK_FATAL) if (msg_type == FSCK_FATAL)
msg_type = FSCK_ERROR; msg_type = FSCK_ERROR;
else if (msg_type == FSCK_INFO)
msg_type = FSCK_WARN;


append_msg_id(&sb, msg_id_info[id].id_string); append_msg_id(&sb, msg_id_info[id].id_string);


@ -687,15 +691,21 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
goto done; goto done;
} }
strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer); strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
if (check_refname_format(sb.buf, 0)) if (check_refname_format(sb.buf, 0)) {
report(options, &tag->object, FSCK_MSG_BAD_TAG_NAME, ret = report(options, &tag->object, FSCK_MSG_BAD_TAG_NAME,
"invalid 'tag' name: %.*s", "invalid 'tag' name: %.*s",
(int)(eol - buffer), buffer); (int)(eol - buffer), buffer);
if (ret)
goto done;
}
buffer = eol + 1; buffer = eol + 1;


if (!skip_prefix(buffer, "tagger ", &buffer)) if (!skip_prefix(buffer, "tagger ", &buffer)) {
/* early tags do not contain 'tagger' lines; warn only */ /* 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 else
ret = fsck_ident(&buffer, &tag->object, options); ret = fsck_ident(&buffer, &tag->object, options);



View File

@ -259,7 +259,7 @@ EOF
thirtyeight=${tag#??} && thirtyeight=${tag#??} &&
rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight && rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight &&
git index-pack --strict tag-test-${pack1}.pack 2>err && git index-pack --strict tag-test-${pack1}.pack 2>err &&
grep "^error:.* expected .tagger. line" err grep "^warning:.* expected .tagger. line" err
' '


test_done test_done