1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package client
import (
"context"
"io"
"gitlab.com/gitlab-org/gitaly/internal/stream"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/streamio"
"google.golang.org/grpc"
)
// ReceivePack proxies an SSH git-receive-pack (git push) session to Gitaly
func ReceivePack(ctx context.Context, conn *grpc.ClientConn, stdin io.Reader, stdout, stderr io.Writer, req *gitalypb.SSHReceivePackRequest) (int32, error) {
ctx2, cancel := context.WithCancel(ctx)
defer cancel()
ssh := gitalypb.NewSSHServiceClient(conn)
receivePackStream, err := ssh.SSHReceivePack(ctx2)
if err != nil {
return 0, err
}
if err = receivePackStream.Send(req); err != nil {
return 0, err
}
inWriter := streamio.NewWriter(func(p []byte) error {
return receivePackStream.Send(&gitalypb.SSHReceivePackRequest{Stdin: p})
})
return stream.Handler(func() (stream.StdoutStderrResponse, error) {
return receivePackStream.Recv()
}, func(errC chan error) {
_, errRecv := io.Copy(inWriter, stdin)
receivePackStream.CloseSend()
errC <- errRecv
}, stdout, stderr)
}
|