]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Tweak last change.
authorBruno Haible <bruno@clisp.org>
Mon, 25 Mar 2024 11:53:34 +0000 (12:53 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 25 Mar 2024 11:53:34 +0000 (12:53 +0100)
* pygnulib/GLImport.py (GLImport._update_ignorelist_): Rename some local
variables. Use rstrip built-in function.

ChangeLog
pygnulib/GLImport.py

index 128806313db2f04d1d5ee14716599fd0f81339d3..1b7a37d3b98d2baaf88fbaeacb234a5aa60e3651 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-03-25  Bruno Haible  <bruno@clisp.org>
+
+       gnulib-tool.py: Tweak last change.
+       * pygnulib/GLImport.py (GLImport._update_ignorelist_): Rename some local
+       variables. Use rstrip built-in function.
+
 2024-03-25  Collin Funk  <collin.funk1@gmail.com>
 
        gnulib-tool.py: Handle removed files in the vc ignore files.
index 0fe465f1de07e41ec33eaa78f9251b0e559c741c..882f1993af1cd93657f3862985e2f7792fcbdca9 100644 (file)
@@ -805,25 +805,27 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
                 with codecs.open(joinpath(destdir, srcpath), 'rb', 'UTF-8') as file:
                     original_lines = file.readlines()
                 # Clean the newlines but not trailing whitespace.
-                original_lines = [ line if not line.endswith('\n') else line[:-1]
+                original_lines = [ line.rstrip('\n')
                                    for line in original_lines ]
-                dirs_ignore = { constants.substart(anchor, '', filename)
-                                for filename in original_lines
-                                if filename.strip() }
-                dirs_added = set(files_added).difference(dirs_ignore)
-                dirs_removed = set(files_removed)
-                if dirs_added or dirs_removed:
+                already_listed_filenames = { constants.substart(anchor, '', filename)
+                                             for filename in original_lines
+                                             if filename.strip() }
+                filenames_to_add = set(files_added).difference(already_listed_filenames)
+                filenames_to_remove = set(files_removed)
+                if filenames_to_add or filenames_to_remove:
                     if not self.config['dryrun']:
                         print('Updating %s (backup in %s)' % (srcpath, backupname))
                         copyfile2(joinpath(destdir, srcpath), joinpath(destdir, backupname))
                         new_lines = original_lines + [ f'{anchor}{filename}'
-                                                       for filename in sorted(dirs_added) ]
+                                                       for filename in sorted(filenames_to_add) ]
                         if anchor != '':
-                            dirs_removed = dirs_removed.union({ f'{anchor}{filename}'
-                                                                for filename in dirs_removed })
+                            lines_to_remove = filenames_to_remove.union({ f'{anchor}{filename}'
+                                                                          for filename in filenames_to_remove })
+                        else:
+                            lines_to_remove = filenames_to_remove
                         new_lines = [ line
                                       for line in new_lines
-                                      if line not in dirs_removed ]
+                                      if line not in lines_to_remove ]
                         with codecs.open(joinpath(destdir, srcpath), 'wb', 'UTF-8') as file:
                             file.write(lines_to_multiline(new_lines))
                     else:  # if self.config['dryrun']