Subject: Re: [RFC/PATCH] log: add log.firstparent option

From: Jeff King <[email-masked]>
Date: Fri, 24 Jul 2015 18:36:36 -0700

On Fri, Jul 24, 2015 at 08:31:55AM -0700, Junio C Hamano wrote:

> Jeff King <[email-masked]> writes:
> 
> > Whoops. Usually I "format-patch -s" and then add any notes while
> > sending. But the wifi at OSCON was so abysmal that instead I wrote the
> > notes directly into the commit message to send the whole thing later.
> > And of course format-patch is not smart enough to know that I meant
> > everything after the "---" as notes. :)
> 
> I think in the cycle we merged Couder's trailer stuff we updated the
> helper functions to locate where the S-o-b should go in an existing
> message and consolidated (or, at least "talked about consolidating")
> them into a single helper.  I do not think we wrote any special case
> for "a line with three-dashes and nothing else on it" when we did
> so, but that function would be the logical place to do so.

Yeah, it nicely has the concept of "ignore this footer". But we would
want it only to kick in when doing emails (where the "---" is
syntactically significant), I would think. So something like the patch
below (no commit message because I'm in an airport right now; I'll add
tests and repost in the next day or two).

diff --git a/log-tree.c b/log-tree.c
index 7b1b57a..8a9c35b 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -688,8 +688,16 @@ void show_log(struct rev_info *opt)
 		ctx.from_ident = &opt->from_ident;
 	pretty_print_commit(&ctx, commit, &msgbuf);
 
-	if (opt->add_signoff)
-		append_signoff(&msgbuf, 0, APPEND_SIGNOFF_DEDUP);
+	if (opt->add_signoff) {
+		int ignore = 0;
+		if (ctx.fmt == CMIT_FMT_EMAIL) {
+			const char *dashes = strstr(msgbuf.buf, "---\n");
+			if (dashes &&
+			    (dashes == msgbuf.buf || dashes[-1] == '\n'))
+				ignore = msgbuf.len - (dashes - msgbuf.buf);
+		}
+		append_signoff(&msgbuf, ignore, APPEND_SIGNOFF_DEDUP);
+	}
 
 	if ((ctx.fmt != CMIT_FMT_USERFORMAT) &&
 	    ctx.notes_message && *ctx.notes_message) {