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:
authorPavlo Strokov <pstrokov@gitlab.com>2020-09-12 09:15:06 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2020-09-15 16:08:09 +0300
commit90a0fe156f60e273fa0adc761b30acfbaaff5fe6 (patch)
treec42e2462053c1dbaf286af5e17295eca2a5d3f13
parent7de73fe9bdced68051087ea6f33dff61c4ed3573 (diff)
Introduce Locator abstraction to diff service
In order to break dependency on the shared global config.Config variable the Locator interface is injected into the service. Calls that eventually lead to global config.Config var were removed. Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/2699
-rw-r--r--changelogs/unreleased/ps-diff-uses-locator.yml5
-rw-r--r--internal/gitaly/service/diff/numstat.go7
-rw-r--r--internal/gitaly/service/diff/server.go5
-rw-r--r--internal/gitaly/service/diff/testhelper_test.go3
-rw-r--r--internal/gitaly/service/register.go2
5 files changed, 15 insertions, 7 deletions
diff --git a/changelogs/unreleased/ps-diff-uses-locator.yml b/changelogs/unreleased/ps-diff-uses-locator.yml
new file mode 100644
index 000000000..6758150d2
--- /dev/null
+++ b/changelogs/unreleased/ps-diff-uses-locator.yml
@@ -0,0 +1,5 @@
+---
+title: Introduce Locator abstraction to diff service
+merge_request: 2559
+author:
+type: changed
diff --git a/internal/gitaly/service/diff/numstat.go b/internal/gitaly/service/diff/numstat.go
index 5a7d66d5f..ec892a681 100644
--- a/internal/gitaly/service/diff/numstat.go
+++ b/internal/gitaly/service/diff/numstat.go
@@ -5,7 +5,6 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/diff"
- "gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@@ -16,7 +15,7 @@ var (
)
func (s *server) DiffStats(in *gitalypb.DiffStatsRequest, stream gitalypb.DiffService_DiffStatsServer) error {
- if err := validateDiffStatsRequestParams(in); err != nil {
+ if err := s.validateDiffStatsRequestParams(in); err != nil {
return err
}
@@ -83,9 +82,9 @@ func sendStats(batch []*gitalypb.DiffStats, stream gitalypb.DiffService_DiffStat
return nil
}
-func validateDiffStatsRequestParams(in *gitalypb.DiffStatsRequest) error {
+func (s *server) validateDiffStatsRequestParams(in *gitalypb.DiffStatsRequest) error {
repo := in.GetRepository()
- if _, err := helper.GetRepoPath(repo); err != nil {
+ if _, err := s.locator.GetRepoPath(repo); err != nil {
return err
}
diff --git a/internal/gitaly/service/diff/server.go b/internal/gitaly/service/diff/server.go
index 22520a33f..24e0e56bd 100644
--- a/internal/gitaly/service/diff/server.go
+++ b/internal/gitaly/service/diff/server.go
@@ -1,6 +1,7 @@
package diff
import (
+ "gitlab.com/gitlab-org/gitaly/internal/storage"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
@@ -8,12 +9,14 @@ const msgSizeThreshold = 5 * 1024
type server struct {
MsgSizeThreshold int
+ locator storage.Locator
gitalypb.UnimplementedDiffServiceServer
}
// NewServer creates a new instance of a gRPC DiffServer
-func NewServer() gitalypb.DiffServiceServer {
+func NewServer(locator storage.Locator) gitalypb.DiffServiceServer {
return &server{
MsgSizeThreshold: msgSizeThreshold,
+ locator: locator,
}
}
diff --git a/internal/gitaly/service/diff/testhelper_test.go b/internal/gitaly/service/diff/testhelper_test.go
index d3d32efd2..a701953f6 100644
--- a/internal/gitaly/service/diff/testhelper_test.go
+++ b/internal/gitaly/service/diff/testhelper_test.go
@@ -5,6 +5,7 @@ import (
"os"
"testing"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc"
@@ -31,7 +32,7 @@ func runDiffServer(t *testing.T) (*grpc.Server, string) {
t.Fatal(err)
}
- gitalypb.RegisterDiffServiceServer(server, NewServer())
+ gitalypb.RegisterDiffServiceServer(server, NewServer(config.NewLocator(config.Config)))
reflection.Register(server)
go server.Serve(listener)
diff --git a/internal/gitaly/service/register.go b/internal/gitaly/service/register.go
index d0efe3166..c4642a738 100644
--- a/internal/gitaly/service/register.go
+++ b/internal/gitaly/service/register.go
@@ -71,7 +71,7 @@ func RegisterAll(grpcServer *grpc.Server, cfg config.Cfg, rubyServer *rubyserver
gitalypb.RegisterBlobServiceServer(grpcServer, blob.NewServer(rubyServer))
gitalypb.RegisterCleanupServiceServer(grpcServer, cleanup.NewServer())
gitalypb.RegisterCommitServiceServer(grpcServer, commit.NewServer(locator))
- gitalypb.RegisterDiffServiceServer(grpcServer, diff.NewServer())
+ gitalypb.RegisterDiffServiceServer(grpcServer, diff.NewServer(locator))
gitalypb.RegisterNamespaceServiceServer(grpcServer, namespace.NewServer())
gitalypb.RegisterOperationServiceServer(grpcServer, operations.NewServer(rubyServer))
gitalypb.RegisterRefServiceServer(grpcServer, ref.NewServer())