Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use git protocol v2 for shallow git_repository fetches #12199

Conversation

michaeleisel
Copy link
Contributor

Without this, the git fetch was failing for me. I believe git operations run with protocol v2 should work seamlessly with other git operations, but I'm not an expert. v2 is the default in git 2.26+, but e.g. MacOS isn't there yet. The global config analogy would be git config --global protocol.version 2.

@michaeleisel
Copy link
Contributor Author

@HackAttack can you take a look?

@oquenchil oquenchil added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Oct 5, 2020
@philwo
Copy link
Member

philwo commented Oct 5, 2020

Hi @michaeleisel, thanks for this fix!

I tested this manually on:

  • CentOS 7 with git 1.8.3.1,
  • Ubuntu 16.04 with git 2.7.4,
  • Ubuntu 18.04 with git 2.17.1,
  • Ubuntu 20.04 with git 2.25.1.

It works fine everywhere except on Ubuntu 18.04:

$ docker run --rm -it ubuntu:18.04 bash
$ apt update && apt install -y git
$ git --version
git version 2.17.1

$ git clone --depth 1 https://github.com/bazelbuild/bazelisk.git
Cloning into 'bazelisk'...
remote: Enumerating objects: 48, done.
remote: Counting objects: 100% (48/48), done.
remote: Compressing objects: 100% (41/41), done.
remote: Total 48 (delta 5), reused 20 (delta 3), pack-reused 0
Unpacking objects: 100% (48/48), done.

$ git -c protocol.version=2 clone --depth 1 https://github.com/bazelbuild/bazelisk.git
Cloning into 'bazelisk'...
fatal: unknown value for config 'protocol.version': 2

So, this would be a regression for users of Ubuntu 18.04, which is a supported OS for Bazel. 😞

Could you explain more about the git invocation where you got an error without this additional flag? What was the error message?

@@ -173,7 +173,7 @@ def _git_maybe_shallow(ctx, git_repo, command, *args):
start = ["git", command]
args_list = list(args)
if git_repo.shallow:
st = _execute(ctx, git_repo, start + [git_repo.shallow] + args_list)
st = _execute(ctx, git_repo, ["git", "-c", "protocol.version=2", command, git_repo.shallow] + args_list)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not make this change to start above, so it applies everywhere?

@michaeleisel
Copy link
Contributor Author

michaeleisel commented Oct 6, 2020

@philwo this is just a fast path for which we handle failure for anyways (see directly below the change), and my understanding is that protocol v2 is needed for fetching arbitrary shas. so, it's not a regression in terms of stability. the example where you succeeded without it is one where it's not fetching an arbitrary sha. for specific cases like that where the sha is being advertised, it is indeed a regression in performance, and perhaps we could run this command twice, once with protocol v2, and once without

@HackAttack the reason to only use it here was to limit the impact of this flag, which seems to be good since there's this regression

@HackAttack
Copy link
Contributor

my understanding is that protocol v2 is needed for fetching arbitrary shas.

I don’t think this is true.

$ docker run -h test --rm -ti ubuntu:16.04 bash
root@test:/# apt update -qq && apt install -y git &> /dev/null
All packages are up to date.
root@test:/# mkdir bazel && cd bazel && git init
Initialized empty Git repository in /bazel/.git/
root@test:/bazel# git remote add origin https://github.com/bazelbuild/bazel.git
root@test:/bazel# git fetch origin 4a27ebbd48b82a3768476cd70fe6925510bde52f
remote: Enumerating objects: 64, done.
remote: Counting objects: 100% (64/64), done.
remote: Compressing objects: 100% (47/47), done.
remote: Total 507977 (delta 13), reused 36 (delta 9), pack-reused 507913
Receiving objects: 100% (507977/507977), 706.54 MiB | 38.69 MiB/s, done.
Resolving deltas: 100% (316795/316795), done.
From https://github.com/bazelbuild/bazel
 * branch            4a27ebbd48b82a3768476cd70fe6925510bde52f -> FETCH_HEAD
root@test:/bazel# git --version
git version 2.7.4

@michaeleisel
Copy link
Contributor Author

It's needed for GHE on macOS at least, up until a very recent version (also note that fetching an individual sha can succeed if it just happens to be tied to a branch or something)

@philwo
Copy link
Member

philwo commented Oct 21, 2020

Sorry, I didn't have time to look into this again yet. I'm still confused why Git is not smart enough to negotiate the correct protocol automatically :(

perhaps we could run this command twice, once with protocol v2, and once without

Did we figure out whether that's a good idea?

@thii
Copy link
Member

thii commented Oct 21, 2020

@michaeleisel What kind of failing did you see? Have you seen this: #10292

@dfreese
Copy link

dfreese commented Jan 31, 2023

Wanted to check in on this, is Ubuntu 18.04 still considered a supported platform?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants