revert: Simplify and inline add_message_to_msg

The add_message_to_msg function has some dead code, an unclear API, only one callsite. While it originally intended fill up an empty commit message with the commit object name while picking, it really doesn't do this -- a bug introduced in v1.5.1-rc1~65^2~2 (Make git-revert & git-cherry-pick a builtin, 2007-03-01). Today, tests in t3505-cherry-pick-empty.sh indicate that not filling up an empty commit message is the desired behavior. Re-implement and inline the function accordingly, with a beneficial side-effect: don't dereference a NULL pointer when the commit doesn't have a delimeter after the header. Helped-by: Junio C Hamano <gitster@pobox.com> Mentored-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramkumar Ramachandra committed Aug 4, 2011 at 16:09 UTC be33c46cda2cd74344d338150019cbabd88df12f
1 file changed +14 -14
builtin/revert.c
+14 -14
@@ -185,19 +185,6 @@ static char *get_encoding(const char *message)
185 return NULL;
186 }
187
188 -static void add_message_to_msg(struct strbuf *msgbuf, const char *message)
189 -{
190 - const char *p = message;
191 - while (*p && (*p != '\n' || p[1] != '\n'))
192 - p++;
193 -
194 - if (!*p)
195 - strbuf_addstr(msgbuf, sha1_to_hex(commit->object.sha1));
196 -
197 - p += 2;
198 - strbuf_addstr(msgbuf, p);
199 -}
200 -
188 static void write_cherry_pick_head(void)
189 {
190 int fd;
@@ -462,11 +449,24 @@ static int do_pick_commit(void)
449 }
450 strbuf_addstr(&msgbuf, ".\n");
451 } else {
452 + const char *p;
453 +
454 base = parent;
455 base_label = msg.parent_label;
456 next = commit;
457 next_label = msg.label;
469 - add_message_to_msg(&msgbuf, msg.message);
458 +
459 + /*
460 + * Append the commit log message to msgbuf; it starts
461 + * after the tree, parent, author, committer
462 + * information followed by "\n\n".
463 + */
464 + p = strstr(msg.message, "\n\n");
465 + if (p) {
466 + p += 2;
467 + strbuf_addstr(&msgbuf, p);
468 + }
469 +
470 if (no_replay) {
471 strbuf_addstr(&msgbuf, "(cherry picked from commit ");
472 strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));