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
|
package diff
import (
"context"
"io"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/structerr"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
)
func (s *server) RawDiff(in *gitalypb.RawDiffRequest, stream gitalypb.DiffService_RawDiffServer) error {
if err := validateRequest(in); err != nil {
return structerr.NewInvalidArgument("%w", err)
}
subCmd := git.Command{
Name: "diff",
Flags: []git.Option{git.Flag{Name: "--full-index"}},
Args: []string{in.LeftCommitId, in.RightCommitId},
}
sw := streamio.NewWriter(func(p []byte) error {
return stream.Send(&gitalypb.RawDiffResponse{Data: p})
})
return sendRawOutput(stream.Context(), s.gitCmdFactory, in.Repository, sw, subCmd)
}
func (s *server) RawPatch(in *gitalypb.RawPatchRequest, stream gitalypb.DiffService_RawPatchServer) error {
if err := validateRequest(in); err != nil {
return structerr.NewInvalidArgument("%w", err)
}
subCmd := git.Command{
Name: "format-patch",
Flags: []git.Option{git.Flag{Name: "--stdout"}, git.ValueFlag{Name: "--signature", Value: "GitLab"}},
Args: []string{in.LeftCommitId + ".." + in.RightCommitId},
}
sw := streamio.NewWriter(func(p []byte) error {
return stream.Send(&gitalypb.RawPatchResponse{Data: p})
})
return sendRawOutput(stream.Context(), s.gitCmdFactory, in.Repository, sw, subCmd)
}
func sendRawOutput(ctx context.Context, gitCmdFactory git.CommandFactory, repo *gitalypb.Repository, sender io.Writer, subCmd git.Command) error {
cmd, err := gitCmdFactory.New(ctx, repo, subCmd)
if err != nil {
return structerr.NewInternal("cmd: %w", err)
}
if _, err := io.Copy(sender, cmd); err != nil {
return structerr.NewUnavailable("send: %w", err)
}
return cmd.Wait()
}
|