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 (
"context"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/log"
"gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
func (s *server) LastCommitForPath(ctx context.Context, in *gitalypb.LastCommitForPathRequest) (*gitalypb.LastCommitForPathResponse, error) {
if err := validateLastCommitForPathRequest(in); err != nil {
return nil, helper.ErrInvalidArgument(err)
}
resp, err := s.lastCommitForPath(ctx, in)
if err != nil {
return nil, helper.ErrInternal(err)
}
return resp, nil
}
func (s *server) lastCommitForPath(ctx context.Context, in *gitalypb.LastCommitForPathRequest) (*gitalypb.LastCommitForPathResponse, error) {
path := string(in.GetPath())
if len(path) == 0 || path == "/" {
path = "."
}
repo := s.localrepo(in.GetRepository())
c, err := s.catfileCache.BatchProcess(ctx, repo)
if err != nil {
return nil, err
}
options := in.GetGlobalOptions()
// Preserve backwards compatibility with legacy LiteralPathspec
// flag: These protobuf changes were not shipped in 13.1, so can be
// remove before 13.2.
if in.GetLiteralPathspec() {
if options == nil {
options = &gitalypb.GlobalOptions{}
}
options.LiteralPathspecs = true
}
commit, err := log.LastCommitForPath(ctx, s.gitCmdFactory, c, repo, git.Revision(in.GetRevision()), path, options)
if log.IsNotFound(err) {
return &gitalypb.LastCommitForPathResponse{}, nil
}
return &gitalypb.LastCommitForPathResponse{Commit: commit}, err
}
func validateLastCommitForPathRequest(in *gitalypb.LastCommitForPathRequest) error {
if err := git.ValidateRevision(in.Revision); err != nil {
return helper.ErrInvalidArgument(err)
}
return nil
}
|