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

[PATCH] git-diff: complain about >=8 consecutive spaces in initial indent

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 3, 2007, 01:00 UTC
Message-ID
<7vfy0thv10.fsf_-_@gitster.siamese.dyndns.org>
In-Reply-To
<1189982942187-git-send-email-bfields@citi.umich.edu>

This teaches coloring code in "diff" to detect indent of 8 or more places using SP, which can and should (in some projects including the kernel and git itself) use HT instead.

---
 * This is primarily meant as a "reminder" patch, and not for
   inclusion.  We earlier saw a patch to "git-apply" to rewrite
   them to HT but rejected it, because some projects use "no HT,
   all SP" policy (e.g. Python).
   We probably should resurrect the earlier "git-apply" patch,
   and teach it and this patch to selectively enable/disable
   detection of different kinds of whitespace breakages.
 diff.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/diff.c b/diff.c
index 0ee9ea1..647377b 100644
--- a/diff.c
+++ b/diff.c
@@ -531,8 +531,10 @@ static void emit_line_with_ws(int nparents,
 	int i;
 	int tail = len;
 	int need_highlight_leading_space = 0;
-	/* The line is a newly added line.  Does it have funny leading
-	 * whitespaces?  In indent, SP should never precede a TAB.
+	/*
+	 * The line is a newly added line.  Does it have funny leading
+	 * whitespaces?  In indent, SP should never precede a TAB, and
+	 * there shouldn't be more than 8 consecutive spaces.
 	 */
 	for (i = col0; i < len; i++) {
 		if (line[i] == '\t') {
@@ -545,6 +547,11 @@ static void emit_line_with_ws(int nparents,
 		else
 			break;
 	}
+	if (0 <= last_space_in_indent && last_tab_in_indent < 0 &&
+	    8 <= (i - col0)) {
+		last_tab_in_indent = i;
+		need_highlight_leading_space = 1;
+	}
 	fputs(set, stdout);
 	fwrite(line, col0, 1, stdout);
 	fputs(reset, stdout);
Previous: J. Bruce FieldsNext: David Kastrup
Message 13 of 16 in “whitespace-stripping”
  1. J. Bruce FieldsSep 16, 2007
  2. 1/3 git-apply: fix whitespace strippingJ. Bruce Fields, Sep 16, 2007
  3. 2/3 git-apply: complain about >=8 consecutive spaces in initial indentJ. Bruce Fields, Sep 16, 2007
  4. 3/3 git-apply: add tests for stripping of leading and trailing whitespaceJ. Bruce Fields, Sep 16, 2007
  5. Krzysztof HalasaSep 17, 2007
  6. J. Bruce FieldsSep 17, 2007
  7. Krzysztof HalasaSep 17, 2007
  8. J. Bruce FieldsSep 18, 2007
  9. Martin LanghoffSep 16, 2007
  10. J. Bruce FieldsSep 17, 2007
  11. Junio C HamanoSep 17, 2007
  12. J. Bruce FieldsSep 17, 2007
  13. git-diff: complain about >=8 consecutive spaces in initial indentJunio C Hamano, Oct 3, 2007
  14. David KastrupSep 18, 2007
  15. J. Bruce FieldsSep 18, 2007
  16. David KastrupSep 18, 2007

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.