From: Nguyễn Thái Ngọc Duy Date: Sat, 26 May 2018 13:55:23 +0000 (+0200) Subject: fsck: factor out msg_id_info[] lazy initialization code X-Git-Tag: v2.19.0-rc0~187^2~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a46baac61eb;p=thirdparty%2Fgit.git fsck: factor out msg_id_info[] lazy initialization code This array will be used by some other function than parse_msg_id() in the following commit. Factor out this prep code so it could be called from that one. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- diff --git a/fsck.c b/fsck.c index 640422a6c6..c004a37372 100644 --- a/fsck.c +++ b/fsck.c @@ -84,26 +84,34 @@ static struct { }; #undef MSG_ID -static int parse_msg_id(const char *text) +static void prepare_msg_ids(void) { int i; - if (!msg_id_info[0].downcased) { - /* convert id_string to lower case, without underscores. */ - for (i = 0; i < FSCK_MSG_MAX; i++) { - const char *p = msg_id_info[i].id_string; - int len = strlen(p); - char *q = xmalloc(len); - - msg_id_info[i].downcased = q; - while (*p) - if (*p == '_') - p++; - else - *(q)++ = tolower(*(p)++); - *q = '\0'; - } + if (msg_id_info[0].downcased) + return; + + /* convert id_string to lower case, without underscores. */ + for (i = 0; i < FSCK_MSG_MAX; i++) { + const char *p = msg_id_info[i].id_string; + int len = strlen(p); + char *q = xmalloc(len); + + msg_id_info[i].downcased = q; + while (*p) + if (*p == '_') + p++; + else + *(q)++ = tolower(*(p)++); + *q = '\0'; } +} + +static int parse_msg_id(const char *text) +{ + int i; + + prepare_msg_ids(); for (i = 0; i < FSCK_MSG_MAX; i++) if (!strcmp(text, msg_id_info[i].downcased))