]> Savannah Git Hosting - gnulib.git/commitdiff
bootstrap: Tweak GNULIB_REFDIR related changes.
authorBruno Haible <bruno@clisp.org>
Wed, 13 Nov 2024 00:25:26 +0000 (01:25 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 13 Nov 2024 01:12:54 +0000 (02:12 +0100)
* top/bootstrap-funclib.sh (prepare_GNULIB_SRCDIR): Improve if/else
structure and comments. When cloning GNULIB_REFDIR and no submodule
'gnulib' is configured, switch to the default branch.
* top/bootstrap (usage):  Update documentation.
* build-aux/bootstrap: Regenerated.

ChangeLog
build-aux/bootstrap
top/bootstrap
top/bootstrap-funclib.sh

index 9473f36f226465d86cbfab72d802dbbd5c7cf526..6840768b00aecd86c8b741b539934c362823a2d4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-11-12  Bruno Haible  <bruno@clisp.org>
+
+       bootstrap: Tweak GNULIB_REFDIR related changes.
+       * top/bootstrap-funclib.sh (prepare_GNULIB_SRCDIR): Improve if/else
+       structure and comments. When cloning GNULIB_REFDIR and no submodule
+       'gnulib' is configured, switch to the default branch.
+       * top/bootstrap (usage):  Update documentation.
+       * build-aux/bootstrap: Regenerated.
+
 2024-11-12  Paul Eggert  <eggert@cs.ucla.edu>
 
        bootstrap: avoid "cd"
@@ -12,6 +21,7 @@
        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.
+       (autopull_usage): Update documentation.
        * build-aux/bootstrap: Regenerate.
 
 2024-11-12  Bruno Haible  <bruno@clisp.org>
index 94c07d15fe4b0d4bedd2f0c553475049f34fa5b8..272e3a7181b3ae67b1a2bdda96e8783180417cd0 100755 (executable)
@@ -546,44 +546,64 @@ prepare_GNULIB_SRCDIR ()
         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" \
           && git -C "$gnulib_path" remote set-url origin "$gnulib_url" \
           && if test -z "$GNULIB_REVISION"; then
-               git -C "$gnulib_path" pull origin
+               git -C "$gnulib_path" pull origin \
+               && {
+                 # We want the default branch of "$gnulib_url" (since that's
+                 # the behaviour if GNULIB_REFDIR is not specified), not the
+                 # current branch of "$GNULIB_REFDIR".
+                 default_branch=`LC_ALL=C git -C "$gnulib_path" \
+                                              remote show origin \
+                                 | sed -n -e 's/^ *HEAD branch: //p'`
+                 test -n "$default_branch" || default_branch='master'
+                 git -C "$gnulib_path" checkout "$default_branch"
+               }
              else
+               # The 'git checkout "$GNULIB_REVISION"' command succeeds if the
+               # GNULIB_REVISION is a commit hash that exists locally, or if it
+               # is a branch name that can be fetched from origin. It fails,
+               # however, 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"'.
                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
+             fi \
+          || cleanup_gnulib
         else
-          if git fetch -h 2>&1 | grep -- --depth > /dev/null; then
-            shallow='--depth 2'
+          # GNULIB_REFDIR is not set or not usable. Ignore it.
+          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
+            git -C "$gnulib_path" checkout "$GNULIB_REVISION" || cleanup_gnulib
           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
-          git -C "$gnulib_path" checkout "$GNULIB_REVISION" || cleanup_gnulib
         fi
         trap - HUP INT PIPE TERM
       else
@@ -591,11 +611,11 @@ prepare_GNULIB_SRCDIR ()
         if test -n "$GNULIB_REVISION"; then
           if test -d "$gnulib_path/.git"; then
             # The 'git checkout "$GNULIB_REVISION"' command succeeds if the
-            # GNULIB_REVISION is a commit hash that exists locally, or if it is
-            # branch name that can be fetched from origin. It fails, however,
-            # 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"'.
+            # GNULIB_REVISION is a commit hash that exists locally, or if it
+            # is a branch name that can be fetched from origin. It fails,
+            # however, 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"'.
             git -C "$gnulib_path" checkout "$GNULIB_REVISION" 2>/dev/null \
             || { git -C "$gnulib_path" fetch origin \
                  && git -C "$gnulib_path" checkout "$GNULIB_REVISION"; } \
@@ -1463,7 +1483,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.
 
index 2136d119e3b08ceda4dbafa4b8566d7bf0ab4a17..6acad165a31d97a1e05ae43862bbec29d4d70495 100755 (executable)
@@ -117,7 +117,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.
 
index 569ab728d0cbc50dfa9f58e49c430d43f30e69e4..7c125533e0590b6188b9bb57993ef3a08ba19a82 100644 (file)
@@ -509,44 +509,64 @@ prepare_GNULIB_SRCDIR ()
         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" \
           && git -C "$gnulib_path" remote set-url origin "$gnulib_url" \
           && if test -z "$GNULIB_REVISION"; then
-               git -C "$gnulib_path" pull origin
+               git -C "$gnulib_path" pull origin \
+               && {
+                 # We want the default branch of "$gnulib_url" (since that's
+                 # the behaviour if GNULIB_REFDIR is not specified), not the
+                 # current branch of "$GNULIB_REFDIR".
+                 default_branch=`LC_ALL=C git -C "$gnulib_path" \
+                                              remote show origin \
+                                 | sed -n -e 's/^ *HEAD branch: //p'`
+                 test -n "$default_branch" || default_branch='master'
+                 git -C "$gnulib_path" checkout "$default_branch"
+               }
              else
+               # The 'git checkout "$GNULIB_REVISION"' command succeeds if the
+               # GNULIB_REVISION is a commit hash that exists locally, or if it
+               # is a branch name that can be fetched from origin. It fails,
+               # however, 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"'.
                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
+             fi \
+          || cleanup_gnulib
         else
-          if git fetch -h 2>&1 | grep -- --depth > /dev/null; then
-            shallow='--depth 2'
+          # GNULIB_REFDIR is not set or not usable. Ignore it.
+          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
+            git -C "$gnulib_path" checkout "$GNULIB_REVISION" || cleanup_gnulib
           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
-          git -C "$gnulib_path" checkout "$GNULIB_REVISION" || cleanup_gnulib
         fi
         trap - HUP INT PIPE TERM
       else
@@ -554,11 +574,11 @@ prepare_GNULIB_SRCDIR ()
         if test -n "$GNULIB_REVISION"; then
           if test -d "$gnulib_path/.git"; then
             # The 'git checkout "$GNULIB_REVISION"' command succeeds if the
-            # GNULIB_REVISION is a commit hash that exists locally, or if it is
-            # branch name that can be fetched from origin. It fails, however,
-            # 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"'.
+            # GNULIB_REVISION is a commit hash that exists locally, or if it
+            # is a branch name that can be fetched from origin. It fails,
+            # however, 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"'.
             git -C "$gnulib_path" checkout "$GNULIB_REVISION" 2>/dev/null \
             || { git -C "$gnulib_path" fetch origin \
                  && git -C "$gnulib_path" checkout "$GNULIB_REVISION"; } \