bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnulib-tool.sh: Improve sort order of directories


From: Bruno Haible
Subject: gnulib-tool.sh: Improve sort order of directories
Date: Thu, 11 Apr 2024 15:12:51 +0200

In the 'poke' package, I'm seeing that gnulib-tool.sh sorts directory names
with a trailing slash, whereas gnulib-tool.py sorts them without a trailing
slash.

How to reproduce:

$ export GNULIB_TOOL_IMPL=sh+py
$ git clone https://git.savannah.gnu.org/git/poke.git
$ cd poke
$ git submodule update --init jitter
$ ./bootstrap --no-git --gnulib-srcdir=$GNULIB_SRCDIR --skip-po
...
.../gnulib-tool: *** gnulib-tool.py produced different output than 
gnulib-tool.sh! Compare .../poke/glpyPFJcaa-sh-out and 
.../poke/glpyPFJcaa-py-out.
.../gnulib-tool: *** Stop.
$ diff -u glpyPFJcaa-sh-out glpyPFJcaa-py-out
--- glpyPFJcaa-sh-out   2024-04-11 14:02:07.797320832 +0200
+++ glpyPFJcaa-py-out   2024-04-11 14:01:58.913246895 +0200
@@ -666,8 +666,8 @@
 Creating build-aux/gnulib-comp.m4
 Creating gnulib-local/Makefile.am
 Creating build-aux/.gitignore
-Creating gnulib-local-doc/.gitignore
 Creating gnulib-local/.gitignore
+Creating gnulib-local-doc/.gitignore
 Finished.

 You may need to add #include directives for the following .h files.

GLImport.py does it better:
            # Sort ignorelist by directory.
            ignorelist = sorted(ignorelist, key=lambda row: row[0])

gnulib-tool.sh does it not so well. It sorts 'gnulib-local' after
'gnulib-local-doc', due to the trailing slash.

This patch fixes it.


2024-04-11  Bruno Haible  <bruno@clisp.org>

        gnulib-tool.sh: Improve sort order of directories.
        * gnulib-tool.sh (func_import): In file fileset-changes, store directory
        names without a trailing slash.

diff --git a/gnulib-tool.sh b/gnulib-tool.sh
index 6335228c46..507607376f 100755
--- a/gnulib-tool.sh
+++ b/gnulib-tool.sh
@@ -6270,10 +6270,10 @@ s,//*$,/,'
 
   if test "$vc_files" != false; then
     # Update the .cvsignore and .gitignore files.
-    { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
-      echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
+    { echo "$added_files" | sed -e '/^$/d' -e 's,^\([^/]*\)$,./\1,' -e 
's,/\([^/]*\)$,|A|\1,'
+      echo "$removed_files" | sed -e '/^$/d' -e 's,^\([^/]*\)$,./\1,' -e 
's,/\([^/]*\)$,|R|\1,'
       # Treat gnulib-comp.m4 like an added file, even if it already existed.
-      echo "$m4base/|A|gnulib-comp.m4"
+      echo "$m4base|A|gnulib-comp.m4"
     } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
     { # Rearrange file descriptors. Needed because "while ... done < ..."
       # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
@@ -6353,8 +6353,13 @@ s,//*$,/,'
       last_dir_added=
       last_dir_removed=
       while read line; do
-        # Why not ''read next_dir op file'' ? Because the dir column can be 
empty.
+        # Why not ''read next_dir op file'' ? Because I hate working with IFS.
         next_dir=`echo "$line" | sed -e 's,|.*,,'`
+        if test "$next_dir" = '.'; then
+          next_dir=
+        else
+          next_dir="$next_dir/"
+        fi
         op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
         file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
         if test "$next_dir" != "$last_dir"; then






reply via email to

[Prev in Thread] Current Thread [Next in Thread]