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

[PATCH] git-apply: war on whitespace -- finishing touches.

From
Junio C Hamano <junkio@cox.net>
Date
Feb 28, 2006, 09:13 UTC
Message-ID
<7vu0ajonfu.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<20060227153702.375db751.akpm@osdl.org>
Andrew Morton <akpm@osdl.org> writes:
> I'd suggest that git have options to a) generate trailing-whitespace
> warnings, b) generate trailing-whitespace errors and c) strip trailing
> whitespace while applying.   And that the as-shipped default be a).

I've done this and will be pushing it out to "master" branch on my next git day (Wednesday, west coast US); "maint" branch will have the same for v1.2.4 sometime by the end of this week.

There is one thing. By making --whitespace=warn the default, the diffstat output people would see after "git pull" would also show the warning message. I personally do not think this is a problem (you will know how dirty a tree you are merging into your tree), but it might not be a bad idea to explicitly squelch it by making it not to warn when we are not applying.

-- >8 --

This changes the default --whitespace policy to nowarn when we are only getting --stat, --summary etc. IOW when not applying the patch. When applying the patch, the default is warn (spit out warning message but apply the patch).

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 apply.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
f21d6726150ec4219e94ea605f27a4cd58eb3d99
diff --git a/apply.c b/apply.c
index c4ff418..9deb206 100644
--- a/apply.c
+++ b/apply.c
@@ -75,6 +75,15 @@ static void parse_whitespace_option(cons
 	die("unrecognized whitespace option '%s'", option);
 }
 
+static void set_default_whitespace_mode(const char *whitespace_option)
+{
+	if (!whitespace_option && !apply_default_whitespace) {
+		new_whitespace = (apply
+				  ? warn_on_whitespace
+				  : nowarn_whitespace);
+	}
+}
+
 /*
  * For "diff-stat" like behaviour, we keep track of the biggest change
  * we've seen, and the longest filename. That allows us to do simple
@@ -1955,9 +1964,11 @@ int main(int argc, char **argv)
 		if (fd < 0)
 			usage(apply_usage);
 		read_stdin = 0;
+		set_default_whitespace_mode(whitespace_option);
 		apply_patch(fd, arg);
 		close(fd);
 	}
+	set_default_whitespace_mode(whitespace_option);
 	if (read_stdin)
 		apply_patch(0, "<stdin>");
 	if (whitespace_error) {
-- 
1.2.3.g1da2
Previous: Andrew MortonNext: Junio C Hamano
Message 16 of 40 in “the war on trailing whitespace”
  1. Andrew MortonFeb 26, 2006
  2. Junio C HamanoFeb 26, 2006
  3. Andrew MortonFeb 26, 2006
  4. Linus TorvaldsFeb 26, 2006
  5. Andrew MortonFeb 26, 2006
  6. Linus TorvaldsFeb 26, 2006
  7. Dave JonesFeb 26, 2006
  8. Dave JonesFeb 26, 2006
  9. MIke GalbraithFeb 27, 2006
  10. Johannes SchindelinFeb 27, 2006
  11. Andrew MortonFeb 27, 2006
  12. Junio C HamanoFeb 27, 2006
  13. Peter WilliamsFeb 27, 2006
  14. Junio C HamanoFeb 28, 2006
  15. Andrew MortonFeb 27, 2006
  16. git-apply: war on whitespace -- finishing touches.Junio C Hamano, Feb 28, 2006
  17. 1/3 apply: squelch excessive errors and --whitespace=error-allJunio C Hamano, Feb 28, 2006
  18. 2/3 apply --whitespace: configuration option.Junio C Hamano, Feb 28, 2006
  19. Andreas EricssonFeb 28, 2006
  20. Junio C HamanoFeb 28, 2006
  21. Andreas EricssonFeb 28, 2006
  22. 3/3 git-apply --whitespace=nowarnJunio C Hamano, Feb 28, 2006
  23. A Large Angry SCMFeb 28, 2006
  24. Junio C HamanoFeb 28, 2006
  25. Adrien BeauFeb 27, 2006
  26. Andreas EricssonFeb 27, 2006
  27. Uwe ZeisbergerFeb 27, 2006
  28. Andreas EricssonFeb 27, 2006
  29. Peter HagervallFeb 27, 2006
  30. Johannes SchindelinFeb 27, 2006
  31. Randal L. SchwartzFeb 27, 2006
  32. Josef WeidendorferFeb 27, 2006
  33. Adrien BeauFeb 27, 2006
  34. Uwe ZeisbergerFeb 27, 2006
  35. Andreas EricssonFeb 27, 2006
  36. Johannes SchindelinFeb 27, 2006
  37. Junio C HamanoFeb 27, 2006
  38. apply --whitespace fixes and enhancements.Junio C Hamano, Feb 27, 2006
  39. Junio C HamanoFeb 26, 2006
  40. Sam RavnborgFeb 26, 2006

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.