Skip to contentSkip to conversation

bootstrap: When a commit hash is specified, do a shallow fetch if possible

PATCH In review Glenn Washburn 2 participants 6 messages Oct 21, 2021 – Jan 8, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bootstrap: When a commit hash is specified, do a shallow fetch if possible

The gnulib sources are large but more importantly have lots of changes. So initial checkout of the repository can take a long time when network or cpu resources are limited. The later is especially acute in a non-KVM QEMU virtual machine (which can take 40+ minutes compared to <30 seconds with this change[1]). The problem is specific to how GRUB uses gnulib, which is by pegging the desired checkout to a specific git revision. In this case, git can not do a shallow clone by using the --depth option because git does not know ahead of time how deep the revision is from the tip. So git must clone the whole repository.

However, there is an alternate method that requires support from the git server[2], namely by asking for a specific commit on fetch. Refactor to use fetch and fallback to fetching the entire repository if fetching by commit hash fails.

Currently the git server hosting the official gnulib git repository does not support fetch by commit hash[3]. However, there are mirrors which do support this[4], and can be specified by setting the $GNULIB_URL.

[1] https://savannah.nongnu.org/support/index.php?110553#comment1
[2] https://stackoverflow.com/a/3489576/2108011
[3] https://savannah.nongnu.org/support/index.php?110553
[4] https://github.com/coreutils/gnulib

---
 bootstrap | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
bootstrap +14 -2
index 5b08e7e2d..914f911f8 100755
@@ -665,9 +665,21 @@ if $use_gnulib; then
       shallow=
       if test -z "$GNULIB_REVISION"; then
         git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
+        git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
+          || cleanup_gnulib
+      else
+        git fetch -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
+        mkdir -p "$gnulib_path"
+        git -C "$gnulib_path" init
+        git -C "$gnulib_path" remote add origin ${GNULIB_URL:-$default_gnulib_url}
+        # Can not do a shallow fetch if fetch by commit hash fails because we
+        # do not know how the to go to get to $GNULIB_REVISION, so we must get
+        # all commits.
+        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
       fi
-      git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
-        || cleanup_gnulib
 
       trap - 1 2 13 15
     fi
Signature · 1 line
2.27.0
#1 lore raw
Quoted 6 lines · On Thu, 21 Oct 2021 12:49:19 -0500 Glenn Washburn…

The gnulib sources are large but more importantly have lots of changes. So initial checkout of the repository can take a long time when network or cpu resources are limited. The later is especially acute in a non-KVM QEMU virtual machine (which can take 40+ minutes compared to <30 seconds with this change[1]). The problem is specific to how GRUB uses gnulib, which is by pegging the desired checkout to a specific git revision. In this case,

FWIW, the patch I've upstreamed has removed references to GRUB. I don't think its matters here, because we'd have our own patch regardless and it doesn't need to be the same as upstream anyway.

Quoted 30 lines

git can not do a shallow clone by using the --depth option because git does not know ahead of time how deep the revision is from the tip. So git must clone the whole repository.

However, there is an alternate method that requires support from the git server[2], namely by asking for a specific commit on fetch. Refactor to use fetch and fallback to fetching the entire repository if fetching by commit hash fails.

Currently the git server hosting the official gnulib git repository does not support fetch by commit hash[3]. However, there are mirrors which do support this[4], and can be specified by setting the $GNULIB_URL.

[1] https://savannah.nongnu.org/support/index.php?110553#comment1
[2] https://stackoverflow.com/a/3489576/2108011
[3] https://savannah.nongnu.org/support/index.php?110553
[4] https://github.com/coreutils/gnulib

---
 bootstrap | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
bootstrap +0 -0
index 5b08e7e2d..914f911f8 100755
@@ -665,9 +665,21 @@ if $use_gnulib; then
       shallow=
       if test -z "$GNULIB_REVISION"; then

bootstrap if $use_gnulib; then · line 676

Quoted 10 lines
bootstrap +9 -0
         git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
+        git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
+          || cleanup_gnulib
+      else
+        git fetch -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
+        mkdir -p "$gnulib_path"
+        git -C "$gnulib_path" init
+        git -C "$gnulib_path" remote add origin ${GNULIB_URL:-$default_gnulib_url}
+        # Can not do a shallow fetch if fetch by commit hash fails because we
+        # do not know how the to go to get to $GNULIB_REVISION, so we must get

Should be "know how deep to go". Daniel, if this is accepted as is, perhaps you could make this change.

Glenn

Quoted 11 lines
bootstrap +5 -2
+        # all commits.
+        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
       fi
-      git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
-        || cleanup_gnulib
 
       trap - 1 2 13 15
     fi
#2 lore raw
In reply to Glenn Washburn
Quoted 41 lines · Glenn Washburn

The gnulib sources are large but more importantly have lots of changes. So initial checkout of the repository can take a long time when network or cpu resources are limited. The later is especially acute in a non-KVM QEMU virtual machine (which can take 40+ minutes compared to <30 seconds with this change[1]). The problem is specific to how GRUB uses gnulib, which is by pegging the desired checkout to a specific git revision. In this case, git can not do a shallow clone by using the --depth option because git does not know ahead of time how deep the revision is from the tip. So git must clone the whole repository.

However, there is an alternate method that requires support from the git server[2], namely by asking for a specific commit on fetch. Refactor to use fetch and fallback to fetching the entire repository if fetching by commit hash fails.

Currently the git server hosting the official gnulib git repository does not support fetch by commit hash[3]. However, there are mirrors which do support this[4], and can be specified by setting the $GNULIB_URL.

[1] https://savannah.nongnu.org/support/index.php?110553#comment1
[2] https://stackoverflow.com/a/3489576/2108011
[3] https://savannah.nongnu.org/support/index.php?110553
[4] https://github.com/coreutils/gnulib

---
 bootstrap | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
bootstrap +4 -0
index 5b08e7e2d..914f911f8 100755
@@ -665,9 +665,21 @@ if $use_gnulib; then
       shallow=
       if test -z "$GNULIB_REVISION"; then
         git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
+        git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
+          || cleanup_gnulib
+      else
+        git fetch -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'

bootstrap if $use_gnulib; then · line 681

Quoted 10 lines
bootstrap +10 -0
+        mkdir -p "$gnulib_path"
+        git -C "$gnulib_path" init
+        git -C "$gnulib_path" remote add origin ${GNULIB_URL:-$default_gnulib_url}
+        # Can not do a shallow fetch if fetch by commit hash fails because we
+        # do not know how the to go to get to $GNULIB_REVISION, so we must get
+        # all commits.
+        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

Is this hunk from gnulib upstream? If not I would prefer if you upstream it into gnulib. We should avoid custom patches for imported code as much as possible.

Daniel

#3 lore raw
Quoted 11 lines · On Fri, 22 Oct 2021 18:44:15 +0200 Daniel Kiper <[email protected]> wrote:
Quoted 10 lines · Glenn Washburn

The gnulib sources are large but more importantly have lots of changes. So initial checkout of the repository can take a long time when network or cpu resources are limited. The later is especially acute in a non-KVM QEMU virtual machine (which can take 40+ minutes compared to <30 seconds with this change[1]). The problem is specific to how GRUB uses gnulib, which is by pegging the desired checkout to a specific git revision. In this case, git can not do a shallow clone by using the --depth option because git does not know ahead of time how deep the revision is from the tip. So git must clone the whole repository.

Quoted 8 lines
Quoted 8 lines

However, there is an alternate method that requires support from the git server[2], namely by asking for a specific commit on fetch. Refactor to use fetch and fallback to fetching the entire repository if fetching by commit hash fails.

Currently the git server hosting the official gnulib git repository does not support fetch by commit hash[3]. However, there are mirrors which do support this[4], and can be specified by setting the $GNULIB_URL.

This paragraph is now out of date, the git server configuration change happened much more quickly than I expected. So before committing it should be removed along with the last two references.

Quoted 29 lines
Quoted 29 lines

[1] https://savannah.nongnu.org/support/index.php?110553#comment1
[2] https://stackoverflow.com/a/3489576/2108011
[3] https://savannah.nongnu.org/support/index.php?110553
[4] https://github.com/coreutils/gnulib

---
 bootstrap | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
bootstrap +10 -0
index 5b08e7e2d..914f911f8 100755
@@ -665,9 +665,21 @@ if $use_gnulib; then
       shallow=
       if test -z "$GNULIB_REVISION"; then
         git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
+        git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
+          || cleanup_gnulib
+      else
+        git fetch -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
+        mkdir -p "$gnulib_path"
+        git -C "$gnulib_path" init
+        git -C "$gnulib_path" remote add origin ${GNULIB_URL:-$default_gnulib_url}
+        # Can not do a shallow fetch if fetch by commit hash fails because we
+        # do not know how the to go to get to $GNULIB_REVISION, so we must get
+        # all commits.
Quoted 8 lines

bootstrap if $use_gnulib; then · line 681

Quoted 4 lines
bootstrap +4 -0
+        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

Is this hunk from gnulib upstream? If not I would prefer if you upstream it into gnulib. We should avoid custom patches for imported code as much as possible.

I agree in general. As mentioned in a follow up reply to this patch, I did submit the patch upstream[1]. The only difference is the commit message. It has not been responded to yet. However, even once accepted upstream we'll have to cherry-pick it to the GRUB repo. Are you thinking we'd need to get all changes to bootstrap at that time? It doesn't look like there's anything that would be that useful (except maybe using the https repo url). I'm curious how you'd like to handle this.

I don't think the issue of a custom patch in this instance is a problem though. Bootstrap very rarely changes, even in upstream (<10 changes in the last 2 years). So there I'm not concerned about having to maintain a lot of custom patches on top of it (like the situation of many distros vis-a-vis GRUB). So I think if its not accepted upstream (I don't see why it wouldn't be), I think we should use in GRUB because it provides significant reduction in bandwith and a drastic reduction in time to checkout on a qemu VM (but also significant not on a VM, 5min vs 1min) depending on the CPU resources available. This is especially useful for a CI/testing system that is frequently run.

I'm fine with waiting a few weeks and see what happens upstream.

Glenn

[1] https://lists.gnu.org/archive/html/bug-gnulib/2021-10/msg00052.html

#4 lore raw
Quoted 65 lines · Glenn Washburn
Quoted 11 lines · On Fri, 22 Oct 2021 18:44:15 +0200 Daniel Kiper <[email protected]> wrote:
Quoted 10 lines · Glenn Washburn

The gnulib sources are large but more importantly have lots of changes. So initial checkout of the repository can take a long time when network or cpu resources are limited. The later is especially acute in a non-KVM QEMU virtual machine (which can take 40+ minutes compared to <30 seconds with this change[1]). The problem is specific to how GRUB uses gnulib, which is by pegging the desired checkout to a specific git revision. In this case, git can not do a shallow clone by using the --depth option because git does not know ahead of time how deep the revision is from the tip. So git must clone the whole repository.

Quoted 8 lines
Quoted 8 lines

However, there is an alternate method that requires support from the git server[2], namely by asking for a specific commit on fetch. Refactor to use fetch and fallback to fetching the entire repository if fetching by commit hash fails.

Currently the git server hosting the official gnulib git repository does not support fetch by commit hash[3]. However, there are mirrors which do support this[4], and can be specified by setting the $GNULIB_URL.

This paragraph is now out of date, the git server configuration change happened much more quickly than I expected. So before committing it should be removed along with the last two references.

Quoted 29 lines
Quoted 29 lines

[1] https://savannah.nongnu.org/support/index.php?110553#comment1
[2] https://stackoverflow.com/a/3489576/2108011
[3] https://savannah.nongnu.org/support/index.php?110553
[4] https://github.com/coreutils/gnulib

---
 bootstrap | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
bootstrap +10 -0
index 5b08e7e2d..914f911f8 100755
@@ -665,9 +665,21 @@ if $use_gnulib; then
       shallow=
       if test -z "$GNULIB_REVISION"; then
         git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
+        git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
+          || cleanup_gnulib
+      else
+        git fetch -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
+        mkdir -p "$gnulib_path"
+        git -C "$gnulib_path" init
+        git -C "$gnulib_path" remote add origin ${GNULIB_URL:-$default_gnulib_url}
+        # Can not do a shallow fetch if fetch by commit hash fails because we
+        # do not know how the to go to get to $GNULIB_REVISION, so we must get
+        # all commits.
Quoted 8 lines

bootstrap if $use_gnulib; then · line 681

Quoted 4 lines
bootstrap +4 -0
+        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

Is this hunk from gnulib upstream? If not I would prefer if you upstream it into gnulib. We should avoid custom patches for imported code as much as possible.

Quoted 2 lines

I agree in general. As mentioned in a follow up reply to this patch, I did submit the patch upstream[1]. The only difference is the commit

Oh, sorry, I missed this somehow.

Quoted 6 lines

message. It has not been responded to yet. However, even once accepted upstream we'll have to cherry-pick it to the GRUB repo. Are you thinking we'd need to get all changes to bootstrap at that time? It doesn't look like there's anything that would be that useful (except maybe using the https repo url). I'm curious how you'd like to handle this.

I want to bump the gnulib version to the latest one. Though first of all we have to upstream a few gnulib issues discovered by the Coverity. Darren, CC-ed, is working on it.

Quoted 10 lines

I don't think the issue of a custom patch in this instance is a problem though. Bootstrap very rarely changes, even in upstream (<10 changes in the last 2 years). So there I'm not concerned about having to maintain a lot of custom patches on top of it (like the situation of many distros vis-a-vis GRUB). So I think if its not accepted upstream (I don't see why it wouldn't be), I think we should use in GRUB because it provides significant reduction in bandwith and a drastic reduction in time to checkout on a qemu VM (but also significant not on a VM, 5min vs 1min) depending on the CPU resources available. This is especially useful for a CI/testing system that is frequently run.

If gnulib upstream folks reject it then I can consider taking this patch into the GRUB.

Quoted 1 line

I'm fine with waiting a few weeks and see what happens upstream.

Sounds like a plan.

Daniel

Quoted 3 lines

Glenn

[1] https://lists.gnu.org/archive/html/bug-gnulib/2021-10/msg00052.html

#5 lore raw
Quoted 20 lines · On Mon, 25 Oct 2021 23:35:06 +0200 Daniel Kiper <[email protected]> wrote:
Quoted 9 lines · Glenn Washburn
Quoted 3 lines · On Fri, 22 Oct 2021 18:44:15 +0200 Daniel Kiper <[email protected]> wrote:

Is this hunk from gnulib upstream? If not I would prefer if you upstream it into gnulib. We should avoid custom patches for imported code as much as possible.

I agree in general. As mentioned in a follow up reply to this patch, I did submit the patch upstream[1]. The only difference is the commit

Oh, sorry, I missed this somehow.

Quoted 6 lines

message. It has not been responded to yet. However, even once accepted upstream we'll have to cherry-pick it to the GRUB repo. Are you thinking we'd need to get all changes to bootstrap at that time? It doesn't look like there's anything that would be that useful (except maybe using the https repo url). I'm curious how you'd like to handle this.

Quoted 3 lines

I want to bump the gnulib version to the latest one. Though first of all we have to upstream a few gnulib issues discovered by the Coverity. Darren, CC-ed, is working on it.

What's the current status of this?

Quoted 11 lines
Quoted 10 lines

I don't think the issue of a custom patch in this instance is a problem though. Bootstrap very rarely changes, even in upstream (<10 changes in the last 2 years). So there I'm not concerned about having to maintain a lot of custom patches on top of it (like the situation of many distros vis-a-vis GRUB). So I think if its not accepted upstream (I don't see why it wouldn't be), I think we should use in GRUB because it provides significant reduction in bandwith and a drastic reduction in time to checkout on a qemu VM (but also significant not on a VM, 5min vs 1min) depending on the CPU resources available. This is especially useful for a CI/testing system that is frequently run.

Quoted 12 lines

If gnulib upstream folks reject it then I can consider taking this patch into the GRUB.

Quoted 1 line

I'm fine with waiting a few weeks and see what happens upstream.

Sounds like a plan.

Daniel

Quoted 3 lines

Glenn

[1] https://lists.gnu.org/archive/html/bug-gnulib/2021-10/msg00052.html

Ok its finally been committed to the upstream repo after being missed these past few months. Once/if the Coverity issues are committed we can work on using the latest git revision.

Glenn