imap-send: store all_msgs as a strbuf

all_msgs is only used as a glorified string, therefore there is no reason to declare it as a struct msg_data. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Nov 25, 2012 at 12:08 UTC 3a34e62684b6dc0edf1301eb2259132ffc233c48
1 file changed +9 -14
imap-send.c
+9 -14
@@ -1391,26 +1391,20 @@ static void wrap_in_html(struct msg_data *msg)
1391
1392 #define CHUNKSIZE 0x1000
1393
1394 -static int read_message(FILE *f, struct msg_data *msg)
1394 +static int read_message(FILE *f, struct strbuf *all_msgs)
1395 {
1396 - struct strbuf buf = STRBUF_INIT;
1397 -
1398 - memset(msg, 0, sizeof(*msg));
1399 -
1396 do {
1401 - if (strbuf_fread(&buf, CHUNKSIZE, f) <= 0)
1397 + if (strbuf_fread(all_msgs, CHUNKSIZE, f) <= 0)
1398 break;
1399 } while (!feof(f));
1400
1405 - msg->len = buf.len;
1406 - msg->data = strbuf_detach(&buf, NULL);
1407 - return msg->len;
1401 + return all_msgs->len;
1402 }
1403
1410 -static int count_messages(struct msg_data *msg)
1404 +static int count_messages(struct strbuf *all_msgs)
1405 {
1406 int count = 0;
1413 - char *p = msg->data;
1407 + char *p = all_msgs->buf;
1408
1409 while (1) {
1410 if (!prefixcmp(p, "From ")) {
@@ -1431,7 +1425,7 @@ static int count_messages(struct msg_data *msg)
1425 return count;
1426 }
1427
1434 -static int split_msg(struct msg_data *all_msgs, struct msg_data *msg, int *ofs)
1428 +static int split_msg(struct strbuf *all_msgs, struct msg_data *msg, int *ofs)
1429 {
1430 char *p, *data;
1431
@@ -1439,7 +1433,7 @@ static int split_msg(struct msg_data *all_msgs, struct msg_data *msg, int *ofs)
1433 if (*ofs >= all_msgs->len)
1434 return 0;
1435
1442 - data = &all_msgs->data[*ofs];
1436 + data = &all_msgs->buf[*ofs];
1437 msg->len = all_msgs->len - *ofs;
1438
1439 if (msg->len < 5 || prefixcmp(data, "From "))
@@ -1509,7 +1503,8 @@ static int git_imap_config(const char *key, const char *val, void *cb)
1503
1504 int main(int argc, char **argv)
1505 {
1512 - struct msg_data all_msgs, msg;
1506 + struct strbuf all_msgs = STRBUF_INIT;
1507 + struct msg_data msg;
1508 struct store *ctx = NULL;
1509 int ofs = 0;
1510 int r;