Re: [PATCH v2] pre-commit hook should ignore carriage returns at EOL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Ciao!

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux