On 2024-11-12 11:09, Bruno Haible wrote:
    in order to get the latest 'master', the
    user would have to first do a 'git pull' in the refdir, and then do
    a 'git pull' in the subdirectory gnulib/.

    This is problematic because
      - This is almost certainly not the intended behaviour.

It was the behavior I wanted. I can live with the other behavior, though.


    Maybe what we need instead of

      git clone "$GNULIB_REFDIR" "$gnulib_path"

    is just a plain copy, roughly like this:

      mkdir "$gnulib_path"
      cp -a "$GNULIB_REFDIR"/.git "$gnulib_path"/.git
      (cd "$gnulib_path" && git checkout ...)

That would be slower, no? A local "git clone" mostly uses hard links.

I installed the attach patches, which use "git remote set-url"; good enough?


2) It needs to be documented in the --help option.

Also done in the attached patches.

Thanks for the review.
From b855d810e26bdb5863f61cc00a31a059467edbe8 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Tue, 12 Nov 2024 13:00:10 -0800
Subject: [PATCH 1/2] bootstrap: go back to old non-submodule semantics
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* top/bootstrap-funclib.sh (prepare_GNULIB_SRCDIR):
When cloning GNULIB_REFDIR and no submodule 'gnulib' is configured,
set the origin’s URL to $gnulib_url and fetch from remote,
so that GNULIB_REFDIR is merely an accelerant rather than
having different semantics.
* build-aux/bootstrap: Regenerate.
---
 ChangeLog                | 10 ++++++
 build-aux/bootstrap      | 77 +++++++++++++++++++++-------------------
 top/bootstrap-funclib.sh | 77 +++++++++++++++++++++-------------------
 3 files changed, 92 insertions(+), 72 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c4a9230a95..213714cc52 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-11-12  Paul Eggert  <egg...@cs.ucla.edu>
+
+	bootstrap: go back to old non-submodule semantics
+	* top/bootstrap-funclib.sh (prepare_GNULIB_SRCDIR):
+	When cloning GNULIB_REFDIR and no submodule 'gnulib' is configured,
+	set the origin’s URL to $gnulib_url and fetch from remote,
+	so that GNULIB_REFDIR is merely an accelerant rather than
+	having different semantics.
+	* build-aux/bootstrap: Regenerate.
+
 2024-11-12  Bruno Haible  <br...@clisp.org>
 
 	gnulib-tool: Fix comment.
diff --git a/build-aux/bootstrap b/build-aux/bootstrap
index ca7cd84386..2e56c624d2 100755
--- a/build-aux/bootstrap
+++ b/build-aux/bootstrap
@@ -37,7 +37,7 @@ medir=`dirname "$me"`
 
 # A library of shell functions for autopull.sh, autogen.sh, and bootstrap.
 
-scriptlibversion=2024-11-12.17; # UTC
+scriptlibversion=2024-11-12.20; # UTC
 
 # Copyright (C) 2003-2024 Free Software Foundation, Inc.
 #
@@ -545,45 +545,49 @@ prepare_GNULIB_SRCDIR ()
       if test ! -d "$gnulib_path"; then
         # The subdirectory 'gnulib' does not yet exist. Clone into it.
         echo "$0: getting gnulib files..."
+        trap cleanup_gnulib HUP INT PIPE TERM
+        gnulib_url=${GNULIB_URL:-$default_gnulib_url}
+        shallow=
         if test -n "$GNULIB_REFDIR" && test -d "$GNULIB_REFDIR"/.git; then
           # Use GNULIB_REFDIR as a reference.
-          git clone "$GNULIB_REFDIR" "$gnulib_path" || cleanup_gnulib
+          git clone "$GNULIB_REFDIR" "$gnulib_path" \
+          && git -C "$gnulib_path" remote set-url origin "$gnulib_url" \
+          && if test -z "$GNULIB_REVISION"; then
+               git -C "$gnulib_path" pull origin
+             else
+               git -C "$gnulib_path" checkout "$GNULIB_REVISION" 2>/dev/null \
+               || { git -C "$gnulib_path" fetch origin \
+                    && git -C "$gnulib_path" checkout "$GNULIB_REVISION"; }
+             fi || cleanup_gnulib
+        elif test -z "$GNULIB_REVISION"; then
+          if git clone -h 2>&1 | grep -- --depth > /dev/null; then
+            shallow='--depth 2'
+          fi
+          git clone $shallow "$gnulib_url" "$gnulib_path" \
+            || cleanup_gnulib
         else
-          # GNULIB_REFDIR is not set or not usable. Ignore it.
-          trap cleanup_gnulib HUP INT PIPE TERM
-          gnulib_url=${GNULIB_URL:-$default_gnulib_url}
-          shallow=
-          if test -z "$GNULIB_REVISION"; then
-            if git clone -h 2>&1 | grep -- --depth > /dev/null; then
-              shallow='--depth 2'
-            fi
-            git clone $shallow "$gnulib_url" "$gnulib_path" \
-              || cleanup_gnulib
-          else
-            if git fetch -h 2>&1 | grep -- --depth > /dev/null; then
-              shallow='--depth 2'
-            fi
-            mkdir -p "$gnulib_path"
-            # Only want a shallow checkout of $GNULIB_REVISION,
-            # but git does not support cloning by commit hash.
-            # So attempt a shallow fetch by commit hash to minimize
-            # the amount of data downloaded and changes needed to be
-            # processed, which can drastically reduce download and
-            # processing time for checkout. If the fetch by commit fails,
-            # a shallow fetch can not be performed because we do not
-            # know what the depth of the commit is without fetching
-            # all commits. So fall back to fetching all commits.
-            git -C "$gnulib_path" init
-            git -C "$gnulib_path" remote add origin "$gnulib_url"
-            git -C "$gnulib_path" fetch $shallow origin "$GNULIB_REVISION" \
-              || git -C "$gnulib_path" fetch origin \
-              || cleanup_gnulib
-            git -C "$gnulib_path" reset --hard FETCH_HEAD
-            (cd "$gnulib_path" && git checkout "$GNULIB_REVISION") \
-              || cleanup_gnulib
+          if git fetch -h 2>&1 | grep -- --depth > /dev/null; then
+            shallow='--depth 2'
           fi
-          trap - HUP INT PIPE TERM
+          mkdir -p "$gnulib_path"
+          # Only want a shallow checkout of $GNULIB_REVISION, but git does not
+          # support cloning by commit hash. So attempt a shallow fetch by commit
+          # hash to minimize the amount of data downloaded and changes needed to
+          # be processed, which can drastically reduce download and processing
+          # time for checkout. If the fetch by commit fails, a shallow fetch can
+          # not be performed because we do not know what the depth of the commit
+          # is without fetching all commits. So fall back to fetching all
+          # commits.
+          git -C "$gnulib_path" init
+          git -C "$gnulib_path" remote add origin "$gnulib_url"
+          git -C "$gnulib_path" fetch $shallow origin "$GNULIB_REVISION" \
+            || git -C "$gnulib_path" fetch origin \
+            || cleanup_gnulib
+          git -C "$gnulib_path" reset --hard FETCH_HEAD
+          (cd "$gnulib_path" && git checkout "$GNULIB_REVISION") \
+            || cleanup_gnulib
         fi
+        trap - HUP INT PIPE TERM
       else
         # The subdirectory 'gnulib' already exists.
         if test -n "$GNULIB_REVISION"; then
@@ -728,7 +732,8 @@ Gnulib sources can be fetched in various ways:
 
  * Otherwise, if the 'gnulib' directory does not exist, Gnulib sources
    are cloned into that directory using git from \$GNULIB_URL, defaulting
-   to $default_gnulib_url.
+   to $default_gnulib_url; if GNULIB_REFDIR is set and is a git repository
+   its contents may be used to accelerate the process.
    If the configuration variable GNULIB_REVISION is set in bootstrap.conf,
    then that revision is checked out.
 
diff --git a/top/bootstrap-funclib.sh b/top/bootstrap-funclib.sh
index 0d8b5a259d..fb2039876f 100644
--- a/top/bootstrap-funclib.sh
+++ b/top/bootstrap-funclib.sh
@@ -1,6 +1,6 @@
 # A library of shell functions for autopull.sh, autogen.sh, and bootstrap.
 
-scriptlibversion=2024-11-12.17; # UTC
+scriptlibversion=2024-11-12.20; # UTC
 
 # Copyright (C) 2003-2024 Free Software Foundation, Inc.
 #
@@ -508,45 +508,49 @@ prepare_GNULIB_SRCDIR ()
       if test ! -d "$gnulib_path"; then
         # The subdirectory 'gnulib' does not yet exist. Clone into it.
         echo "$0: getting gnulib files..."
+        trap cleanup_gnulib HUP INT PIPE TERM
+        gnulib_url=${GNULIB_URL:-$default_gnulib_url}
+        shallow=
         if test -n "$GNULIB_REFDIR" && test -d "$GNULIB_REFDIR"/.git; then
           # Use GNULIB_REFDIR as a reference.
-          git clone "$GNULIB_REFDIR" "$gnulib_path" || cleanup_gnulib
+          git clone "$GNULIB_REFDIR" "$gnulib_path" \
+          && git -C "$gnulib_path" remote set-url origin "$gnulib_url" \
+          && if test -z "$GNULIB_REVISION"; then
+               git -C "$gnulib_path" pull origin
+             else
+               git -C "$gnulib_path" checkout "$GNULIB_REVISION" 2>/dev/null \
+               || { git -C "$gnulib_path" fetch origin \
+                    && git -C "$gnulib_path" checkout "$GNULIB_REVISION"; }
+             fi || cleanup_gnulib
+        elif test -z "$GNULIB_REVISION"; then
+          if git clone -h 2>&1 | grep -- --depth > /dev/null; then
+            shallow='--depth 2'
+          fi
+          git clone $shallow "$gnulib_url" "$gnulib_path" \
+            || cleanup_gnulib
         else
-          # GNULIB_REFDIR is not set or not usable. Ignore it.
-          trap cleanup_gnulib HUP INT PIPE TERM
-          gnulib_url=${GNULIB_URL:-$default_gnulib_url}
-          shallow=
-          if test -z "$GNULIB_REVISION"; then
-            if git clone -h 2>&1 | grep -- --depth > /dev/null; then
-              shallow='--depth 2'
-            fi
-            git clone $shallow "$gnulib_url" "$gnulib_path" \
-              || cleanup_gnulib
-          else
-            if git fetch -h 2>&1 | grep -- --depth > /dev/null; then
-              shallow='--depth 2'
-            fi
-            mkdir -p "$gnulib_path"
-            # Only want a shallow checkout of $GNULIB_REVISION,
-            # but git does not support cloning by commit hash.
-            # So attempt a shallow fetch by commit hash to minimize
-            # the amount of data downloaded and changes needed to be
-            # processed, which can drastically reduce download and
-            # processing time for checkout. If the fetch by commit fails,
-            # a shallow fetch can not be performed because we do not
-            # know what the depth of the commit is without fetching
-            # all commits. So fall back to fetching all commits.
-            git -C "$gnulib_path" init
-            git -C "$gnulib_path" remote add origin "$gnulib_url"
-            git -C "$gnulib_path" fetch $shallow origin "$GNULIB_REVISION" \
-              || git -C "$gnulib_path" fetch origin \
-              || cleanup_gnulib
-            git -C "$gnulib_path" reset --hard FETCH_HEAD
-            (cd "$gnulib_path" && git checkout "$GNULIB_REVISION") \
-              || cleanup_gnulib
+          if git fetch -h 2>&1 | grep -- --depth > /dev/null; then
+            shallow='--depth 2'
           fi
-          trap - HUP INT PIPE TERM
+          mkdir -p "$gnulib_path"
+          # Only want a shallow checkout of $GNULIB_REVISION, but git does not
+          # support cloning by commit hash. So attempt a shallow fetch by commit
+          # hash to minimize the amount of data downloaded and changes needed to
+          # be processed, which can drastically reduce download and processing
+          # time for checkout. If the fetch by commit fails, a shallow fetch can
+          # not be performed because we do not know what the depth of the commit
+          # is without fetching all commits. So fall back to fetching all
+          # commits.
+          git -C "$gnulib_path" init
+          git -C "$gnulib_path" remote add origin "$gnulib_url"
+          git -C "$gnulib_path" fetch $shallow origin "$GNULIB_REVISION" \
+            || git -C "$gnulib_path" fetch origin \
+            || cleanup_gnulib
+          git -C "$gnulib_path" reset --hard FETCH_HEAD
+          (cd "$gnulib_path" && git checkout "$GNULIB_REVISION") \
+            || cleanup_gnulib
         fi
+        trap - HUP INT PIPE TERM
       else
         # The subdirectory 'gnulib' already exists.
         if test -n "$GNULIB_REVISION"; then
@@ -691,7 +695,8 @@ Gnulib sources can be fetched in various ways:
 
  * Otherwise, if the 'gnulib' directory does not exist, Gnulib sources
    are cloned into that directory using git from \$GNULIB_URL, defaulting
-   to $default_gnulib_url.
+   to $default_gnulib_url; if GNULIB_REFDIR is set and is a git repository
+   its contents may be used to accelerate the process.
    If the configuration variable GNULIB_REVISION is set in bootstrap.conf,
    then that revision is checked out.
 
-- 
2.43.0

From fd902a8e3911ff6eee2f42c6809b965f877a398f Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Tue, 12 Nov 2024 13:13:47 -0800
Subject: [PATCH 2/2] bootstrap: avoid "cd"

* top/bootstrap-funclib.sh: Avoid "cd".  This saves a few
subprocesses and is more likely to yield diagnostics that make
sense to the user.
* build-aux/bootstrap: Regenerate.
---
 ChangeLog                |  6 ++++++
 build-aux/bootstrap      | 29 ++++++++++++-----------------
 top/bootstrap-funclib.sh | 29 ++++++++++++-----------------
 3 files changed, 30 insertions(+), 34 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 213714cc52..9473f36f22 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2024-11-12  Paul Eggert  <egg...@cs.ucla.edu>
 
+	bootstrap: avoid "cd"
+	* top/bootstrap-funclib.sh: Avoid "cd".  This saves a few
+	subprocesses and is more likely to yield diagnostics that make
+	sense to the user.
+	* build-aux/bootstrap: Regenerate.
+
 	bootstrap: go back to old non-submodule semantics
 	* top/bootstrap-funclib.sh (prepare_GNULIB_SRCDIR):
 	When cloning GNULIB_REFDIR and no submodule 'gnulib' is configured,
diff --git a/build-aux/bootstrap b/build-aux/bootstrap
index 2e56c624d2..94c07d15fe 100755
--- a/build-aux/bootstrap
+++ b/build-aux/bootstrap
@@ -37,7 +37,7 @@ medir=`dirname "$me"`
 
 # A library of shell functions for autopull.sh, autogen.sh, and bootstrap.
 
-scriptlibversion=2024-11-12.20; # UTC
+scriptlibversion=2024-11-12.21; # UTC
 
 # Copyright (C) 2003-2024 Free Software Foundation, Inc.
 #
@@ -505,11 +505,10 @@ prepare_GNULIB_SRCDIR ()
       # if the GNULIB_REVISION is a commit hash that only exists in
       # origin. In this case, we need a 'git fetch' and then retry
       # 'git checkout "$GNULIB_REVISION"'.
-      (cd "$GNULIB_SRCDIR" \
-       && { git checkout "$GNULIB_REVISION" 2>/dev/null \
-            || { git fetch origin && git checkout "$GNULIB_REVISION"; }
-          }
-      ) || exit $?
+      git -C "$GNULIB_SRCDIR" checkout "$GNULIB_REVISION" 2>/dev/null \
+      || { git -C "$GNULIB_SRCDIR" fetch origin \
+           && git -C "$GNULIB_SRCDIR" checkout "$GNULIB_REVISION"; } \
+      || exit $?
     fi
   else
     if ! $use_git; then
@@ -584,8 +583,7 @@ prepare_GNULIB_SRCDIR ()
             || git -C "$gnulib_path" fetch origin \
             || cleanup_gnulib
           git -C "$gnulib_path" reset --hard FETCH_HEAD
-          (cd "$gnulib_path" && git checkout "$GNULIB_REVISION") \
-            || cleanup_gnulib
+          git -C "$gnulib_path" checkout "$GNULIB_REVISION" || cleanup_gnulib
         fi
         trap - HUP INT PIPE TERM
       else
@@ -598,11 +596,10 @@ prepare_GNULIB_SRCDIR ()
             # if the GNULIB_REVISION is a commit hash that only exists in
             # origin. In this case, we need a 'git fetch' and then retry
             # 'git checkout "$GNULIB_REVISION"'.
-            (cd "$gnulib_path" \
-             && { git checkout "$GNULIB_REVISION" 2>/dev/null \
-                  || { git fetch origin && git checkout "$GNULIB_REVISION"; }
-                }
-            ) || exit $?
+            git -C "$gnulib_path" checkout "$GNULIB_REVISION" 2>/dev/null \
+            || { git -C "$gnulib_path" fetch origin \
+                 && git -C "$gnulib_path" checkout "$GNULIB_REVISION"; } \
+            || exit $?
           else
             die "Error: GNULIB_REVISION is specified in bootstrap.conf," \
                 "but '$gnulib_path' contains no git history"
@@ -901,9 +898,7 @@ update_po_files() {
     && ls "$ref_po_dir"/*.po 2>/dev/null |
       sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return
 
-  langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g')
-  test "$langs" = '*' && langs=x
-  for po in $langs; do
+  for po in x $(ls $ref_po_dir | sed -n 's/\.po$//p'); do
     case $po in x) continue;; esac
     new_po="$ref_po_dir/$po.po"
     cksum_file="$ref_po_dir/$po.s1"
@@ -1366,7 +1361,7 @@ autogen()
       || die 'cannot generate runtime-po/Makevars'
 
       # Copy identical files from po to runtime-po.
-      (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
+      cp -p po/Makefile.in.in po/*-quot po/*.header po/*.sed po/*.sin runtime-po
     fi
   fi
 
diff --git a/top/bootstrap-funclib.sh b/top/bootstrap-funclib.sh
index fb2039876f..569ab728d0 100644
--- a/top/bootstrap-funclib.sh
+++ b/top/bootstrap-funclib.sh
@@ -1,6 +1,6 @@
 # A library of shell functions for autopull.sh, autogen.sh, and bootstrap.
 
-scriptlibversion=2024-11-12.20; # UTC
+scriptlibversion=2024-11-12.21; # UTC
 
 # Copyright (C) 2003-2024 Free Software Foundation, Inc.
 #
@@ -468,11 +468,10 @@ prepare_GNULIB_SRCDIR ()
       # if the GNULIB_REVISION is a commit hash that only exists in
       # origin. In this case, we need a 'git fetch' and then retry
       # 'git checkout "$GNULIB_REVISION"'.
-      (cd "$GNULIB_SRCDIR" \
-       && { git checkout "$GNULIB_REVISION" 2>/dev/null \
-            || { git fetch origin && git checkout "$GNULIB_REVISION"; }
-          }
-      ) || exit $?
+      git -C "$GNULIB_SRCDIR" checkout "$GNULIB_REVISION" 2>/dev/null \
+      || { git -C "$GNULIB_SRCDIR" fetch origin \
+           && git -C "$GNULIB_SRCDIR" checkout "$GNULIB_REVISION"; } \
+      || exit $?
     fi
   else
     if ! $use_git; then
@@ -547,8 +546,7 @@ prepare_GNULIB_SRCDIR ()
             || git -C "$gnulib_path" fetch origin \
             || cleanup_gnulib
           git -C "$gnulib_path" reset --hard FETCH_HEAD
-          (cd "$gnulib_path" && git checkout "$GNULIB_REVISION") \
-            || cleanup_gnulib
+          git -C "$gnulib_path" checkout "$GNULIB_REVISION" || cleanup_gnulib
         fi
         trap - HUP INT PIPE TERM
       else
@@ -561,11 +559,10 @@ prepare_GNULIB_SRCDIR ()
             # if the GNULIB_REVISION is a commit hash that only exists in
             # origin. In this case, we need a 'git fetch' and then retry
             # 'git checkout "$GNULIB_REVISION"'.
-            (cd "$gnulib_path" \
-             && { git checkout "$GNULIB_REVISION" 2>/dev/null \
-                  || { git fetch origin && git checkout "$GNULIB_REVISION"; }
-                }
-            ) || exit $?
+            git -C "$gnulib_path" checkout "$GNULIB_REVISION" 2>/dev/null \
+            || { git -C "$gnulib_path" fetch origin \
+                 && git -C "$gnulib_path" checkout "$GNULIB_REVISION"; } \
+            || exit $?
           else
             die "Error: GNULIB_REVISION is specified in bootstrap.conf," \
                 "but '$gnulib_path' contains no git history"
@@ -864,9 +861,7 @@ update_po_files() {
     && ls "$ref_po_dir"/*.po 2>/dev/null |
       sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return
 
-  langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g')
-  test "$langs" = '*' && langs=x
-  for po in $langs; do
+  for po in x $(ls $ref_po_dir | sed -n 's/\.po$//p'); do
     case $po in x) continue;; esac
     new_po="$ref_po_dir/$po.po"
     cksum_file="$ref_po_dir/$po.s1"
@@ -1329,7 +1324,7 @@ autogen()
       || die 'cannot generate runtime-po/Makevars'
 
       # Copy identical files from po to runtime-po.
-      (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
+      cp -p po/Makefile.in.in po/*-quot po/*.header po/*.sed po/*.sin runtime-po
     fi
   fi
 
-- 
2.43.0

Reply via email to