diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-02-01 12:12:29 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-02-01 12:37:41 +0300 |
commit | 8bbe0b868fce6585797c2142e619f900b63188e3 (patch) | |
tree | 4fd95e8c027d2c8d15808ce6c69095547c4df0d1 | |
parent | 5221277991fd23c87cf1cfad1e7f282d2beb00d5 (diff) |
localrepo: Use protocol v2 for internal fetches
When spawning git-upload-pack(1) we need to splice through GIT_PROTOCOL
such that we can tell which Git protocol shall be used. Right now, we
support both protocol v0, which is the default protocol, and protocol
v2, which is a newer iteration of this protocol. Wherever possible we
want to use v2, which provides some benefits for us like being able to
skip the initial reference advertisement phase in case we're only
fetching a subset of references.
While we have the setup in place to pass through the protocol version
for the SSH-based transport, we do not currently use it when doing
internal fetches. As a result, we fall back to v0 of the protocol and
thus miss out on any potentially new features.
Fix this by requesting protocol v2 for internal fetches.
Changelog: performance
-rw-r--r-- | internal/git/localrepo/remote.go | 1 | ||||
-rw-r--r-- | internal/git/localrepo/remote_extra_test.go | 8 |
2 files changed, 4 insertions, 5 deletions
diff --git a/internal/git/localrepo/remote.go b/internal/git/localrepo/remote.go index 1ef7617a9..69ffb29d8 100644 --- a/internal/git/localrepo/remote.go +++ b/internal/git/localrepo/remote.go @@ -129,6 +129,7 @@ func (repo *Repo) FetchInternal( git.WithInternalFetch(&gitalypb.SSHUploadPackRequest{ Repository: remoteRepo, GitConfigOptions: []string{"uploadpack.allowAnySHA1InWant=true"}, + GitProtocol: git.ProtocolV2, }), git.WithEnv(opts.Env...), git.WithStderr(opts.Stderr), diff --git a/internal/git/localrepo/remote_extra_test.go b/internal/git/localrepo/remote_extra_test.go index 265bc6520..1b473c06e 100644 --- a/internal/git/localrepo/remote_extra_test.go +++ b/internal/git/localrepo/remote_extra_test.go @@ -81,10 +81,8 @@ func TestRepo_FetchInternal(t *testing.T) { require.NoFileExists(t, filepath.Join(repoPath, "objects/info/commit-graph")) require.NoDirExists(t, filepath.Join(repoPath, "objects/info/commit-graphs")) - // Assert that we're using the expected Git protocol version. This is currently - // broken: we use the default Git protocol version, whereas we really want to use - // protocol v2. - require.Empty(t, readGitProtocol()) + // Assert that we're using the expected Git protocol version, which is protocol v2. + require.Equal(t, "GIT_PROTOCOL=version=2\n", readGitProtocol()) }) t.Run("refspec without tags", func(t *testing.T) { @@ -136,7 +134,7 @@ func TestRepo_FetchInternal(t *testing.T) { ) require.EqualError(t, err, "exit status 128") require.IsType(t, err, localrepo.ErrFetchFailed{}) - require.Contains(t, stderr.String(), "fatal: couldn't find remote ref refs/does/not/exist\nfatal: the remote end hung up unexpectedly\n") + require.Equal(t, stderr.String(), "fatal: couldn't find remote ref refs/does/not/exist\n") }) t.Run("with env", func(t *testing.T) { |