Subject: bug#74847: change default tar format from v7 to ustar (was: Re: reproducible tar archives)

From: Karl Berry <[email-masked]>
Date: Mon, 24 Feb 2025 15:41:54 -0700

Back on this suggestion:
    https://debbugs.gnu.org/cgi/bugreport.cgi?bug=74847

    What do you think about changing Automake's default tar format from v7
    to ustar?

Given Bruno's experience, ok, let's try. I won't be surprised if
problems come out of the woodwork, but maybe it will be fine.

I think the change below is all that's needed to implement this?
I pushed it. Let me know if something more comes to mind.

    What do you think about defaulting to the --format=posix PAX format?

Given the draconian warnings in the automake manual (not written by me),
I suspect it is still premature. In particular, I doubt the situation
has changed on Solaris:

    > @option{tar-pax} selects the new pax interchange format defined by POSIX
    > 1003.1-2001.  It does not limit the length of file names.
    > ...
    > As of 2018, this format [tar-pax] is supported by the native @code{tar}
    > command only on GNU, FreeBSD, and OpenBSD systems; it is not
    > supported by the native @code{tar} command on NetBSD, AIX, HP-UX, or
    > Solaris. 

which is followed by:

    > There are moves to change the pax format in an upward-compatible
    > way, so this option may refer to a more recent version in the future.

Did any change to pax formats ever come to pass? --thanks, karl.

-----------------------------------------------------------------------------
dist: change tar format default to ustar (!).

Suggested in https://bugs.gnu.org74847.

* m4/init.m4 (tar-ustar): make ustar the default instead of tar-v7.
* doc/automake.texi (tar-formats): document this.
* NEWS: mention this.
* t/tar-override.sh: force tar-v7 for purposes of this test.
diff --git a/NEWS b/NEWS
index da6b5e493..796a9030f 100644
--- a/NEWS
+++ b/NEWS
@@ -6,13 +6,17 @@ New in 1.x:

 * New features added

+  - Default tar format is now ustar, to support longer filenames;
+    the tar-v7 and other explicit options to force a particular tar
+    format are unchanged. (bug#74847)
+
+  - New option dist-bzip3 for bzip3 compression of distributions. (bug#73795)
+
   - New option --stderr-prefix for tap-driver.sh, to prefix each line of
     stderr from a test script with a given string. (bug#72536)

   - Support for Algol 68 added, based on the GNU Algol 68 compiler. (bug#75807)

-  - New option dist-bzip3 for bzip3 compression of distributions. (bug#73795)
-
 * Bugs fixed

   - Do not make Perl warnings fatal, per Perl's recommendation.
diff --git a/doc/automake.texi b/doc/automake.texi
index 6dcd94826..51190ea50 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -11373,7 +11373,7 @@ These options must be passed as arguments to @code{AM_INIT_AUTOMAKE}
 Automake will complain if it sees such options in an
 @code{AUTOMAKE_OPTIONS} variable.

-@option{tar-v7} selects the old V7 tar format.  This is the historical
+@option{tar-v7} selects the old V7 tar format.  This was the historical
 default.  This antiquated format is understood by all tar
 implementations and supports file names with up to 99 characters.  When
 given longer file names some tar implementations will diagnose the
@@ -11383,7 +11383,8 @@ directories.  When using this format, consider using the
 @option{filename-length-max=99} option to catch file names too long.

 @option{tar-ustar} selects the ustar format defined by POSIX
-1003.1-1988.  This format is old enough to be portable:
+1003.1-1988.  This format became the default in Automake version 1.18
+(released in 2025).
 As of 2018, it is supported by the native @code{tar} command on
 GNU, FreeBSD, NetBSD, OpenBSD, AIX, HP-UX, and Solaris, at least.
 It fully supports empty directories.  It can store file names with up
diff --git a/m4/init.m4 b/m4/init.m4
index 5da8f9e13..ed10dabcf 100644
--- a/m4/init.m4
+++ b/m4/init.m4
@@ -100,8 +100,9 @@ AC_REQUIRE([AC_PROG_AWK])dnl
 AC_REQUIRE([AC_PROG_MAKE_SET])dnl
 AC_REQUIRE([AM_SET_LEADING_DOT])dnl
 _AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])],
-	      [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
-			     [_AM_PROG_TAR([v7])])])
+  [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
+    [_AM_IF_OPTION([tar-v7], [_AM_PROG_TAR([v7])],
+      [_AM_PROG_TAR([ustar])])])])
 _AM_IF_OPTION([no-dependencies],,
 [AC_PROVIDE_IFELSE([AC_PROG_CC],
 		  [_AM_DEPENDENCIES([CC])],
diff --git a/t/tar-override.sh b/t/tar-override.sh
index 941a599da..e02c255ca 100644
--- a/t/tar-override.sh
+++ b/t/tar-override.sh
@@ -16,14 +16,21 @@

 # Check that the user can override the tar program used by "make dist"
 # at runtime, by redefining the 'TAR' environment variable.
-# NOTE: currently this works only when the tar format used is 'v7'
-#       (which is the default one).
+# 
+# Currently this works only when the tar format used is 'v7';
+# as of 2025 (automake-1.18), this is no longer the default,
+# so force that format in our test setup.

 . test-init.sh

 cwd=$(pwd) || fatal_ "getting current working directory"

-echo AC_OUTPUT >> configure.ac
+cat > configure.ac << 'END'
+AC_INIT([tar-override], [1.0])
+AM_INIT_AUTOMAKE([tar-v7])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+END

 cat > am--tar <<'END'
 #!/bin/sh

compile finished at Mon Feb 24 14:39:19 2025