git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "SZEDER Gábor" <szeder@ira.uka.de>
Cc: David Brown <davidb@codeaurora.org>, git@vger.kernel.org
Subject: Re: [PATCH] commit: fix too generous RFC-2822 footer handling
Date: Tue, 03 Nov 2009 22:11:21 -0800	[thread overview]
Message-ID: <7vljimlsza.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1257304146-15543-1-git-send-email-szeder@ira.uka.de> ("SZEDER Gábor"'s message of "Wed\,  4 Nov 2009 04\:09\:06 +0100")

SZEDER Gábor <szeder@ira.uka.de> writes:

>  builtin-commit.c  |    8 ++++++++
>  t/t7501-commit.sh |    4 ++--
>  2 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/builtin-commit.c b/builtin-commit.c
> index beddf01..4971156 100644
> --- a/builtin-commit.c
> +++ b/builtin-commit.c
> @@ -429,6 +429,14 @@ static int ends_rfc2822_footer(struct strbuf *sb)
>  		hit = (buf[i] == '\n');
>  	}
>  
> +	for (j = i-1; j > 0; j--)
> +		if (buf[j] == '\n') {
> +			hit = 1;
> +			break;
> +		}
> +	if (!hit)	/* one-line message */
> +		return 0;
> +

That looks overly convoluted.  Why isn't the attached patch enough?

 - We inspected the last line of the message buffer, and 'i' is at the
   beginning of that last line;

 - At the line that begins at 'i', we found something that does not match
   the sob we are going to add;

 - We want a newline if it is a single liner (i.e. i == 0), or if that
   last one is not sob/acked-by and friends.

If you are anal and want to allow an author with a funny name "is allowed
as the first word", we _could_ encounter a single-liner commit like this:

        From: is allowed as the first word <author@example.xz>
	Subject: Signed-off-by: is allowed as the first word <author@example.xz>

        Signed-off-by: is allowed as the first word <author@example.xz>

and you may want to add "!i ||" in front of prefixcmp(), but I do not
think that is worth it.

 builtin-commit.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/builtin-commit.c b/builtin-commit.c
index c395cbf..cfa6b06 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -530,7 +530,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		for (i = sb.len - 1; i > 0 && sb.buf[i - 1] != '\n'; i--)
 			; /* do nothing */
 		if (prefixcmp(sb.buf + i, sob.buf)) {
-			if (!ends_rfc2822_footer(&sb))
+			if (!i || !ends_rfc2822_footer(&sb))
 				strbuf_addch(&sb, '\n');
 			strbuf_addbuf(&sb, &sob);
 		}

  reply	other threads:[~2009-11-04  6:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-27 23:45 [PATCH] commit: More generous accepting of RFC-2822 footer lines David Brown
2009-10-28  0:05 ` Shawn O. Pearce
2009-10-28  7:14   ` Junio C Hamano
2009-10-28 14:23     ` David Brown
2009-10-28 17:13 ` David Brown
2009-10-28 18:06   ` Junio C Hamano
2009-10-28 18:17     ` David Brown
2009-11-03 16:59     ` SZEDER Gábor
2009-11-04  3:09       ` [PATCH] commit: fix too generous RFC-2822 footer handling SZEDER Gábor
2009-11-04  6:11         ` Junio C Hamano [this message]
2009-11-04 15:11           ` SZEDER Gábor

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=7vljimlsza.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=davidb@codeaurora.org \
    --cc=git@vger.kernel.org \
    --cc=szeder@ira.uka.de \
    /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.
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 NNTP newsgroup(s).