git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] attribute: whitespace set to true detects all errors known to git

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 21, 2009, 09:35 UTC
Message-ID
<7vr5xerktl.fsf_-_@alter.siamese.dyndns.org>
In-Reply-To
<7vvdmqrl06.fsf@alter.siamese.dyndns.org>

That is what the documentation says, but the code pretends as if all the known whitespace error tokens were given.

Among the whitespace error tokens, there is one kind that loosens the rule when set: cr-at-eol. Which means that whitespace error token that is set to true ignores a newly introduced CR at the end, which is inconsistent with the documentation.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * I wish cr-at-eol were no-cr-at-eol instead, so that we didn't have to
   do this, but it is too late for that.  Oh well.
 ws.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/ws.c b/ws.c
index b1efcd9..819c797 100644
--- a/ws.c
+++ b/ws.c
@@ -10,11 +10,12 @@
 static struct whitespace_rule {
 	const char *rule_name;
 	unsigned rule_bits;
+	unsigned loosens_error;
 } whitespace_rule_names[] = {
-	{ "trailing-space", WS_TRAILING_SPACE },
-	{ "space-before-tab", WS_SPACE_BEFORE_TAB },
-	{ "indent-with-non-tab", WS_INDENT_WITH_NON_TAB },
-	{ "cr-at-eol", WS_CR_AT_EOL },
+	{ "trailing-space", WS_TRAILING_SPACE, 0 },
+	{ "space-before-tab", WS_SPACE_BEFORE_TAB, 0 },
+	{ "indent-with-non-tab", WS_INDENT_WITH_NON_TAB, 0 },
+	{ "cr-at-eol", WS_CR_AT_EOL, 1 },
 };
 
 unsigned parse_whitespace_rule(const char *string)
@@ -79,7 +80,8 @@ unsigned whitespace_rule(const char *pathname)
 			unsigned all_rule = 0;
 			int i;
 			for (i = 0; i < ARRAY_SIZE(whitespace_rule_names); i++)
-				all_rule |= whitespace_rule_names[i].rule_bits;
+				if (!whitespace_rule_names[i].loosens_error)
+					all_rule |= whitespace_rule_names[i].rule_bits;
 			return all_rule;
 		} else if (ATTR_FALSE(value)) {
 			/* false (-whitespace) */
Previous: Junio C Hamano
Message 3 of 3 in “.gitattributes: CR at the end of the line is an error”
  1. .gitattributes: CR at the end of the line is an errorNanako Shiraishi, Jun 19, 2009
  2. Junio C HamanoJun 21, 2009
  3. attribute: whitespace set to true detects all errors known to gitJunio C Hamano, Jun 21, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.