Windows: Consistently avoid ending output lines with CR
authorJoey Hess <joeyh@joeyh.name>
Mon, 30 Oct 2023 18:43:43 +0000 (14:43 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 30 Oct 2023 18:43:43 +0000 (14:43 -0400)
This matches the behavior of git on Windows, which does not end lines with
CR either.

Previously, git-annex used to always write lines with putStrLn, so would
output CR on Windows. Then parts of it changed to use ByteString.putStrLn,
which does not output CR. That left its output inconsistent, sometimes
within the same command.

The point of this commit is to get back to consistency. Having the same
behavior as git is a nice bonus. It would be much harder to make it
consistently output CR, because every place it uses ByteString.putStrLn or
similar would need to be changed.

Sponsored-by: Nicholas Golder-Manning on Patreon
CHANGELOG
Messages.hs

index 584d19709d43f685a7009f5a6d345b5a155c8609..2aaf0c2023ee83c111d215dedaa50a7a470c1beb 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -5,6 +5,9 @@ git-annex (10.20230927) UNRELEASED; urgency=medium
   * importfeed: Use caching database to avoid needing to list urls
     on every run, and avoid using too much memory.
   * Improve memory use of --all when using annex.private.
+  * Windows: Consistently avoid ending output lines with CR. This matches
+    the behavior of git on Windows, which does not end lines with CR
+    either.
   * Windows: Fix CRLF handling in some log files.
 
  -- Joey Hess <id@joeyh.name>  Tue, 10 Oct 2023 13:17:31 -0400
index 3bf1256ee11329f7f81d80e83aae65e135826451..6b6222a07bbea4fb6d63a051a16b356c2ca0132b 100644 (file)
@@ -5,7 +5,7 @@
  - Licensed under the GNU AGPL version 3 or higher.
  -}
 
-{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}
+{-# LANGUAGE OverloadedStrings, ScopedTypeVariables, CPP #-}
 
 module Messages (
        showStartMessage,
@@ -265,6 +265,12 @@ setupConsole = do
         - a file or a pipe. -}
        hSetBuffering stdout LineBuffering
        hSetBuffering stderr LineBuffering
+#ifdef mingw32_HOST_OS
+       {- Avoid outputting CR at end of line on Windows. git commands do
+        - not ouput CR there. -}
+       hSetNewlineMode stdout noNewlineTranslation
+       hSetNewlineMode stderr noNewlineTranslation
+#endif
 
 enableDebugOutput :: Annex ()
 enableDebugOutput = do