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>2021-01-28 14:31:11 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2021-01-29 00:25:29 +0300
commit2659b1869af144ef2bb7f5ed0f6572dc3173ecca (patch)
tree59e670482900b8af750a40265138a0b6ca4bccbf
parent5f97b81d07b8c64a7fa51d6f025ad39a64ee5eba (diff)
Replacement of the git.NewCommandWithoutRepo in ssh package
Replacement of the git.NewCommandWithoutRepo with the git.CommandFactory.NewWithoutRepo call. Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/2699
-rw-r--r--internal/gitaly/service/operations/testhelper_test.go7
-rw-r--r--internal/gitaly/service/register.go1
-rw-r--r--internal/gitaly/service/remote/fetch_internal_remote_test.go4
-rw-r--r--internal/gitaly/service/ssh/monitor_stdin_command.go4
-rw-r--r--internal/gitaly/service/ssh/receive_pack.go2
-rw-r--r--internal/gitaly/service/ssh/server.go5
-rw-r--r--internal/gitaly/service/ssh/testhelper_test.go4
-rw-r--r--internal/gitaly/service/ssh/upload_archive.go2
-rw-r--r--internal/gitaly/service/ssh/upload_pack.go2
-rw-r--r--internal/praefect/replicator_test.go2
10 files changed, 21 insertions, 12 deletions
diff --git a/internal/gitaly/service/operations/testhelper_test.go b/internal/gitaly/service/operations/testhelper_test.go
index 8740932d4..d8af4082c 100644
--- a/internal/gitaly/service/operations/testhelper_test.go
+++ b/internal/gitaly/service/operations/testhelper_test.go
@@ -83,14 +83,15 @@ func runOperationServiceServerWithRubyServer(t *testing.T, ruby *rubyserver.Serv
locator := config.NewLocator(config.Config)
hookManager := gitalyhook.NewManager(locator, gitalyhook.GitlabAPIStub, config.Config)
- server := NewServer(config.Config, ruby, hookManager, locator, conns, git.NewExecCommandFactory(config.Config))
+ gitCmdFactory := git.NewExecCommandFactory(config.Config)
+ server := NewServer(config.Config, ruby, hookManager, locator, conns, gitCmdFactory)
gitalypb.RegisterOperationServiceServer(srv.GrpcServer(), server)
gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hook.NewServer(config.Config, hookManager))
- gitalypb.RegisterRepositoryServiceServer(srv.GrpcServer(), repository.NewServer(config.Config, ruby, locator, git.NewExecCommandFactory(config.Config)))
+ gitalypb.RegisterRepositoryServiceServer(srv.GrpcServer(), repository.NewServer(config.Config, ruby, locator, gitCmdFactory))
gitalypb.RegisterRefServiceServer(srv.GrpcServer(), ref.NewServer(config.Config, locator))
gitalypb.RegisterCommitServiceServer(srv.GrpcServer(), commit.NewServer(config.Config, locator))
- gitalypb.RegisterSSHServiceServer(srv.GrpcServer(), ssh.NewServer(config.Config, locator))
+ gitalypb.RegisterSSHServiceServer(srv.GrpcServer(), ssh.NewServer(config.Config, locator, gitCmdFactory))
reflection.Register(srv.GrpcServer())
srv.Start(t)
diff --git a/internal/gitaly/service/register.go b/internal/gitaly/service/register.go
index 318892d13..f84343233 100644
--- a/internal/gitaly/service/register.go
+++ b/internal/gitaly/service/register.go
@@ -81,6 +81,7 @@ func RegisterAll(grpcServer *grpc.Server, cfg config.Cfg, rubyServer *rubyserver
gitalypb.RegisterSSHServiceServer(grpcServer, ssh.NewServer(
cfg,
locator,
+ gitCmdFactory,
ssh.WithPackfileNegotiationMetrics(sshPackfileNegotiationMetrics),
))
gitalypb.RegisterSmartHTTPServiceServer(grpcServer, smarthttp.NewServer(
diff --git a/internal/gitaly/service/remote/fetch_internal_remote_test.go b/internal/gitaly/service/remote/fetch_internal_remote_test.go
index 3b4f8214a..38fae0edd 100644
--- a/internal/gitaly/service/remote/fetch_internal_remote_test.go
+++ b/internal/gitaly/service/remote/fetch_internal_remote_test.go
@@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/client"
+ "gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
serverPkg "gitlab.com/gitlab-org/gitaly/internal/gitaly/server"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service/ref"
@@ -47,8 +48,9 @@ func TestSuccessfulFetchInternalRemote(t *testing.T) {
}...)
locator := config.NewLocator(config.Config)
+ gitCmdFactory := git.NewExecCommandFactory(config.Config)
gitaly0Server := testhelper.NewServer(t, nil, nil, testhelper.WithStorages([]string{"gitaly-0"}))
- gitalypb.RegisterSSHServiceServer(gitaly0Server.GrpcServer(), ssh.NewServer(config.Config, locator))
+ gitalypb.RegisterSSHServiceServer(gitaly0Server.GrpcServer(), ssh.NewServer(config.Config, locator, gitCmdFactory))
gitalypb.RegisterRefServiceServer(gitaly0Server.GrpcServer(), ref.NewServer(config.Config, locator))
reflection.Register(gitaly0Server.GrpcServer())
gitaly0Server.Start(t)
diff --git a/internal/gitaly/service/ssh/monitor_stdin_command.go b/internal/gitaly/service/ssh/monitor_stdin_command.go
index f9fea54c0..252bac9ac 100644
--- a/internal/gitaly/service/ssh/monitor_stdin_command.go
+++ b/internal/gitaly/service/ssh/monitor_stdin_command.go
@@ -10,13 +10,13 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/git/pktline"
)
-func monitorStdinCommand(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, globals []git.GlobalOption, sc git.SubCmd, opts ...git.CmdOpt) (*command.Command, *pktline.ReadMonitor, error) {
+func monitorStdinCommand(ctx context.Context, gitCmdFactory git.CommandFactory, stdin io.Reader, stdout, stderr io.Writer, globals []git.GlobalOption, sc git.SubCmd, opts ...git.CmdOpt) (*command.Command, *pktline.ReadMonitor, error) {
stdinPipe, monitor, err := pktline.NewReadMonitor(ctx, stdin)
if err != nil {
return nil, nil, fmt.Errorf("create monitor: %v", err)
}
- cmd, err := git.NewCommandWithoutRepo(ctx, globals, sc, append([]git.CmdOpt{
+ cmd, err := gitCmdFactory.NewWithoutRepo(ctx, globals, sc, append([]git.CmdOpt{
git.WithStdin(stdinPipe), git.WithStdout(stdout), git.WithStderr(stderr),
}, opts...)...)
stdinPipe.Close() // this now belongs to cmd
diff --git a/internal/gitaly/service/ssh/receive_pack.go b/internal/gitaly/service/ssh/receive_pack.go
index 6ec60b04f..93b4d2f50 100644
--- a/internal/gitaly/service/ssh/receive_pack.go
+++ b/internal/gitaly/service/ssh/receive_pack.go
@@ -65,7 +65,7 @@ func (s *server) sshReceivePack(stream gitalypb.SSHService_SSHReceivePackServer,
globalOpts[i] = git.ValueFlag{"-c", o}
}
- cmd, err := git.NewCommandWithoutRepo(ctx, globalOpts,
+ cmd, err := s.gitCmdFactory.NewWithoutRepo(ctx, globalOpts,
git.SubCmd{
Name: "receive-pack",
Args: []string{repoPath},
diff --git a/internal/gitaly/service/ssh/server.go b/internal/gitaly/service/ssh/server.go
index 9cdbc2e1b..9e1cf3306 100644
--- a/internal/gitaly/service/ssh/server.go
+++ b/internal/gitaly/service/ssh/server.go
@@ -4,6 +4,7 @@ import (
"time"
"github.com/prometheus/client_golang/prometheus"
+ "gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/storage"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -17,16 +18,18 @@ var (
type server struct {
cfg config.Cfg
locator storage.Locator
+ gitCmdFactory git.CommandFactory
uploadPackRequestTimeout time.Duration
uploadArchiveRequestTimeout time.Duration
packfileNegotiationMetrics *prometheus.CounterVec
}
// NewServer creates a new instance of a grpc SSHServer
-func NewServer(cfg config.Cfg, locator storage.Locator, serverOpts ...ServerOpt) gitalypb.SSHServiceServer {
+func NewServer(cfg config.Cfg, locator storage.Locator, gitCmdFactory git.CommandFactory, serverOpts ...ServerOpt) gitalypb.SSHServiceServer {
s := &server{
cfg: cfg,
locator: locator,
+ gitCmdFactory: gitCmdFactory,
uploadPackRequestTimeout: defaultUploadPackRequestTimeout,
uploadArchiveRequestTimeout: defaultUploadArchiveRequestTimeout,
packfileNegotiationMetrics: prometheus.NewCounterVec(
diff --git a/internal/gitaly/service/ssh/testhelper_test.go b/internal/gitaly/service/ssh/testhelper_test.go
index ae7123c18..f08feae89 100644
--- a/internal/gitaly/service/ssh/testhelper_test.go
+++ b/internal/gitaly/service/ssh/testhelper_test.go
@@ -5,6 +5,7 @@ import (
"path/filepath"
"testing"
+ "gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/hook"
hookservice "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/hook"
@@ -42,7 +43,8 @@ func runSSHServer(t *testing.T, serverOpts ...ServerOpt) (string, func()) {
srv := testhelper.NewServer(t, nil, nil, testhelper.WithInternalSocket(config.Config))
locator := config.NewLocator(config.Config)
- gitalypb.RegisterSSHServiceServer(srv.GrpcServer(), NewServer(config.Config, locator, serverOpts...))
+ gitCmdFactory := git.NewExecCommandFactory(config.Config)
+ gitalypb.RegisterSSHServiceServer(srv.GrpcServer(), NewServer(config.Config, locator, gitCmdFactory, serverOpts...))
gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hookservice.NewServer(config.Config, hook.NewManager(locator, hook.GitlabAPIStub, config.Config)))
srv.Start(t)
diff --git a/internal/gitaly/service/ssh/upload_archive.go b/internal/gitaly/service/ssh/upload_archive.go
index 64e1da024..f074b290f 100644
--- a/internal/gitaly/service/ssh/upload_archive.go
+++ b/internal/gitaly/service/ssh/upload_archive.go
@@ -51,7 +51,7 @@ func (s *server) sshUploadArchive(stream gitalypb.SSHService_SSHUploadArchiveSer
return stream.Send(&gitalypb.SSHUploadArchiveResponse{Stderr: p})
})
- cmd, monitor, err := monitorStdinCommand(ctx, stdin, stdout, stderr, nil, git.SubCmd{
+ cmd, monitor, err := monitorStdinCommand(ctx, s.gitCmdFactory, stdin, stdout, stderr, nil, git.SubCmd{
Name: "upload-archive",
Args: []string{repoPath},
})
diff --git a/internal/gitaly/service/ssh/upload_pack.go b/internal/gitaly/service/ssh/upload_pack.go
index 76c5e50dc..f596459fb 100644
--- a/internal/gitaly/service/ssh/upload_pack.go
+++ b/internal/gitaly/service/ssh/upload_pack.go
@@ -103,7 +103,7 @@ func (s *server) sshUploadPack(stream gitalypb.SSHService_SSHUploadPackServer, r
stats.UpdateMetrics(s.packfileNegotiationMetrics)
}()
- cmd, monitor, err := monitorStdinCommand(ctx, stdin, stdout, stderr, globalOpts, git.SubCmd{
+ cmd, monitor, err := monitorStdinCommand(ctx, s.gitCmdFactory, stdin, stdout, stderr, globalOpts, git.SubCmd{
Name: "upload-pack",
Args: []string{repoPath},
}, git.WithGitProtocol(ctx, req))
diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go
index 6db17aa5d..39bcb96eb 100644
--- a/internal/praefect/replicator_test.go
+++ b/internal/praefect/replicator_test.go
@@ -1037,7 +1037,7 @@ func newReplicationService(tb testing.TB) (*grpc.Server, string) {
gitalypb.RegisterRepositoryServiceServer(svr, repository.NewServer(gitaly_config.Config, RubyServer, locator, gitCmdFactory))
gitalypb.RegisterObjectPoolServiceServer(svr, objectpoolservice.NewServer(gitaly_config.Config, locator, gitCmdFactory))
gitalypb.RegisterRemoteServiceServer(svr, remote.NewServer(gitaly_config.Config, RubyServer, locator, gitCmdFactory))
- gitalypb.RegisterSSHServiceServer(svr, ssh.NewServer(gitaly_config.Config, locator))
+ gitalypb.RegisterSSHServiceServer(svr, ssh.NewServer(gitaly_config.Config, locator, gitCmdFactory))
gitalypb.RegisterRefServiceServer(svr, ref.NewServer(gitaly_config.Config, locator))
healthpb.RegisterHealthServer(svr, health.NewServer())
reflection.Register(svr)