On 3/24/24 4:05 PM, Bruno Haible wrote:
> Oh, indeed. If filetable['added'] and filetable['removed'] are the same,
> no wonder that you are seeing nonsense in the .gitignore files...

Yes, I didn't notice it because I thought the issue was in my
interpretation of the 'sed' and 'join' commands in
GLImport._update_ignorelist_ or something similar. I guess the moral
of the story is that I should trust myself more. :)

> The sorting is probably relevant for the added files (since they get added
> at the end of the .gitignore file), but redundant for the removed files.

I think the test results that I am seeing align with what you
described here. I've added the following line to sort the files by
directory:

ignorelist = sorted(ignorelist, key=lambda group: group[0])

$ env GNULIB_TOOL_IMPL=py ./test-all.sh 2>&1 | grep '.gitignore'
Only in tmp891098-result/gl/m4: .gitignore

This is in test-oath-toolkit-1.sh, since gnulib-tool.py doesn't read
the 'gl_VC_FILES([false])' from the cache correctly. I think I already
mentioned this in a previous email.

Can you apply this patch for me? Then I can look into the
files_removed handling. I want to spend more time on that since
gnulib-tool.py only appends to the existing .gitgnore. However,
gnulib-tool.sh passes it through sed-ignore-removed.

                { cat "$destdir/$dir$ignore"~
                  sed -e "s|^|$anchor|" < "$tmp"/ignore-added
                } | sed -f "$tmp"/sed-ignore-removed \
                  > "$destdir/$dir$ignore"

Then I am not convinced the check if we need to back up is correct at
the moment:

    if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed;

turns into:

      if srcdata != destdata:

It seems to produce the same output at the moment, but I'm not sure if
that is just luck. I rather look into that more too.

Collin
From 9f128d511b95aad974867b8f84b91b1e996a8cde Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sun, 24 Mar 2024 16:09:34 -0700
Subject: [PATCH] gnulib-tool.py: Fix filetable construction for ignorelist.

* pygnulib/GLImport.py (GLImport.execute): Fix typo in dictionary key
that overwrites removed files. Sort ignorelist by directory.
---
 ChangeLog            | 6 ++++++
 pygnulib/GLImport.py | 3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index d6827684c7..65196e85d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-03-24  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Fix filetable construction for ignorelist.
+	* pygnulib/GLImport.py (GLImport.execute): Fix typo in dictionary key
+	that overwrites removed files. Sort ignorelist by directory.
+
 2024-03-24  Bruno Haible  <br...@clisp.org>
 
 	gnulib-tool.py: Bring the output into the right order.
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index d417137df6..8be9cc45c9 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -1393,13 +1393,14 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
             # Treat gnulib-comp.m4 like an added file, even if it already existed.
             filetable['added'] += [joinpath(m4base, 'gnulib-comp.m4')]
             filetable['added'] = sorted(set(filetable['added']))
-            filetable['removed'] = sorted(set(filetable['added']))
+            filetable['removed'] = sorted(set(filetable['removed']))
             for file in filetable['added']:
                 directory, basename = os.path.split(file)
                 ignorelist += [tuple([directory, '|A|', basename])]
             for file in filetable['removed']:
                 directory, basename = os.path.split(file)
                 ignorelist += [tuple([directory, '|R|', basename])]
+            ignorelist = sorted(ignorelist, key=lambda group: group[0])
             last_dir = ''
             last_dir_files_added = list()
             last_dir_files_removed = list()
-- 
2.44.0

Reply via email to