diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-09-18 11:36:35 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-09-19 09:49:36 +0300 |
commit | e9e8d0e303a470cfba89cfa103fb0779299f0726 (patch) | |
tree | 9420a33629a8f4d825e1d00e2fa51e3227726771 | |
parent | aa8dfbd189afbde91dccbd779bf367c7cf50fc05 (diff) |
service: Simplify injection of dependencies for Conflicts 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/conflicts/server.go | 22 | ||||
-rw-r--r-- | internal/gitaly/service/conflicts/testhelper_test.go | 9 | ||||
-rw-r--r-- | internal/gitaly/service/setup/register.go | 9 |
3 files changed, 10 insertions, 30 deletions
diff --git a/internal/gitaly/service/conflicts/server.go b/internal/gitaly/service/conflicts/server.go index 4490bf97a..1dfbdbf3f 100644 --- a/internal/gitaly/service/conflicts/server.go +++ b/internal/gitaly/service/conflicts/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/grpc/client" "gitlab.com/gitlab-org/gitaly/v16/internal/structerr" @@ -26,21 +27,14 @@ type server struct { } // NewServer creates a new instance of a grpc ConflictsServer -func NewServer( - hookManager hook.Manager, - locator storage.Locator, - gitCmdFactory git.CommandFactory, - catfileCache catfile.Cache, - connsPool *client.Pool, - updater *updateref.UpdaterWithHooks, -) gitalypb.ConflictsServiceServer { +func NewServer(deps *service.Dependencies) gitalypb.ConflictsServiceServer { return &server{ - hookManager: hookManager, - locator: locator, - gitCmdFactory: gitCmdFactory, - catfileCache: catfileCache, - pool: connsPool, - updater: updater, + hookManager: deps.GetHookManager(), + locator: deps.GetLocator(), + gitCmdFactory: deps.GetGitCmdFactory(), + catfileCache: deps.GetCatfileCache(), + pool: deps.GetConnsPool(), + updater: deps.GetUpdaterWithHooks(), } } diff --git a/internal/gitaly/service/conflicts/testhelper_test.go b/internal/gitaly/service/conflicts/testhelper_test.go index 5dbda1816..ae8d5e1df 100644 --- a/internal/gitaly/service/conflicts/testhelper_test.go +++ b/internal/gitaly/service/conflicts/testhelper_test.go @@ -36,14 +36,7 @@ func setupConflictsService(tb testing.TB, hookManager hook.Manager) (config.Cfg, func runConflictsServer(tb testing.TB, cfg config.Cfg, hookManager hook.Manager) string { return testserver.RunGitalyServer(tb, cfg, func(srv *grpc.Server, deps *service.Dependencies) { - gitalypb.RegisterConflictsServiceServer(srv, NewServer( - deps.GetHookManager(), - deps.GetLocator(), - deps.GetGitCmdFactory(), - deps.GetCatfileCache(), - deps.GetConnsPool(), - deps.GetUpdaterWithHooks(), - )) + gitalypb.RegisterConflictsServiceServer(srv, NewServer(deps)) gitalypb.RegisterRepositoryServiceServer(srv, repository.NewServer(deps)) gitalypb.RegisterSSHServiceServer(srv, ssh.NewServer(deps)) gitalypb.RegisterHookServiceServer(srv, hookservice.NewServer( diff --git a/internal/gitaly/service/setup/register.go b/internal/gitaly/service/setup/register.go index 9bb678bf7..669e3c286 100644 --- a/internal/gitaly/service/setup/register.go +++ b/internal/gitaly/service/setup/register.go @@ -66,14 +66,7 @@ func RegisterAll(srv *grpc.Server, deps *service.Dependencies) { gitalypb.RegisterSmartHTTPServiceServer(srv, smarthttp.NewServer(deps, smarthttp.WithPackfileNegotiationMetrics(smarthttpPackfileNegotiationMetrics), )) - gitalypb.RegisterConflictsServiceServer(srv, conflicts.NewServer( - deps.GetHookManager(), - deps.GetLocator(), - deps.GetGitCmdFactory(), - deps.GetCatfileCache(), - deps.GetConnsPool(), - deps.GetUpdaterWithHooks(), - )) + gitalypb.RegisterConflictsServiceServer(srv, conflicts.NewServer(deps)) gitalypb.RegisterRemoteServiceServer(srv, remote.NewServer( deps.GetLocator(), deps.GetGitCmdFactory(), |