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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
package smarthttp
import (
"context"
"fmt"
"io"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus"
log "github.com/sirupsen/logrus"
"gitlab.com/gitlab-org/gitaly-proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/pktline"
"gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/streamio"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (s *server) InfoRefsUploadPack(in *gitalypb.InfoRefsRequest, stream gitalypb.SmartHTTPService_InfoRefsUploadPackServer) error {
w := streamio.NewWriter(func(p []byte) error {
return stream.Send(&gitalypb.InfoRefsResponse{Data: p})
})
return handleInfoRefs(stream.Context(), "upload-pack", in, w)
}
func (s *server) InfoRefsReceivePack(in *gitalypb.InfoRefsRequest, stream gitalypb.SmartHTTPService_InfoRefsReceivePackServer) error {
w := streamio.NewWriter(func(p []byte) error {
return stream.Send(&gitalypb.InfoRefsResponse{Data: p})
})
return handleInfoRefs(stream.Context(), "receive-pack", in, w)
}
func handleInfoRefs(ctx context.Context, service string, req *gitalypb.InfoRefsRequest, w io.Writer) error {
grpc_logrus.Extract(ctx).WithFields(log.Fields{
"service": service,
}).Debug("handleInfoRefs")
env := git.AddGitProtocolEnv(ctx, req, []string{})
repoPath, err := helper.GetRepoPath(req.Repository)
if err != nil {
return err
}
args := []string{}
for _, params := range req.GitConfigOptions {
args = append(args, "-c", params)
}
args = append(args, service, "--stateless-rpc", "--advertise-refs", repoPath)
cmd, err := git.BareCommand(ctx, nil, nil, nil, env, args...)
if err != nil {
if _, ok := status.FromError(err); ok {
return err
}
return status.Errorf(codes.Internal, "GetInfoRefs: cmd: %v", err)
}
if _, err := pktline.WriteString(w, fmt.Sprintf("# service=git-%s\n", service)); err != nil {
return status.Errorf(codes.Internal, "GetInfoRefs: pktLine: %v", err)
}
if err := pktline.WriteFlush(w); err != nil {
return status.Errorf(codes.Internal, "GetInfoRefs: pktFlush: %v", err)
}
if _, err := io.Copy(w, cmd); err != nil {
return status.Errorf(codes.Internal, "GetInfoRefs: %v", err)
}
if err := cmd.Wait(); err != nil {
return status.Errorf(codes.Internal, "GetInfoRefs: %v", err)
}
return nil
}
|