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

Re: [PATCH 3/5] Unify whitespace checking

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 14, 2007, 00:03 UTC
Message-ID
<7vd4taywfw.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<1197552751-53480-4-git-send-email-win@wincent.com>
Wincent Colaiuta <win@wincent.com> writes:
Show 6 quoted lines
> The new function is called check_and_emit_line() and it does two things:
> checks a line for whitespace errors and optionally emits it. The checking
> is based on lines of content rather than patch lines (in other words, the
> caller must strip the leading "+" or "-"); this was suggested by Junio on
> the mailing list to allow for a future extension to "git show" to display
> whitespace errors in blobs.

I do not think "git show" is a realistic "future extension", by the way. But at least from the interface-cleanliness point of view, I think not passing the leading "+" to the function is a right thing to do.

Show 12 quoted lines
> diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
> index dc538b3..a0a47dd 100755
> --- a/t/t4015-diff-whitespace.sh
> +++ b/t/t4015-diff-whitespace.sh
> @@ -121,7 +121,7 @@ test_expect_success 'check mixed spaces and tabs in indent' '
>  
>  	# This is indented with SP HT SP.
>  	echo " 	 foo();" > x &&
> -	git diff --check | grep "space before tab"
> +	git diff --check | grep "Space in indent is followed by a tab"
>  
>  '

Hmph. I think with the multiple detection this rewording would make the error message very long to read. Was the rewording really necessary?

Show 5 quoted lines
> +/* If stream is non-NULL, emits the line after checking. */
> +unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule,
> +                             FILE *stream, const char *set,
> +                             const char *reset, const char *ws)
> +{

Honestly, I regretted suggesting this, fearing that it might make the checking too costly, but the code is clean, readable, and does not look costly at all. Nice job.

Previous: Andreas EricssonNext: Wincent Colaiuta
Message 10 of 24 in “"diff --check" and whitespace enhancements”
  1. 0/5 "diff --check" and whitespace enhancementsWincent Colaiuta, Dec 13, 2007
  2. 1/5 "diff --check" should affect exit statusWincent Colaiuta, Dec 13, 2007
  3. 2/5 New version of pre-commit hookWincent Colaiuta, Dec 13, 2007
  4. 3/5 Unify whitespace checkingWincent Colaiuta, Dec 13, 2007
  5. 4/5 Make "diff --check" output match "git apply"Wincent Colaiuta, Dec 13, 2007
  6. 5/5 Add tests for "git diff --check" with core.whitespace optionsWincent Colaiuta, Dec 13, 2007
  7. Junio C HamanoDec 14, 2007
  8. Junio C HamanoDec 14, 2007
  9. Andreas EricssonDec 13, 2007
  10. Junio C HamanoDec 14, 2007
  11. Wincent ColaiutaDec 14, 2007
  12. Jakub NarebskiDec 14, 2007
  13. Wincent ColaiutaDec 14, 2007
  14. Jakub NarebskiDec 14, 2007
  15. Don't use the pager when running "git diff --check"Wincent Colaiuta, Dec 13, 2007
  16. Jeff KingDec 14, 2007
  17. Junio C HamanoDec 14, 2007
  18. Junio C HamanoDec 14, 2007
  19. Wincent ColaiutaDec 14, 2007
  20. Junio C HamanoDec 14, 2007
  21. Wincent ColaiutaDec 14, 2007
  22. Junio C HamanoDec 14, 2007
  23. Junio C HamanoDec 13, 2007
  24. Junio C HamanoDec 14, 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.