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
|
package log
import (
"context"
"io/ioutil"
"strings"
"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/command"
"gitlab.com/gitlab-org/gitaly/internal/git"
)
// LastCommitForPath returns the last commit which modified path.
func LastCommitForPath(ctx context.Context, repo *gitalypb.Repository, revision string, path string) (*gitalypb.GitCommit, error) {
cmd, err := git.Command(ctx, repo, "log", "--format=%H", "--max-count=1", revision, "--", path)
if err != nil {
return nil, err
}
commitID, err := ioutil.ReadAll(cmd)
if err != nil {
return nil, err
}
return GetCommit(ctx, repo, strings.TrimSpace(string(commitID)))
}
// GitLogCommand returns a Command that executes git log with the given the arguments
func GitLogCommand(ctx context.Context, repo *gitalypb.Repository, revisions []string, paths []string, extraArgs ...string) (*command.Command, error) {
grpc_logrus.Extract(ctx).WithFields(log.Fields{
"Revisions": revisions,
}).Debug("GitLog")
formatFlag := "--pretty=%H"
args := []string{
"log",
formatFlag,
}
args = append(args, extraArgs...)
args = append(args, revisions...)
args = append(args, "--")
args = append(args, paths...)
cmd, err := git.Command(ctx, repo, args...)
if err != nil {
return nil, err
}
return cmd, nil
}
|