contrib: ignore CR in update-copyright.py

Message ID d15fec2f-b7aa-2830-089a-62c0fd0b66d9@suse.cz
State Accepted
Headers
Series contrib: ignore CR in update-copyright.py |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Martin Liška Jan. 17, 2023, noon UTC
  When opening files, preserve CR characters. By default, open
accepts universal newlines, but I think we should only split with '\n'.

Ready to be installed?
Thanks,
Martin

contrib/ChangeLog:

	* update-copyright.py: Split lines only with '\n'.
---
 contrib/update-copyright.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Jeff Law March 11, 2023, 4:20 p.m. UTC | #1
On 1/17/23 05:00, Martin Liška wrote:
> When opening files, preserve CR characters. By default, open
> accepts universal newlines, but I think we should only split with '\n'.
> 
> Ready to be installed?
> Thanks,
> Martin
> 
> contrib/ChangeLog:
> 
> 	* update-copyright.py: Split lines only with '\n'.
OK.

jeff
  

Patch

diff --git a/contrib/update-copyright.py b/contrib/update-copyright.py
index ac7a94743cf..bdb5417bcec 100755
--- a/contrib/update-copyright.py
+++ b/contrib/update-copyright.py
@@ -408,7 +408,7 @@  class Copyright:
         line_filter = filter.get_line_filter (dir, filename)
         mode = None
         encoding = self.guess_encoding(pathname)
-        with open (pathname, 'r', encoding=encoding) as file:
+        with open (pathname, 'r', encoding=encoding, newline='\n') as file:
             prev = None
             mode = os.fstat (file.fileno()).st_mode
             for line in file:
@@ -434,7 +434,7 @@  class Copyright:
         # If something changed, write the new file out.
         if changed and self.errors.ok():
             tmp_pathname = pathname + '.tmp'
-            with open (tmp_pathname, 'w', encoding=encoding) as file:
+            with open (tmp_pathname, 'w', encoding=encoding, newline='\n') as file:
                 for line in lines:
                     file.write (line)
                 os.fchmod (file.fileno(), mode)