]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Handle removed files in the vc ignore files.
authorCollin Funk <collin.funk1@gmail.com>
Mon, 25 Mar 2024 05:20:15 +0000 (22:20 -0700)
committerBruno Haible <bruno@clisp.org>
Mon, 25 Mar 2024 11:41:44 +0000 (12:41 +0100)
* pygnulib/GLImport.py (GLImport._update_ignorelist_): Handle removed
files. Check whether the original lines should be removed too.

ChangeLog
pygnulib/GLImport.py

index 0693acfc130ba1d9650c58d55689494778299519..128806313db2f04d1d5ee14716599fd0f81339d3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-03-25  Collin Funk  <collin.funk1@gmail.com>
+
+       gnulib-tool.py: Handle removed files in the vc ignore files.
+       * pygnulib/GLImport.py (GLImport._update_ignorelist_): Handle removed
+       files. Check whether the original lines should be removed too.
+
 2024-03-24  Collin Funk  <collin.funk1@gmail.com>
 
        gnulib-tool.py: Fix filetable construction for ignorelist.
index e8c8231886013ccb631c3dc5f3d8b63cd8499344..0fe465f1de07e41ec33eaa78f9251b0e559c741c 100644 (file)
@@ -803,20 +803,29 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
         if isfile(joinpath(destdir, srcpath)):
             if files_added or files_removed:
                 with codecs.open(joinpath(destdir, srcpath), 'rb', 'UTF-8') as file:
-                    srcdata = file.read()
+                    original_lines = file.readlines()
+                # Clean the newlines but not trailing whitespace.
+                original_lines = [ line if not line.endswith('\n') else line[:-1]
+                                   for line in original_lines ]
                 dirs_ignore = { constants.substart(anchor, '', filename)
-                                for filename in srcdata.split('\n')
+                                for filename in original_lines
                                 if filename.strip() }
-                srcdata = lines_to_multiline(sorted(dirs_ignore))
-                dirs_ignore = [ '%s%s' % (anchor, d)
-                                for d in set(files_added).difference(dirs_ignore) ]
-                destdata = lines_to_multiline(sorted(dirs_ignore))
-                if srcdata != destdata:
+                dirs_added = set(files_added).difference(dirs_ignore)
+                dirs_removed = set(files_removed)
+                if dirs_added or dirs_removed:
                     if not self.config['dryrun']:
                         print('Updating %s (backup in %s)' % (srcpath, backupname))
                         copyfile2(joinpath(destdir, srcpath), joinpath(destdir, backupname))
-                        with codecs.open(joinpath(destdir, srcpath), 'ab', 'UTF-8') as file:
-                            file.write(destdata)
+                        new_lines = original_lines + [ f'{anchor}{filename}'
+                                                       for filename in sorted(dirs_added) ]
+                        if anchor != '':
+                            dirs_removed = dirs_removed.union({ f'{anchor}{filename}'
+                                                                for filename in dirs_removed })
+                        new_lines = [ line
+                                      for line in new_lines
+                                      if line not in dirs_removed ]
+                        with codecs.open(joinpath(destdir, srcpath), 'wb', 'UTF-8') as file:
+                            file.write(lines_to_multiline(new_lines))
                     else:  # if self.config['dryrun']
                         print('Update %s (backup in %s)' % (srcpath, backupname))
         else:  # if not isfile(joinpath(destdir, srcpath))