Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2023-09-18 11:36:35 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2023-09-19 09:50:09 +0300
commit2aae84c1a6831e5d5440b954d4fee40dd7c1e4fd (patch)
tree2facdf2bab5ce50b5d01d9caa73b2c3bf2422550
parente9e8d0e303a470cfba89cfa103fb0779299f0726 (diff)
service: Simplify injection of dependencies for Remote server
While we already have a `service.Dependencies` type around for quite a long time, we still pass in dependencies explicitly when constructing the actual server. This makes it harder than necessary to make a server require more dependencies as you will have to adjust all callsites where the server is currently getting constructed. Simplify the code to instead inject the `service.Dependencies` type into the server directly. This will allow us to propagate dependencies more readily in the future.
-rw-r--r--internal/gitaly/service/remote/server.go19
-rw-r--r--internal/gitaly/service/remote/testhelper_test.go8
-rw-r--r--internal/gitaly/service/remote/update_remote_mirror_test.go12
-rw-r--r--internal/gitaly/service/repository/testhelper_test.go8
-rw-r--r--internal/gitaly/service/setup/register.go8
5 files changed, 14 insertions, 41 deletions
diff --git a/internal/gitaly/service/remote/server.go b/internal/gitaly/service/remote/server.go
index 1eb3dcf5d..ba2552537 100644
--- a/internal/gitaly/service/remote/server.go
+++ b/internal/gitaly/service/remote/server.go
@@ -4,6 +4,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v16/internal/git"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/localrepo"
+ "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v16/internal/grpc/client"
@@ -21,19 +22,13 @@ type server struct {
}
// NewServer creates a new instance of a grpc RemoteServiceServer
-func NewServer(
- locator storage.Locator,
- gitCmdFactory git.CommandFactory,
- catfileCache catfile.Cache,
- txManager transaction.Manager,
- connsPool *client.Pool,
-) gitalypb.RemoteServiceServer {
+func NewServer(deps *service.Dependencies) gitalypb.RemoteServiceServer {
return &server{
- locator: locator,
- gitCmdFactory: gitCmdFactory,
- catfileCache: catfileCache,
- txManager: txManager,
- conns: connsPool,
+ locator: deps.GetLocator(),
+ gitCmdFactory: deps.GetGitCmdFactory(),
+ catfileCache: deps.GetCatfileCache(),
+ txManager: deps.GetTxManager(),
+ conns: deps.GetConnsPool(),
}
}
diff --git a/internal/gitaly/service/remote/testhelper_test.go b/internal/gitaly/service/remote/testhelper_test.go
index 24fef7021..75a1dc1dd 100644
--- a/internal/gitaly/service/remote/testhelper_test.go
+++ b/internal/gitaly/service/remote/testhelper_test.go
@@ -25,13 +25,7 @@ func setupRemoteService(t *testing.T, ctx context.Context, opts ...testserver.Gi
cfg := testcfg.Build(t)
addr := testserver.RunGitalyServer(t, cfg, func(srv *grpc.Server, deps *service.Dependencies) {
- gitalypb.RegisterRemoteServiceServer(srv, NewServer(
- deps.GetLocator(),
- deps.GetGitCmdFactory(),
- deps.GetCatfileCache(),
- deps.GetTxManager(),
- deps.GetConnsPool(),
- ))
+ gitalypb.RegisterRemoteServiceServer(srv, NewServer(deps))
gitalypb.RegisterRepositoryServiceServer(srv, repository.NewServer(deps))
}, opts...)
cfg.SocketPath = addr
diff --git a/internal/gitaly/service/remote/update_remote_mirror_test.go b/internal/gitaly/service/remote/update_remote_mirror_test.go
index 3f2c01cc5..d926a50c8 100644
--- a/internal/gitaly/service/remote/update_remote_mirror_test.go
+++ b/internal/gitaly/service/remote/update_remote_mirror_test.go
@@ -568,19 +568,15 @@ func TestUpdateRemoteMirror(t *testing.T) {
cfg := testcfg.Build(t)
addr := testserver.RunGitalyServer(t, cfg, func(srv *grpc.Server, deps *service.Dependencies) {
+ gitalypb.RegisterRepositoryServiceServer(srv, repositorysvc.NewServer(deps))
+
cmdFactory := deps.GetGitCmdFactory()
if tc.wrapCommandFactory != nil {
cmdFactory = tc.wrapCommandFactory(t, deps.GetGitCmdFactory())
}
+ deps.GitCmdFactory = cmdFactory
- gitalypb.RegisterRemoteServiceServer(srv, NewServer(
- deps.GetLocator(),
- cmdFactory,
- deps.GetCatfileCache(),
- deps.GetTxManager(),
- deps.GetConnsPool(),
- ))
- gitalypb.RegisterRepositoryServiceServer(srv, repositorysvc.NewServer(deps))
+ gitalypb.RegisterRemoteServiceServer(srv, NewServer(deps))
})
cfg.SocketPath = addr
diff --git a/internal/gitaly/service/repository/testhelper_test.go b/internal/gitaly/service/repository/testhelper_test.go
index fb9bb6356..420e42f16 100644
--- a/internal/gitaly/service/repository/testhelper_test.go
+++ b/internal/gitaly/service/repository/testhelper_test.go
@@ -64,13 +64,7 @@ func runRepositoryService(tb testing.TB, cfg config.Cfg, opts ...testserver.Gita
deps.GetPackObjectsCache(),
deps.GetPackObjectsLimiter(),
))
- gitalypb.RegisterRemoteServiceServer(srv, remote.NewServer(
- deps.GetLocator(),
- deps.GetGitCmdFactory(),
- deps.GetCatfileCache(),
- deps.GetTxManager(),
- deps.GetConnsPool(),
- ))
+ gitalypb.RegisterRemoteServiceServer(srv, remote.NewServer(deps))
gitalypb.RegisterSSHServiceServer(srv, ssh.NewServer(deps))
gitalypb.RegisterRefServiceServer(srv, ref.NewServer(deps))
gitalypb.RegisterCommitServiceServer(srv, commit.NewServer(deps))
diff --git a/internal/gitaly/service/setup/register.go b/internal/gitaly/service/setup/register.go
index 669e3c286..a1e3a8efb 100644
--- a/internal/gitaly/service/setup/register.go
+++ b/internal/gitaly/service/setup/register.go
@@ -67,13 +67,7 @@ func RegisterAll(srv *grpc.Server, deps *service.Dependencies) {
smarthttp.WithPackfileNegotiationMetrics(smarthttpPackfileNegotiationMetrics),
))
gitalypb.RegisterConflictsServiceServer(srv, conflicts.NewServer(deps))
- gitalypb.RegisterRemoteServiceServer(srv, remote.NewServer(
- deps.GetLocator(),
- deps.GetGitCmdFactory(),
- deps.GetCatfileCache(),
- deps.GetTxManager(),
- deps.GetConnsPool(),
- ))
+ gitalypb.RegisterRemoteServiceServer(srv, remote.NewServer(deps))
gitalypb.RegisterServerServiceServer(srv, server.NewServer(deps.GetGitCmdFactory(), deps.GetCfg().Storages))
gitalypb.RegisterObjectPoolServiceServer(srv, objectpool.NewServer(
deps.GetLocator(),