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:46:14 +0300
commit928f1c937afb39eb7ae3c2dfad7e9fdd41e0d25c (patch)
treed85e7f4e882bb9b8864ddf3a2f095d5d7c4e0c58
parentda6de8e528c56be822231ced0832d331afd2218b (diff)
service: Simplify injection of dependencies for Ref 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/git/remoterepo/testhelper_test.go7
-rw-r--r--internal/gitaly/service/operations/testhelper_test.go7
-rw-r--r--internal/gitaly/service/ref/delete_refs_test.go7
-rw-r--r--internal/gitaly/service/ref/server.go16
-rw-r--r--internal/gitaly/service/ref/testhelper_test.go7
-rw-r--r--internal/gitaly/service/repository/testhelper_test.go7
-rw-r--r--internal/gitaly/service/setup/register.go7
-rw-r--r--internal/grpc/middleware/customfieldshandler/customfields_handler_test.go13
8 files changed, 19 insertions, 52 deletions
diff --git a/internal/git/remoterepo/testhelper_test.go b/internal/git/remoterepo/testhelper_test.go
index 1b7b24871..400e0d279 100644
--- a/internal/git/remoterepo/testhelper_test.go
+++ b/internal/git/remoterepo/testhelper_test.go
@@ -36,12 +36,7 @@ func setupGitalyServer(t *testing.T) config.Cfg {
deps.GetRepositoryCounter(),
))
gitalypb.RegisterCommitServiceServer(srv, commit.NewServer(deps))
- gitalypb.RegisterRefServiceServer(srv, ref.NewServer(
- deps.GetLocator(),
- deps.GetGitCmdFactory(),
- deps.GetTxManager(),
- deps.GetCatfileCache(),
- ))
+ gitalypb.RegisterRefServiceServer(srv, ref.NewServer(deps))
})
return cfg
diff --git a/internal/gitaly/service/operations/testhelper_test.go b/internal/gitaly/service/operations/testhelper_test.go
index eed9012c9..8510ddfdf 100644
--- a/internal/gitaly/service/operations/testhelper_test.go
+++ b/internal/gitaly/service/operations/testhelper_test.go
@@ -99,12 +99,7 @@ func runOperationServiceServer(tb testing.TB, cfg config.Cfg, options ...testser
deps.GetBackupLocator(),
deps.GetRepositoryCounter(),
))
- gitalypb.RegisterRefServiceServer(srv, ref.NewServer(
- deps.GetLocator(),
- deps.GetGitCmdFactory(),
- deps.GetTxManager(),
- deps.GetCatfileCache(),
- ))
+ gitalypb.RegisterRefServiceServer(srv, ref.NewServer(deps))
gitalypb.RegisterCommitServiceServer(srv, commit.NewServer(deps))
gitalypb.RegisterSSHServiceServer(srv, ssh.NewServer(
deps.GetLocator(),
diff --git a/internal/gitaly/service/ref/delete_refs_test.go b/internal/gitaly/service/ref/delete_refs_test.go
index 61fbcae3c..cc4aed5ab 100644
--- a/internal/gitaly/service/ref/delete_refs_test.go
+++ b/internal/gitaly/service/ref/delete_refs_test.go
@@ -105,12 +105,7 @@ func TestDeleteRefs_transaction(t *testing.T) {
txManager := transaction.NewTrackingManager()
addr := testserver.RunGitalyServer(t, cfg, func(srv *grpc.Server, deps *service.Dependencies) {
- gitalypb.RegisterRefServiceServer(srv, NewServer(
- deps.GetLocator(),
- deps.GetGitCmdFactory(),
- deps.GetTxManager(),
- deps.GetCatfileCache(),
- ))
+ gitalypb.RegisterRefServiceServer(srv, NewServer(deps))
gitalypb.RegisterRepositoryServiceServer(srv, repository.NewServer(
deps.GetCfg(),
deps.GetLocator(),
diff --git a/internal/gitaly/service/ref/server.go b/internal/gitaly/service/ref/server.go
index 552ddfefb..e20d2cd62 100644
--- a/internal/gitaly/service/ref/server.go
+++ b/internal/gitaly/service/ref/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/proto/go/gitalypb"
@@ -18,17 +19,12 @@ type server struct {
}
// NewServer creates a new instance of a grpc RefServer
-func NewServer(
- locator storage.Locator,
- gitCmdFactory git.CommandFactory,
- txManager transaction.Manager,
- catfileCache catfile.Cache,
-) gitalypb.RefServiceServer {
+func NewServer(deps *service.Dependencies) gitalypb.RefServiceServer {
return &server{
- txManager: txManager,
- locator: locator,
- gitCmdFactory: gitCmdFactory,
- catfileCache: catfileCache,
+ txManager: deps.GetTxManager(),
+ locator: deps.GetLocator(),
+ gitCmdFactory: deps.GetGitCmdFactory(),
+ catfileCache: deps.GetCatfileCache(),
}
}
diff --git a/internal/gitaly/service/ref/testhelper_test.go b/internal/gitaly/service/ref/testhelper_test.go
index a80dc7dcf..67c4cc226 100644
--- a/internal/gitaly/service/ref/testhelper_test.go
+++ b/internal/gitaly/service/ref/testhelper_test.go
@@ -46,12 +46,7 @@ func setupRefService(tb testing.TB) (config.Cfg, gitalypb.RefServiceClient) {
func runRefServiceServer(tb testing.TB, cfg config.Cfg) string {
return testserver.RunGitalyServer(tb, cfg, func(srv *grpc.Server, deps *service.Dependencies) {
- gitalypb.RegisterRefServiceServer(srv, NewServer(
- deps.GetLocator(),
- deps.GetGitCmdFactory(),
- deps.GetTxManager(),
- deps.GetCatfileCache(),
- ))
+ gitalypb.RegisterRefServiceServer(srv, NewServer(deps))
gitalypb.RegisterHookServiceServer(srv, hookservice.NewServer(
deps.GetHookManager(),
deps.GetLocator(),
diff --git a/internal/gitaly/service/repository/testhelper_test.go b/internal/gitaly/service/repository/testhelper_test.go
index 635bcb8d1..9f4eb2067 100644
--- a/internal/gitaly/service/repository/testhelper_test.go
+++ b/internal/gitaly/service/repository/testhelper_test.go
@@ -87,12 +87,7 @@ func runRepositoryService(tb testing.TB, cfg config.Cfg, opts ...testserver.Gita
deps.GetGitCmdFactory(),
deps.GetTxManager(),
))
- gitalypb.RegisterRefServiceServer(srv, ref.NewServer(
- deps.GetLocator(),
- deps.GetGitCmdFactory(),
- deps.GetTxManager(),
- deps.GetCatfileCache(),
- ))
+ gitalypb.RegisterRefServiceServer(srv, ref.NewServer(deps))
gitalypb.RegisterCommitServiceServer(srv, commit.NewServer(deps))
gitalypb.RegisterObjectPoolServiceServer(srv, objectpool.NewServer(
deps.GetLocator(),
diff --git a/internal/gitaly/service/setup/register.go b/internal/gitaly/service/setup/register.go
index 691d2a39d..b8bb74be2 100644
--- a/internal/gitaly/service/setup/register.go
+++ b/internal/gitaly/service/setup/register.go
@@ -58,12 +58,7 @@ func RegisterAll(srv *grpc.Server, deps *service.Dependencies) {
gitalypb.RegisterDiffServiceServer(srv, diff.NewServer(deps))
gitalypb.RegisterNamespaceServiceServer(srv, namespace.NewServer(deps))
gitalypb.RegisterOperationServiceServer(srv, operations.NewServer(deps))
- gitalypb.RegisterRefServiceServer(srv, ref.NewServer(
- deps.GetLocator(),
- deps.GetGitCmdFactory(),
- deps.GetTxManager(),
- deps.GetCatfileCache(),
- ))
+ gitalypb.RegisterRefServiceServer(srv, ref.NewServer(deps))
gitalypb.RegisterRepositoryServiceServer(srv, repository.NewServer(
deps.GetCfg(),
deps.GetLocator(),
diff --git a/internal/grpc/middleware/customfieldshandler/customfields_handler_test.go b/internal/grpc/middleware/customfieldshandler/customfields_handler_test.go
index c7c2c88c2..15895b7ba 100644
--- a/internal/grpc/middleware/customfieldshandler/customfields_handler_test.go
+++ b/internal/grpc/middleware/customfieldshandler/customfields_handler_test.go
@@ -11,6 +11,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v16/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/service/ref"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v16/internal/grpc/backchannel"
@@ -49,12 +50,12 @@ func createNewServer(t *testing.T, cfg config.Cfg, logger log.Logger) *grpc.Serv
catfileCache := catfile.NewCache(cfg)
t.Cleanup(catfileCache.Stop)
- gitalypb.RegisterRefServiceServer(server, ref.NewServer(
- config.NewLocator(cfg),
- gitCommandFactory,
- transaction.NewManager(cfg, backchannel.NewRegistry()),
- catfileCache,
- ))
+ gitalypb.RegisterRefServiceServer(server, ref.NewServer(&service.Dependencies{
+ StorageLocator: config.NewLocator(cfg),
+ GitCmdFactory: gitCommandFactory,
+ TransactionManager: transaction.NewManager(cfg, backchannel.NewRegistry()),
+ CatfileCache: catfileCache,
+ }))
return server
}