git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Jeremy White <jwhite@codeweavers.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Michael Haggerty <mhagger@alum.mit.edu>
Subject: [PATCH 4/8] imap-send: store all_msgs as a strbuf
Date: Sun, 25 Nov 2012 12:08:37 +0100	[thread overview]
Message-ID: <1353841721-16269-5-git-send-email-mhagger@alum.mit.edu> (raw)
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

  parent reply	other threads:[~2012-11-25 11:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-25 11:08 [PATCH 0/8] Add function strbuf_addstr_xml_quoted() and more Michael Haggerty
2012-11-25 11:08 ` [PATCH 1/8] Add new function strbuf_add_xml_quoted() Michael Haggerty
2012-11-25 11:08 ` [PATCH 2/8] xml_entities(): use function strbuf_addstr_xml_quoted() Michael Haggerty
2012-11-25 11:08 ` [PATCH 3/8] lf_to_crlf(): NUL-terminate msg_data::data Michael Haggerty
2012-11-25 11:08 ` Michael Haggerty [this message]
2012-11-25 11:08 ` [PATCH 5/8] imap-send: correctly report errors reading from stdin Michael Haggerty
2012-11-25 11:08 ` [PATCH 6/8] imap-send: change msg_data from storing (char *, len) to storing strbuf Michael Haggerty
2012-11-29 21:30   ` Junio C Hamano
2012-11-29 23:43     ` Jeff King
2012-11-30 13:36     ` Michael Haggerty
2012-12-02  1:48       ` Junio C Hamano
2012-12-02  6:03         ` Michael Haggerty
2012-12-03 15:06         ` Thiago Farina
2012-11-25 11:08 ` [PATCH 7/8] wrap_in_html(): use strbuf_addstr_xml_quoted() Michael Haggerty
2012-11-29 21:41 ` [PATCH 0/8] Add function strbuf_addstr_xml_quoted() and more Junio C Hamano
     [not found] ` <1353841721-16269-9-git-send-email-mhagger@alum.mit.edu>
     [not found]   ` <7v7gp4p00u.fsf@alter.siamese.dyndns.org>
2012-11-30 13:40     ` [PATCH 8/8] wrap_in_html(): process message in bulk rather than line-by-line Michael Haggerty
2012-12-02  9:25       ` Junio C Hamano
2012-12-02 10:35         ` Michael Haggerty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1353841721-16269-5-git-send-email-mhagger@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jwhite@codeweavers.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).