Skip to content

Commit

Permalink
fsck: report the ID of the error/warning
Browse files Browse the repository at this point in the history
Some repositories written by legacy code have objects with non-fatal
fsck issues. To allow 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`).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Jun 23, 2015
1 parent 5d477a3 commit 71ab8fa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,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, ...)
Expand All @@ -197,6 +215,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);
Expand Down
4 changes: 2 additions & 2 deletions t/t1450-fsck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
'
Expand Down

0 comments on commit 71ab8fa

Please sign in to comment.