git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/8] imap-send: store all_msgs as a strbuf

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Nov 25, 2012, 11:08 UTC
Message-ID
<1353841721-16269-5-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1353841721-16269-1-git-send-email-mhagger@alum.mit.edu>

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>
---
 imap-send.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/imap-send.c b/imap-send.c
index c818b0c..50e223a 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1391,26 +1391,20 @@ static void wrap_in_html(struct msg_data *msg)
 
 #define CHUNKSIZE 0x1000
 
-static int read_message(FILE *f, struct msg_data *msg)
+static int read_message(FILE *f, struct strbuf *all_msgs)
 {
-	struct strbuf buf = STRBUF_INIT;
-
-	memset(msg, 0, sizeof(*msg));
-
 	do {
-		if (strbuf_fread(&buf, CHUNKSIZE, f) <= 0)
+		if (strbuf_fread(all_msgs, CHUNKSIZE, f) <= 0)
 			break;
 	} while (!feof(f));
 
-	msg->len  = buf.len;
-	msg->data = strbuf_detach(&buf, NULL);
-	return msg->len;
+	return all_msgs->len;
 }
 
-static int count_messages(struct msg_data *msg)
+static int count_messages(struct strbuf *all_msgs)
 {
 	int count = 0;
-	char *p = msg->data;
+	char *p = all_msgs->buf;
 
 	while (1) {
 		if (!prefixcmp(p, "From ")) {
@@ -1431,7 +1425,7 @@ static int count_messages(struct msg_data *msg)
 	return count;
 }
 
-static int split_msg(struct msg_data *all_msgs, struct msg_data *msg, int *ofs)
+static int split_msg(struct strbuf *all_msgs, struct msg_data *msg, int *ofs)
 {
 	char *p, *data;
 
@@ -1439,7 +1433,7 @@ static int split_msg(struct msg_data *all_msgs, struct msg_data *msg, int *ofs)
 	if (*ofs >= all_msgs->len)
 		return 0;
 
-	data = &all_msgs->data[*ofs];
+	data = &all_msgs->buf[*ofs];
 	msg->len = all_msgs->len - *ofs;
 
 	if (msg->len < 5 || prefixcmp(data, "From "))
@@ -1509,7 +1503,8 @@ static int git_imap_config(const char *key, const char *val, void *cb)
 
 int main(int argc, char **argv)
 {
-	struct msg_data all_msgs, msg;
+	struct strbuf all_msgs = STRBUF_INIT;
+	struct msg_data msg;
 	struct store *ctx = NULL;
 	int ofs = 0;
 	int r;
-- 
1.8.0
Previous: Michael HaggertyNext: Michael Haggerty
Message 5 of 18 in “Add function strbuf_addstr_xml_quoted() and more”
  1. 0/8 Add function strbuf_addstr_xml_quoted() and moreMichael Haggerty, Nov 25, 2012
  2. 1/8 Add new function strbuf_add_xml_quoted()Michael Haggerty, Nov 25, 2012
  3. 2/8 xml_entities(): use function strbuf_addstr_xml_quoted()Michael Haggerty, Nov 25, 2012
  4. 3/8 lf_to_crlf(): NUL-terminate msg_data::dataMichael Haggerty, Nov 25, 2012
  5. 4/8 imap-send: store all_msgs as a strbufMichael Haggerty, Nov 25, 2012
  6. 5/8 imap-send: correctly report errors reading from stdinMichael Haggerty, Nov 25, 2012
  7. 6/8 imap-send: change msg_data from storing (char *, len) to storing strbufMichael Haggerty, Nov 25, 2012
  8. Junio C HamanoNov 29, 2012
  9. Jeff KingNov 29, 2012
  10. Michael HaggertyNov 30, 2012
  11. Junio C HamanoDec 2, 2012
  12. Michael HaggertyDec 2, 2012
  13. Thiago FarinaDec 3, 2012
  14. 7/8 wrap_in_html(): use strbuf_addstr_xml_quoted()Michael Haggerty, Nov 25, 2012
  15. Junio C HamanoNov 29, 2012
  16. Michael HaggertyNov 30, 2012
  17. Junio C HamanoDec 2, 2012
  18. Michael HaggertyDec 2, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.