git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Christian Holtje <docwhat@gmail.com>
Cc: Alex Riesen <raa.lkml@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH v2] pre-commit hook should ignore carriage returns at EOL
Date: Wed, 25 Jun 2008 12:14:41 -0700	[thread overview]
Message-ID: <7vhcbh1g4e.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <5B163827-204D-4F76-88C9-8F0C93E60AF3@gmail.com> (Christian Holtje's message of "Wed, 25 Jun 2008 14:47:58 -0400")

Christian Holtje <docwhat@gmail.com> writes:

> On Jun 25, 2008, at 2:14 PM, Alex Riesen wrote:
>> Christian Holtje, Tue, Jun 24, 2008 21:21:22 +0200:
>>> diff --git a/t/t7503-template-hook--pre-commit.sh b/t/t7503-template-
>>> hook--pre-commit.sh
>>
>> Your patch has long lines wrapped.
>>
>>> diff --git a/templates/hooks--pre-commit b/templates/hooks--pre-
>>> commit
>>> index b25dce6..335ca09 100644
>>> --- a/templates/hooks--pre-commit
>>> +++ b/templates/hooks--pre-commit
>>> @@ -55,8 +55,14 @@ perl -e '
>>> 	if (s/^\+//) {
>>> 	    $lineno++;
>>> 	    chomp;
>>> -	    if (/\s$/) {
>>> -		bad_line("trailing whitespace", $_);
>>> +	    if (/\r$/) {
>>> +		if (/\s\r$/) {
>>> +		    bad_line("trailing whitespace", $_);
>>> +		}
>>> +	    } else {
>>> +		if (/\s$/) {
>>> +		    bad_line("trailing whitespace", $_);
>>> +		}
>>
>> You coud just strip the trailing (cr)lf, instead of chomp:
>>
>>  	if (s/^\+//) {
>>  	    $lineno++;
>> - 	    chomp;
>> +	    s/\r?\n$//so;
>> 	    if (/\s$/) {
>> 		bad_line("trailing whitespace", $_);
>>
>> Makes for a shorter patch and less code.
>
> That's a good idea!  However, this patch is not going anyplace, I
> think.  Junio submitted a different patch to disable the pre-commit
> example.
>
> Junio, do you want me to make this change anyway?  It does make sense.
> The unittests for the pre-commit hook may or may not still be  useful.

"disable" is not an issue.  The intention has always been that these are
samples, and it was an accident that some packaging shipped them enabled
by mistake.  The patch was to make that mistake harder to make.

The issue now is about keeping the example hooks _relevant_.  The one we
have does not work well with projects that want to check in files with
CRLF line endings (iow, without using autocrlf to attempt to make the
project files cross-platform), so it is irrelevant for such projects with
Windows origin.

The "solution" you are proposing to strip out \r makes the check less
useful for projects that want to keep files with LF line endings in the
commited history, because your patch would stop catching such a mistake of
adding an CR before LF.  It is robbing from Peter to pay Paul, and I am
afraid it would make the sample even more irrelevant in the end.  I do not
think we would want to go there.

I suggested using "diff --check" (and possibly teaching "diff --check"
other things the scripted example checks, such as conflict markers),
which would know to honor the line endings specified per path via
gitattributes(5), instead of building on top of the big Perl script, and I
had an impression that you agreed to the approach.

  reply	other threads:[~2008-06-25 19:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-24 19:21 [PATCH v2] pre-commit hook should ignore carriage returns at EOL Christian Holtje
2008-06-25 18:14 ` Alex Riesen
2008-06-25 18:47   ` Christian Holtje
2008-06-25 19:14     ` Junio C Hamano [this message]
2008-06-26  2:41       ` Christian Holtje
2008-06-26 22:33         ` Junio C Hamano
2008-06-26 22:34           ` [PATCH 1/5] diff --check: explain why we do not care whether old side is binary Junio C Hamano
2008-06-26 22:35           ` [PATCH 2/5] check_and_emit_line(): rename and refactor Junio C Hamano
2008-06-26 22:36           ` [PATCH 3/5] checkdiff: pass diff_options to the callback Junio C Hamano
2008-06-26 22:36           ` [PATCH 4/5] Teach "diff --check" about a new blank lines at end Junio C Hamano
2008-06-26 22:37           ` [PATCH 5/5] diff --check: detect leftover conflict markers Junio C Hamano
2008-06-26 23:01           ` [PATCH v2] pre-commit hook should ignore carriage returns at EOL Junio C Hamano
2008-06-26 23:06             ` Junio C Hamano
2008-06-27  4:24               ` Jeff King

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=7vhcbh1g4e.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=docwhat@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=raa.lkml@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).