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:45:40 +0300
commitda6de8e528c56be822231ced0832d331afd2218b (patch)
treef811a68336e29403467f667984eb9b32055bf478
parent04d42dd6e30f0a1638445df9a3f2eb85e75171ee (diff)
service: Simplify injection of dependencies for Operations 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/operations/server.go28
-rw-r--r--internal/gitaly/service/operations/testhelper_test.go13
-rw-r--r--internal/gitaly/service/operations/user_create_branch_test.go11
-rw-r--r--internal/gitaly/service/operations/user_delete_branch_test.go11
-rw-r--r--internal/gitaly/service/setup/register.go11
5 files changed, 14 insertions, 60 deletions
diff --git a/internal/gitaly/service/operations/server.go b/internal/gitaly/service/operations/server.go
index a3e09a5a7..e926b9b45 100644
--- a/internal/gitaly/service/operations/server.go
+++ b/internal/gitaly/service/operations/server.go
@@ -9,6 +9,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v16/internal/git/quarantine"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/hook"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/hook/updateref"
+ "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"
@@ -30,25 +31,16 @@ type Server struct {
}
// NewServer creates a new instance of a grpc OperationServiceServer
-func NewServer(
- hookManager hook.Manager,
- txManager transaction.Manager,
- locator storage.Locator,
- conns *client.Pool,
- gitCmdFactory git.CommandFactory,
- catfileCache catfile.Cache,
- updater *updateref.UpdaterWithHooks,
- signingKey string,
-) *Server {
+func NewServer(deps *service.Dependencies) *Server {
return &Server{
- hookManager: hookManager,
- txManager: txManager,
- locator: locator,
- conns: conns,
- gitCmdFactory: gitCmdFactory,
- catfileCache: catfileCache,
- updater: updater,
- signingKey: signingKey,
+ hookManager: deps.GetHookManager(),
+ txManager: deps.GetTxManager(),
+ locator: deps.GetLocator(),
+ conns: deps.GetConnsPool(),
+ gitCmdFactory: deps.GetGitCmdFactory(),
+ catfileCache: deps.GetCatfileCache(),
+ updater: deps.GetUpdaterWithHooks(),
+ signingKey: deps.GetCfg().Git.SigningKey,
}
}
diff --git a/internal/gitaly/service/operations/testhelper_test.go b/internal/gitaly/service/operations/testhelper_test.go
index ae44ec3ff..eed9012c9 100644
--- a/internal/gitaly/service/operations/testhelper_test.go
+++ b/internal/gitaly/service/operations/testhelper_test.go
@@ -79,18 +79,7 @@ func runOperationServiceServer(tb testing.TB, cfg config.Cfg, options ...testser
tb.Helper()
return testserver.RunGitalyServer(tb, cfg, func(srv *grpc.Server, deps *service.Dependencies) {
- operationServer := NewServer(
- deps.GetHookManager(),
- deps.GetTxManager(),
- deps.GetLocator(),
- deps.GetConnsPool(),
- deps.GetGitCmdFactory(),
- deps.GetCatfileCache(),
- deps.GetUpdaterWithHooks(),
- deps.GetCfg().Git.SigningKey,
- )
-
- gitalypb.RegisterOperationServiceServer(srv, operationServer)
+ gitalypb.RegisterOperationServiceServer(srv, NewServer(deps))
gitalypb.RegisterHookServiceServer(srv, hook.NewServer(
deps.GetHookManager(),
deps.GetLocator(),
diff --git a/internal/gitaly/service/operations/user_create_branch_test.go b/internal/gitaly/service/operations/user_create_branch_test.go
index c6e8aa854..c7feddde0 100644
--- a/internal/gitaly/service/operations/user_create_branch_test.go
+++ b/internal/gitaly/service/operations/user_create_branch_test.go
@@ -123,16 +123,7 @@ func TestUserCreateBranch_transactions(t *testing.T) {
cfg.ListenAddr = "127.0.0.1:0" // runs gitaly on the TCP address
addr := testserver.RunGitalyServer(t, cfg, func(srv *grpc.Server, deps *service.Dependencies) {
- gitalypb.RegisterOperationServiceServer(srv, NewServer(
- deps.GetHookManager(),
- deps.GetTxManager(),
- deps.GetLocator(),
- deps.GetConnsPool(),
- deps.GetGitCmdFactory(),
- deps.GetCatfileCache(),
- deps.GetUpdaterWithHooks(),
- deps.GetCfg().Git.SigningKey,
- ))
+ gitalypb.RegisterOperationServiceServer(srv, NewServer(deps))
gitalypb.RegisterHookServiceServer(srv, hook.NewServer(
deps.GetHookManager(),
deps.GetLocator(),
diff --git a/internal/gitaly/service/operations/user_delete_branch_test.go b/internal/gitaly/service/operations/user_delete_branch_test.go
index e71780551..a34285953 100644
--- a/internal/gitaly/service/operations/user_delete_branch_test.go
+++ b/internal/gitaly/service/operations/user_delete_branch_test.go
@@ -446,16 +446,7 @@ func TestUserDeleteBranch_transaction(t *testing.T) {
transactionServer := &testTransactionServer{}
testserver.RunGitalyServer(t, cfg, func(srv *grpc.Server, deps *service.Dependencies) {
- gitalypb.RegisterOperationServiceServer(srv, NewServer(
- deps.GetHookManager(),
- deps.GetTxManager(),
- deps.GetLocator(),
- deps.GetConnsPool(),
- deps.GetGitCmdFactory(),
- deps.GetCatfileCache(),
- deps.GetUpdaterWithHooks(),
- deps.GetCfg().Git.SigningKey,
- ))
+ gitalypb.RegisterOperationServiceServer(srv, NewServer(deps))
})
ctx, err := txinfo.InjectTransaction(ctx, 1, "node", true)
diff --git a/internal/gitaly/service/setup/register.go b/internal/gitaly/service/setup/register.go
index f2830e113..691d2a39d 100644
--- a/internal/gitaly/service/setup/register.go
+++ b/internal/gitaly/service/setup/register.go
@@ -57,16 +57,7 @@ func RegisterAll(srv *grpc.Server, deps *service.Dependencies) {
gitalypb.RegisterCommitServiceServer(srv, commit.NewServer(deps))
gitalypb.RegisterDiffServiceServer(srv, diff.NewServer(deps))
gitalypb.RegisterNamespaceServiceServer(srv, namespace.NewServer(deps))
- gitalypb.RegisterOperationServiceServer(srv, operations.NewServer(
- deps.GetHookManager(),
- deps.GetTxManager(),
- deps.GetLocator(),
- deps.GetConnsPool(),
- deps.GetGitCmdFactory(),
- deps.GetCatfileCache(),
- deps.GetUpdaterWithHooks(),
- deps.GetCfg().Git.SigningKey,
- ))
+ gitalypb.RegisterOperationServiceServer(srv, operations.NewServer(deps))
gitalypb.RegisterRefServiceServer(srv, ref.NewServer(
deps.GetLocator(),
deps.GetGitCmdFactory(),