Skip to content

Commit 034a7b7

Browse files
avargitster
authored andcommitted
fsck.c: remove (mostly) redundant append_msg_id() function
Remove the append_msg_id() function in favor of calling prepare_msg_ids(). We already have code to compute the camel-cased msg_id strings in msg_id_info, let's use it. When the append_msg_id() function was added in 71ab8fa (fsck: report the ID of the error/warning, 2015-06-22) the prepare_msg_ids() function didn't exist. When prepare_msg_ids() was added in a46baac (fsck: factor out msg_id_info[] lazy initialization code, 2018-05-26) this code wasn't moved over to lazy initialization. This changes the behavior of the code to initialize all the messages instead of just camel-casing the one we need on the fly. Since the common case is that we're printing just one message this is mostly redundant work. But that's OK in this case, reporting this fsck issue to the user isn't performance-sensitive. If we were somehow doing so in a tight loop (in a hopelessly broken repository?) this would help, since we'd save ourselves from re-doing this work for identical messages, we could just grab the prepared string from msg_id_info after the first invocation. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1abc2d commit 034a7b7

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

fsck.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -264,24 +264,6 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values)
264264
free(to_free);
265265
}
266266

267-
static void append_msg_id(struct strbuf *sb, const char *msg_id)
268-
{
269-
for (;;) {
270-
char c = *(msg_id)++;
271-
272-
if (!c)
273-
break;
274-
if (c != '_')
275-
strbuf_addch(sb, tolower(c));
276-
else {
277-
assert(*msg_id);
278-
strbuf_addch(sb, *(msg_id)++);
279-
}
280-
}
281-
282-
strbuf_addstr(sb, ": ");
283-
}
284-
285267
static int object_on_skiplist(struct fsck_options *opts,
286268
const struct object_id *oid)
287269
{
@@ -308,7 +290,8 @@ static int report(struct fsck_options *options,
308290
else if (msg_type == FSCK_INFO)
309291
msg_type = FSCK_WARN;
310292

311-
append_msg_id(&sb, msg_id_info[id].id_string);
293+
prepare_msg_ids();
294+
strbuf_addf(&sb, "%s: ", msg_id_info[id].camelcased);
312295

313296
va_start(ap, fmt);
314297
strbuf_vaddf(&sb, fmt, ap);

0 commit comments

Comments
 (0)