From: Bruno Haible Date: Mon, 25 Mar 2024 11:53:34 +0000 (+0100) Subject: gnulib-tool.py: Tweak last change. X-Git-Tag: v1.0~232 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=39519878b6ef3397c593343454a402ae11d62c46;p=gnulib.git gnulib-tool.py: Tweak last change. * pygnulib/GLImport.py (GLImport._update_ignorelist_): Rename some local variables. Use rstrip built-in function. --- diff --git a/ChangeLog b/ChangeLog index 128806313d..1b7a37d3b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2024-03-25 Bruno Haible + + 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 gnulib-tool.py: Handle removed files in the vc ignore files. diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index 0fe465f1de..882f1993af 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -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']