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
|
package repository
import (
"context"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/repository"
"gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
const (
CommitGraphRelPath = "objects/info/commit-graph"
CommitGraphsRelPath = "objects/info/commit-graphs"
CommitGraphChainRelPath = CommitGraphsRelPath + "/commit-graph-chain"
)
// WriteCommitGraph write or update commit-graph file in a repository
func (s *server) WriteCommitGraph(
ctx context.Context,
in *gitalypb.WriteCommitGraphRequest,
) (*gitalypb.WriteCommitGraphResponse, error) {
if err := s.writeCommitGraph(ctx, in.GetRepository(), in.GetSplitStrategy()); err != nil {
return nil, err
}
return &gitalypb.WriteCommitGraphResponse{}, nil
}
func (s *server) writeCommitGraph(
ctx context.Context,
repo repository.GitRepo,
splitStrategy gitalypb.WriteCommitGraphRequest_SplitStrategy,
) error {
flags := []git.Option{
git.Flag{Name: "--reachable"},
}
switch splitStrategy {
case gitalypb.WriteCommitGraphRequest_SizeMultiple:
flags = append(flags,
git.Flag{Name: "--split"},
git.ValueFlag{Name: "--size-multiple", Value: "4"},
)
default:
return helper.ErrInvalidArgumentf("unsupported split strategy: %v", splitStrategy)
}
cmd, err := s.gitCmdFactory.New(ctx, repo,
git.SubSubCmd{
Name: "commit-graph",
Action: "write",
Flags: flags,
},
)
if err != nil {
return helper.ErrInternal(err)
}
if err := cmd.Wait(); err != nil {
return helper.ErrInternal(err)
}
return nil
}
|