fsck: report the ID of the error/warning

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>

Johannes Schindelin committed Jun 22, 2015 at 17:25 UTC 71ab8fa840fcca4b4f80acba6a529e3cbc174b65
2 files changed +22 -2
fsck.c
+20
@@ -189,6 +189,24 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
189 free(to_free);
190 }
191
192 +static void append_msg_id(struct strbuf *sb, const char *msg_id)
193 +{
194 + for (;;) {
195 + char c = *(msg_id)++;
196 +
197 + if (!c)
198 + break;
199 + if (c != '_')
200 + strbuf_addch(sb, tolower(c));
201 + else {
202 + assert(*msg_id);
203 + strbuf_addch(sb, *(msg_id)++);
204 + }
205 + }
206 +
207 + strbuf_addstr(sb, ": ");
208 +}
209 +
210 __attribute__((format (printf, 4, 5)))
211 static int report(struct fsck_options *options, struct object *object,
212 enum fsck_msg_id id, const char *fmt, ...)
@@ -197,6 +215,8 @@ static int report(struct fsck_options *options, struct object *object,
215 struct strbuf sb = STRBUF_INIT;
216 int msg_type = fsck_msg_type(id, options), result;
217
218 + append_msg_id(&sb, msg_id_info[id].id_string);
219 +
220 va_start(ap, fmt);
221 strbuf_vaddf(&sb, fmt, ap);
222 result = options->error_func(object, msg_type, sb.buf);
t/t1450-fsck.sh
+2 -2
@@ -231,8 +231,8 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
231 git fsck --tags 2>out &&
232
233 cat >expect <<-EOF &&
234 - warning in tag $tag: invalid '\''tag'\'' name: wrong name format
235 - warning in tag $tag: invalid format - expected '\''tagger'\'' line
234 + warning in tag $tag: badTagName: invalid '\''tag'\'' name: wrong name format
235 + warning in tag $tag: missingTaggerEntry: invalid format - expected '\''tagger'\'' line
236 EOF
237 test_cmp expect out
238 '