[PATCH 2/5] Improve message-id generation flow control for format-patch

Previous thread: [PATCH] branch: optionally setup branch.*.merge from upstream local branches by Jay Soffian on Monday, February 18, 2008 - 7:07 pm. (14 messages)

Next thread: [PATCH 4/5] Retain extra blank lines between the summary and the body by Daniel Barkalow on Monday, February 18, 2008 - 8:56 pm. (1 message)
From: Daniel Barkalow
Date: Monday, February 18, 2008 - 8:56 pm

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
 builtin-log.c |   29 ++++++++++++++---------------
 revision.h    |    2 +-
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/builtin-log.c b/builtin-log.c
index 99d69f0..4f08ca4 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -575,16 +575,19 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const cha
 	o2->flags = flags2;
 }
 
-static void gen_message_id(char *dest, unsigned int length, char *base)
+static void gen_message_id(struct rev_info *info, char *base)
 {
 	const char *committer = git_committer_info(IDENT_WARN_ON_NO_NAME);
 	const char *email_start = strrchr(committer, '<');
 	const char *email_end = strrchr(committer, '>');
-	if(!email_start || !email_end || email_start > email_end - 1)
+	struct strbuf buf;
+	if (!email_start || !email_end || email_start > email_end - 1)
 		die("Could not extract email from committer identity.");
-	snprintf(dest, length, "%s.%lu.git.%.*s", base,
-		 (unsigned long) time(NULL),
-		 (int)(email_end - email_start - 1), email_start + 1);
+	strbuf_init(&buf, 0);
+	strbuf_addf(&buf, "%s.%lu.git.%.*s", base,
+		    (unsigned long) time(NULL),
+		    (int)(email_end - email_start - 1), email_start + 1);
+	info->message_id = strbuf_detach(&buf, NULL);
 }
 
 static const char *clean_message_id(const char *msg_id)
@@ -625,8 +628,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	const char *in_reply_to = NULL;
 	struct patch_ids ids;
 	char *add_signoff = NULL;
-	char message_id[1024];
-	char ref_message_id[1024];
 
 	git_config(git_format_config);
 	init_revisions(&rev, prefix);
@@ -809,15 +810,13 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		rev.nr = total - nr + (start_number - 1);
 		/* Make the second and subsequent mails replies to the first */
 		if (thread) {
-			if (nr == (total - 2)) {
-				strncpy(ref_message_id, ...
From: Johannes Schindelin
Date: Tuesday, February 19, 2008 - 6:01 am

Hi,


Mini-nit: technically, ref_message_id should be "char *", too.

Ciao,
Dscho

-

From: Daniel Barkalow
Date: Tuesday, February 19, 2008 - 9:26 am

I'd intended ref_message_id to just reference the string owned by a 
different message's message_id, but that doesn't really work with struct 
rev_info. I bet you'd like me to not leak memory out through 
ref_message_id, too. I think I want to see how the code to collect the set 
of commits in the series (for more capable generation of cover letter 
contents) goes before changing this either way.

(It's incidentally kind of amusing that you managed to convey the way you 
thought the code should be designed, different from how I'd designed it, 
through a note on whether a struct field should be const or not.)

	-Daniel
*This .sig left intentionally blank*
-

From: Johannes Schindelin
Date: Tuesday, February 19, 2008 - 9:51 am

Hi,


Hehe!

You're right in that the revision machinery needs some cleaning up.  AFAIK 
there is no method yet to release the memory allocated during one revision 
walk (including the preparation).

And you're right that this should be done separately, so please kindly 
accept my apologies while I retract my comment.

Ciao,
Dscho

-

Previous thread: [PATCH] branch: optionally setup branch.*.merge from upstream local branches by Jay Soffian on Monday, February 18, 2008 - 7:07 pm. (14 messages)

Next thread: [PATCH 4/5] Retain extra blank lines between the summary and the body by Daniel Barkalow on Monday, February 18, 2008 - 8:56 pm. (1 message)