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
79
80
81
82
|
package commit
import (
"fmt"
"github.com/golang/protobuf/proto"
"gitlab.com/gitlab-org/gitaly/v14/internal/git"
"gitlab.com/gitlab-org/gitaly/v14/internal/helper"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
)
type commitsByMessageSender struct {
stream gitalypb.CommitService_CommitsByMessageServer
commits []*gitalypb.GitCommit
}
func (sender *commitsByMessageSender) Reset() { sender.commits = nil }
func (sender *commitsByMessageSender) Append(m proto.Message) {
sender.commits = append(sender.commits, m.(*gitalypb.GitCommit))
}
func (sender *commitsByMessageSender) Send() error {
return sender.stream.Send(&gitalypb.CommitsByMessageResponse{Commits: sender.commits})
}
func (s *server) CommitsByMessage(in *gitalypb.CommitsByMessageRequest, stream gitalypb.CommitService_CommitsByMessageServer) error {
if err := validateCommitsByMessageRequest(in); err != nil {
return helper.ErrInvalidArgument(err)
}
if err := s.commitsByMessage(in, stream); err != nil {
return helper.ErrInternal(err)
}
return nil
}
func (s *server) commitsByMessage(in *gitalypb.CommitsByMessageRequest, stream gitalypb.CommitService_CommitsByMessageServer) error {
ctx := stream.Context()
sender := &commitsByMessageSender{stream: stream}
repo := s.localrepo(in.GetRepository())
gitLogExtraOptions := []git.Option{
git.Flag{Name: "--grep=" + in.GetQuery()},
git.Flag{Name: "--regexp-ignore-case"},
}
if offset := in.GetOffset(); offset > 0 {
gitLogExtraOptions = append(gitLogExtraOptions, git.Flag{Name: fmt.Sprintf("--skip=%d", offset)})
}
if limit := in.GetLimit(); limit > 0 {
gitLogExtraOptions = append(gitLogExtraOptions, git.Flag{Name: fmt.Sprintf("--max-count=%d", limit)})
}
revision := in.GetRevision()
if len(revision) == 0 {
var err error
revision, err = defaultBranchName(ctx, repo)
if err != nil {
return err
}
}
var paths []string
if path := in.GetPath(); len(path) > 0 {
paths = append(paths, string(path))
}
return s.sendCommits(stream.Context(), sender, repo, []string{string(revision)}, paths, in.GetGlobalOptions(), gitLogExtraOptions...)
}
func validateCommitsByMessageRequest(in *gitalypb.CommitsByMessageRequest) error {
if err := git.ValidateRevisionAllowEmpty(in.Revision); err != nil {
return err
}
if in.GetQuery() == "" {
return fmt.Errorf("empty Query")
}
return nil
}
|