git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Sebastian Schuberth <sschuberth@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH] Do not strip empty lines / trailing spaces from a commit message template
Date: Thu, 11 Mar 2010 12:46:51 -0800	[thread overview]
Message-ID: <7vaaueziv8.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <20100311083148.GA13786@sigill.intra.peff.net> (Jeff King's message of "Thu\, 11 Mar 2010 03\:31\:48 -0500")

Jeff King <peff@peff.net> writes:

> On Thu, Mar 11, 2010 at 03:12:13AM -0500, Jeff King wrote:
>
>> >  	if (fp == NULL)
>> >  		die_errno("could not open '%s'", git_path(commit_editmsg));
>> >  
>> > -	if (cleanup_mode != CLEANUP_NONE)
>> > +	if (cleanup_mode != CLEANUP_NONE && strcmp(hook_arg1, "template"))
>> >  		stripspace(&sb, 0);
>> 
>> And the code looks OK, though admittedly I am not too familiar with this
>> chunk of code (at first I was confused that you would have to look at
>> hook_arg1, but apparently there is no other variable that contains the
>> result of that big if-else chain).


I suspect that the attached would be much easier to read and understand.

> BTW, a subtle point for anyone else reviewing this patch: we also call
> stripspace in message_is_empty to skip over an untouched template. But
> that code path is stil OK, because we stripspace the whole message that
> comes back from the user before calling message_is_empty(), so the
> result should be the same for an untouched template.
>
> -Peff

Thanks for a patch and a review.

> How about a test to check the new behavior?

Speaking of tests, t2203 will segfault with your patch.  I don't think the
following does, though.

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

diff --git a/builtin-commit.c b/builtin-commit.c
index 8a68dd3..14488d5 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -534,6 +534,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	const char *hook_arg1 = NULL;
 	const char *hook_arg2 = NULL;
 	int ident_shown = 0;
+	int clean_message_contents = (cleanup_mode != CLEANUP_NONE);
 
 	if (!no_verify && run_hook(index_file, "pre-commit", NULL))
 		return 0;
@@ -571,6 +572,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		if (strbuf_read_file(&sb, template_file, 0) < 0)
 			die_errno("could not read '%s'", template_file);
 		hook_arg1 = "template";
+		clean_message_contents = 0;
 	}
 
 	/*
@@ -584,7 +586,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	if (fp == NULL)
 		die_errno("could not open '%s'", git_path(commit_editmsg));
 
-	if (cleanup_mode != CLEANUP_NONE && strcmp(hook_arg1, "template"))
+	if (clean_message_contents)
 		stripspace(&sb, 0);
 
 	if (signoff) {

  reply	other threads:[~2010-03-11 20:47 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-10 15:57 [PATCH] Do not strip empty lines / trailing spaces from a commit message template Sebastian Schuberth
2010-03-11  8:12 ` Jeff King
2010-03-11  8:31   ` Jeff King
2010-03-11 20:46     ` Junio C Hamano [this message]
2010-03-11 22:46       ` Jeff King
2010-03-12  5:54         ` Junio C Hamano
2010-03-12 17:07       ` Sebastian Schuberth
2010-03-12 23:13         ` Junio C Hamano
2010-03-13 17:36           ` [PATCH] git-send-email.perl - Fix 550 EHLO argument does not match calling host Jari Aalto
2010-03-13 22:32             ` Junio C Hamano
2010-03-13 23:56               ` Jari Aalto
2010-03-14  6:28                 ` Junio C Hamano
2010-03-14 10:19                   ` Jari Aalto
2010-03-14 12:09                     ` Junio C Hamano
2010-03-14 14:55                       ` Jari Aalto
2010-03-14 14:59                       ` Jari Aalto
2010-03-14 10:21                   ` Jari Aalto
2010-03-14 11:55                     ` Junio C Hamano
2010-03-14 14:41                       ` Jari Aalto
2010-03-14 15:03                       ` Jari Aalto
2010-03-14 13:17                     ` Jakub Narebski
2010-03-14 14:52                       ` Jari Aalto
2010-03-14 15:15                     ` [PATCH 1/3] git-send-email.perl: improve error message in send_message() Jari Aalto
2010-03-14 15:16                     ` [PATCH 2/3] git-send-email.perl: add option --smtp-debug Jari Aalto
2010-03-14 15:16                     ` [PATCH 3/3] git-send-email.perl - Fix 550 EHLO argument does not match calling host Jari Aalto
2010-03-14 19:53                       ` Jakub Narebski
2010-03-14 20:20                         ` Jari Aalto
2010-03-14 20:33                         ` [PATCH] " Jari Aalto

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=7vaaueziv8.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=sschuberth@gmail.com \
    /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).