public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: "H. Peter Anvin" <hpa@zytor•com>
Cc: Jeff King <peff@peff•net>, Git Mailing List <git@vger•kernel.org>
Subject: Re: git am and the wrong chunk of ---
Date: Fri, 10 Aug 2012 09:15:04 -0700	[thread overview]
Message-ID: <7v628qlo53.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <b661ef79-510e-4be6-bed2-451e9967db6f@email.android.com> (H. Peter Anvin's message of "Fri, 10 Aug 2012 07:48:39 -0700")

"H. Peter Anvin" <hpa@zytor•com> writes:

> The users I am referring to generally have a --- line, rather than
> a scissor, between the cover text and commit.  Also, there is
> (almost) always a From: line and subject at the top of the patch
> proper.

Oh, so it is more like this?

    From: author name <author@address•xz>
    Date: author date
    Subject: patch title

    Heya,

    I was walking my dog when I found a solution to this
    problem the other day.  Here it is.

    ---
    >From 755e8b3f35e3991a735a6be740eda4567d45a741 Mon Sep 17 00:00:00 2001
    From: author name <author@address•xz>
    Date: random date we do not care
    Subject: patch title

    commit message body

    ---

We could teach "am -c" to recognize the format-patch file magic

    "^[>]From [0-9a-f]{40} Mon Sep 17 00:00:00 2001"

as another form of accepted scissors, I guess.

Something like the attached (untested) patch, perhaps.

But I am fairly negative on it.

Where would it end?  After all, the top "---" is not something our
tools are generating, but is manually typed by the users.

I do not think it is unreasonable to expect that they are capable
and intelligent enough to guess that "---" is _not_ the way to say
"cut here and what follows are the log message", when "---" is
already the way to say "cut here, and what we saw up to this point
is the log message".

 builtin/mailinfo.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index eaf9e15..62ea09d 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -730,6 +730,22 @@ static inline int patchbreak(const struct strbuf *line)
 	return 0;
 }
 
+static int is_format_patch_magic(const struct strbuf *line)
+{
+	const char *buf = line->buf;
+	size_t len = line->len;
+
+	if (len && *buf == '>') {
+		buf++;
+		len--;
+	}
+	if (len < 70)
+		return 0;
+	return (!memcmp(buf, "From ", 5) &&
+		strspn(buf + 5, "0123456789abcdef") == 40 &&
+		!memcmp(buf + 46, "Mon Sep 17 00:00:00 2001", 24));
+}
+
 static int is_scissors_line(const struct strbuf *line)
 {
 	size_t i, len = line->len;
@@ -807,7 +823,7 @@ static int handle_commit_msg(struct strbuf *line)
 	if (metainfo_charset)
 		convert_to_utf8(line, charset.buf);
 
-	if (use_scissors && is_scissors_line(line)) {
+	if (use_scissors && (is_scissors_line(line) || is_format_patch_magic(line))) {
 		int i;
 		if (fseek(cmitmsg, 0L, SEEK_SET))
 			die_errno("Could not rewind output message file");

  reply	other threads:[~2012-08-10 16:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-10  0:13 git am and the wrong chunk of --- H. Peter Anvin
2012-08-10  1:26 ` Junio C Hamano
2012-08-10 10:36 ` Jeff King
2012-08-10 11:00   ` Andreas Ericsson
2012-08-10 14:46   ` Junio C Hamano
2012-08-10 14:48     ` H. Peter Anvin
2012-08-10 16:15       ` Junio C Hamano [this message]
2012-08-10 16:39         ` H. Peter Anvin

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

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

  git send-email \
    --in-reply-to=7v628qlo53.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=hpa@zytor$(echo .)com \
    --cc=peff@peff$(echo .)net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox