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
|
package commit
import (
"fmt"
"io"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"gitlab.com/gitlab-org/gitaly/v14/internal/git"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v14/streamio"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (s *server) RawBlame(in *gitalypb.RawBlameRequest, stream gitalypb.CommitService_RawBlameServer) error {
if err := validateRawBlameRequest(in); err != nil {
return status.Errorf(codes.InvalidArgument, "RawBlame: %v", err)
}
ctx := stream.Context()
revision := string(in.GetRevision())
path := string(in.GetPath())
cmd, err := s.gitCmdFactory.New(ctx, in.Repository, git.SubCmd{
Name: "blame",
Flags: []git.Option{git.Flag{Name: "-p"}},
Args: []string{revision},
PostSepArgs: []string{path},
})
if err != nil {
if _, ok := status.FromError(err); ok {
return err
}
return status.Errorf(codes.Internal, "RawBlame: cmd: %v", err)
}
sw := streamio.NewWriter(func(p []byte) error {
return stream.Send(&gitalypb.RawBlameResponse{Data: p})
})
_, err = io.Copy(sw, cmd)
if err != nil {
return status.Errorf(codes.Unavailable, "RawBlame: send: %v", err)
}
if err := cmd.Wait(); err != nil {
ctxlogrus.Extract(ctx).WithError(err).Info("ignoring git-blame error")
}
return nil
}
func validateRawBlameRequest(in *gitalypb.RawBlameRequest) error {
if err := git.ValidateRevision(in.Revision); err != nil {
return err
}
if len(in.GetPath()) == 0 {
return fmt.Errorf("empty Path")
}
return nil
}
|