Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-02-04 10:53:59 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-02-04 11:26:57 +0300
commit4e03796a03e7f1b4c75ccdf2c80c6b9cdc62d863 (patch)
tree48e4a84e30ad6de19e1fa9523321c6b05494d0ec
parentdbd28b34d0e36d590db5b99e2e9c23cf5a8dca86 (diff)
git/stats: Convert LogObjectsInfo to accept a repo executor
`LogObjectsInfo()` accepts both a repository and Git command factory as input. Convert it to instead accept a `git.RepositoryExecutor` such that callers don't need to have a command factory around.
-rw-r--r--internal/git/stats/git.go5
-rw-r--r--internal/git/stats/git_test.go9
-rw-r--r--internal/gitaly/service/objectpool/fetch_into_object_pool.go2
-rw-r--r--internal/gitaly/service/repository/gc.go2
-rw-r--r--internal/gitaly/service/repository/midx.go2
-rw-r--r--internal/gitaly/service/repository/repack.go12
6 files changed, 16 insertions, 16 deletions
diff --git a/internal/git/stats/git.go b/internal/git/stats/git.go
index e96df7c1c..de5895579 100644
--- a/internal/git/stats/git.go
+++ b/internal/git/stats/git.go
@@ -9,15 +9,14 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"gitlab.com/gitlab-org/gitaly/v14/internal/git"
- "gitlab.com/gitlab-org/gitaly/v14/internal/git/repository"
)
// LogObjectsInfo read statistics of the git repo objects
// and logs it under 'count-objects' key as structured entry.
-func LogObjectsInfo(ctx context.Context, gitCmdFactory git.CommandFactory, repo repository.GitRepo) {
+func LogObjectsInfo(ctx context.Context, repo git.RepositoryExecutor) {
logger := ctxlogrus.Extract(ctx)
- cmd, err := gitCmdFactory.New(ctx, repo, git.SubCmd{
+ cmd, err := repo.Exec(ctx, git.SubCmd{
Name: "count-objects",
Flags: []git.Option{git.Flag{Name: "--verbose"}},
})
diff --git a/internal/git/stats/git_test.go b/internal/git/stats/git_test.go
index 7b15b60ae..4d64fe405 100644
--- a/internal/git/stats/git_test.go
+++ b/internal/git/stats/git_test.go
@@ -11,6 +11,7 @@ import (
"github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg"
@@ -24,8 +25,6 @@ func TestLogObjectInfo(t *testing.T) {
repo2, repoPath2 := gittest.CloneRepo(t, cfg, cfg.Storages[0])
ctx := testhelper.Context(t)
- gitCmdFactory := gittest.NewCommandFactory(t, cfg)
-
requireLog := func(entries []*logrus.Entry) map[string]interface{} {
for _, entry := range entries {
if entry.Message == "git repo statistic" {
@@ -62,10 +61,10 @@ func TestLogObjectInfo(t *testing.T) {
logger, hook := test.NewNullLogger()
testCtx := ctxlogrus.ToContext(ctx, logger.WithField("test", "logging"))
- LogObjectsInfo(testCtx, gitCmdFactory, &gitalypb.Repository{
+ LogObjectsInfo(testCtx, localrepo.NewTestRepo(t, cfg, &gitalypb.Repository{
StorageName: repo1.StorageName,
RelativePath: filepath.Join(strings.TrimPrefix(tmpDir, storagePath), ".git"),
- })
+ }))
countObjects := requireLog(hook.AllEntries())
require.ElementsMatch(t, []string{repoPath1 + "/objects", repoPath2 + "/objects"}, countObjects["alternate"])
@@ -75,7 +74,7 @@ func TestLogObjectInfo(t *testing.T) {
logger, hook := test.NewNullLogger()
testCtx := ctxlogrus.ToContext(ctx, logger.WithField("test", "logging"))
- LogObjectsInfo(testCtx, gitCmdFactory, repo2)
+ LogObjectsInfo(testCtx, localrepo.NewTestRepo(t, cfg, repo2))
countObjects := requireLog(hook.AllEntries())
require.Contains(t, countObjects, "prune-packable")
diff --git a/internal/gitaly/service/objectpool/fetch_into_object_pool.go b/internal/gitaly/service/objectpool/fetch_into_object_pool.go
index ea73c4673..ef8a7437f 100644
--- a/internal/gitaly/service/objectpool/fetch_into_object_pool.go
+++ b/internal/gitaly/service/objectpool/fetch_into_object_pool.go
@@ -25,7 +25,7 @@ func (s *server) FetchIntoObjectPool(ctx context.Context, req *gitalypb.FetchInt
return nil, helper.ErrInternal(err)
}
- stats.LogObjectsInfo(ctx, s.gitCmdFactory, req.ObjectPool.Repository)
+ stats.LogObjectsInfo(ctx, objectPool.Repo)
return &gitalypb.FetchIntoObjectPoolResponse{}, nil
}
diff --git a/internal/gitaly/service/repository/gc.go b/internal/gitaly/service/repository/gc.go
index 382088356..ba8a9d57f 100644
--- a/internal/gitaly/service/repository/gc.go
+++ b/internal/gitaly/service/repository/gc.go
@@ -50,7 +50,7 @@ func (s *server) GarbageCollect(ctx context.Context, in *gitalypb.GarbageCollect
return nil, err
}
- stats.LogObjectsInfo(ctx, s.gitCmdFactory, repo)
+ stats.LogObjectsInfo(ctx, repo)
return &gitalypb.GarbageCollectResponse{}, nil
}
diff --git a/internal/gitaly/service/repository/midx.go b/internal/gitaly/service/repository/midx.go
index f5c2818b0..81357ce04 100644
--- a/internal/gitaly/service/repository/midx.go
+++ b/internal/gitaly/service/repository/midx.go
@@ -39,7 +39,7 @@ func (s *server) MidxRepack(ctx context.Context, in *gitalypb.MidxRepackRequest)
}
}
- stats.LogObjectsInfo(ctx, s.gitCmdFactory, repo)
+ stats.LogObjectsInfo(ctx, repo)
return &gitalypb.MidxRepackResponse{}, nil
}
diff --git a/internal/gitaly/service/repository/repack.go b/internal/gitaly/service/repository/repack.go
index cf43ff5a2..db595ec6a 100644
--- a/internal/gitaly/service/repository/repack.go
+++ b/internal/gitaly/service/repository/repack.go
@@ -8,7 +8,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"gitlab.com/gitlab-org/gitaly/v14/internal/git"
- "gitlab.com/gitlab-org/gitaly/v14/internal/git/repository"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/stats"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -36,26 +36,28 @@ func log2Threads(numCPUs int) git.ValueFlag {
}
func (s *server) RepackFull(ctx context.Context, in *gitalypb.RepackFullRequest) (*gitalypb.RepackFullResponse, error) {
+ repo := s.localrepo(in.GetRepository())
options := []git.Option{
git.Flag{Name: "-A"},
git.Flag{Name: "--pack-kept-objects"},
git.Flag{Name: "-l"},
log2Threads(runtime.NumCPU()),
}
- if err := s.repackCommand(ctx, in.GetRepository(), in.GetCreateBitmap(), options...); err != nil {
+ if err := s.repackCommand(ctx, repo, in.GetCreateBitmap(), options...); err != nil {
return nil, err
}
return &gitalypb.RepackFullResponse{}, nil
}
func (s *server) RepackIncremental(ctx context.Context, in *gitalypb.RepackIncrementalRequest) (*gitalypb.RepackIncrementalResponse, error) {
- if err := s.repackCommand(ctx, in.GetRepository(), false); err != nil {
+ repo := s.localrepo(in.GetRepository())
+ if err := s.repackCommand(ctx, repo, false); err != nil {
return nil, err
}
return &gitalypb.RepackIncrementalResponse{}, nil
}
-func (s *server) repackCommand(ctx context.Context, repo repository.GitRepo, bitmap bool, args ...git.Option) error {
+func (s *server) repackCommand(ctx context.Context, repo *localrepo.Repo, bitmap bool, args ...git.Option) error {
cmd, err := s.gitCmdFactory.New(ctx, repo,
git.SubCmd{
Name: "repack",
@@ -78,7 +80,7 @@ func (s *server) repackCommand(ctx context.Context, repo repository.GitRepo, bit
return err
}
- stats.LogObjectsInfo(ctx, s.gitCmdFactory, repo)
+ stats.LogObjectsInfo(ctx, repo)
return nil
}