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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
May 26, 2018 at 15:55 UTC
a46baac61ebc6a8b187f76bcd49b625e0d4f408e
1 file changed
+24
-16
fsck.c
+24
-16
@@ -84,26 +84,34 @@ static struct {
84
};
85
#undef MSG_ID
86
87
-static int parse_msg_id(const char *text)
87
+static void prepare_msg_ids(void)
88
{
89
int i;
90
91
- if (!msg_id_info[0].downcased) {
92
- /* convert id_string to lower case, without underscores. */
93
- for (i = 0; i < FSCK_MSG_MAX; i++) {
94
- const char *p = msg_id_info[i].id_string;
95
- int len = strlen(p);
96
- char *q = xmalloc(len);
97
-
98
- msg_id_info[i].downcased = q;
99
- while (*p)
100
- if (*p == '_')
101
- p++;
102
- else
103
- *(q)++ = tolower(*(p)++);
104
- *q = '\0';
105
- }
91
+ if (msg_id_info[0].downcased)
92
+ return;
93
+
94
+ /* convert id_string to lower case, without underscores. */
95
+ for (i = 0; i < FSCK_MSG_MAX; i++) {
96
+ const char *p = msg_id_info[i].id_string;
97
+ int len = strlen(p);
98
+ char *q = xmalloc(len);
99
+
100
+ msg_id_info[i].downcased = q;
101
+ while (*p)
102
+ if (*p == '_')
103
+ p++;
104
+ else
105
+ *(q)++ = tolower(*(p)++);
106
+ *q = '\0';
107
}
108
+}
109
+
110
+static int parse_msg_id(const char *text)
111
+{
112
+ int i;
113
+
114
+ prepare_msg_ids();
115
116
for (i = 0; i < FSCK_MSG_MAX; i++)
117
if (!strcmp(text, msg_id_info[i].downcased))