diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-05-10 14:18:58 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-05-11 16:45:25 +0300 |
commit | 04abc27b23752b1d685b93a04b9fab96a3fea21a (patch) | |
tree | f0913d08ee9a09a3d0eeaf24e7eb7521245d1a2d | |
parent | 9c740310cc02434e8755f1edce8fa802d43f38a9 (diff) |
internalrefs: Convert to use git.RepositoryExecutor interface
This commit converts the internalrefs package to use the new
git.RepositoryExecutor interface and adjusts its callers.
-rw-r--r-- | internal/gitaly/service/cleanup/apply_bfg_object_map_stream.go | 6 | ||||
-rw-r--r-- | internal/gitaly/service/cleanup/internalrefs/cleaner.go | 18 | ||||
-rw-r--r-- | internal/gitaly/service/cleanup/server.go | 6 |
3 files changed, 14 insertions, 16 deletions
diff --git a/internal/gitaly/service/cleanup/apply_bfg_object_map_stream.go b/internal/gitaly/service/cleanup/apply_bfg_object_map_stream.go index 3f70ea27f..8be0daa9a 100644 --- a/internal/gitaly/service/cleanup/apply_bfg_object_map_stream.go +++ b/internal/gitaly/service/cleanup/apply_bfg_object_map_stream.go @@ -36,18 +36,18 @@ func (s *server) ApplyBfgObjectMapStream(server gitalypb.CleanupService_ApplyBfg } ctx := server.Context() - repo := firstRequest.GetRepository() + repo := s.localrepo(firstRequest.GetRepository()) reader := &bfgStreamReader{firstRequest: firstRequest, server: server} chunker := chunk.New(&bfgStreamWriter{server: server}) - notifier, err := notifier.New(ctx, s.catfileCache, repo, chunker) + notifier, err := notifier.New(ctx, s.catfileCache, firstRequest.GetRepository(), chunker) if err != nil { return helper.ErrInternal(err) } // It doesn't matter if new internal references are added after this RPC // starts running - they shouldn't point to the objects removed by the BFG - cleaner, err := internalrefs.NewCleaner(ctx, s.cfg, s.gitCmdFactory, repo, notifier.Notify) + cleaner, err := internalrefs.NewCleaner(ctx, s.cfg, repo, notifier.Notify) if err != nil { return helper.ErrInternal(err) } diff --git a/internal/gitaly/service/cleanup/internalrefs/cleaner.go b/internal/gitaly/service/cleanup/internalrefs/cleaner.go index b7c000fcd..624c5cb5a 100644 --- a/internal/gitaly/service/cleanup/internalrefs/cleaner.go +++ b/internal/gitaly/service/cleanup/internalrefs/cleaner.go @@ -10,11 +10,8 @@ import ( "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/git" - "gitlab.com/gitlab-org/gitaly/internal/git/catfile" - "gitlab.com/gitlab-org/gitaly/internal/git/localrepo" "gitlab.com/gitlab-org/gitaly/internal/git/updateref" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" - "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) // A ForEachFunc can be called for every entry in the filter-repo or BFG object @@ -41,18 +38,13 @@ type ErrInvalidObjectMap error // NewCleaner builds a new instance of Cleaner, which is used to apply a // filter-repo or BFG object map to a repository. -func NewCleaner(ctx context.Context, cfg config.Cfg, gitCmdFactory git.CommandFactory, repo *gitalypb.Repository, forEach ForEachFunc) (*Cleaner, error) { - // This is only an intermediate state in this commit series to satisfy the interface. The - // subsequent commit will remove this ad-hoc cache again. - catfileCache := catfile.NewCache(gitCmdFactory, cfg) - localRepo := localrepo.New(gitCmdFactory, catfileCache, repo, cfg) - - table, err := buildLookupTable(ctx, gitCmdFactory, repo) +func NewCleaner(ctx context.Context, cfg config.Cfg, repo git.RepositoryExecutor, forEach ForEachFunc) (*Cleaner, error) { + table, err := buildLookupTable(ctx, repo) if err != nil { return nil, err } - updater, err := updateref.New(ctx, cfg, localRepo) + updater, err := updateref.New(ctx, cfg, repo) if err != nil { return nil, err } @@ -132,8 +124,8 @@ func (c *Cleaner) processEntry(ctx context.Context, oldSHA, newSHA string) error // an object that has been rewritten by the filter-repo or BFG (and so require // action). It is consulted once per line in the object map. Git is optimized // for ref -> SHA lookups, but we want the opposite! -func buildLookupTable(ctx context.Context, gitCmdFactory git.CommandFactory, repo *gitalypb.Repository) (map[string][]git.ReferenceName, error) { - cmd, err := gitCmdFactory.New(ctx, repo, git.SubCmd{ +func buildLookupTable(ctx context.Context, repo git.RepositoryExecutor) (map[string][]git.ReferenceName, error) { + cmd, err := repo.Exec(ctx, git.SubCmd{ Name: "for-each-ref", Flags: []git.Option{git.ValueFlag{Name: "--format", Value: "%(objectname) %(refname)"}}, Args: git.InternalRefPrefixes[:], diff --git a/internal/gitaly/service/cleanup/server.go b/internal/gitaly/service/cleanup/server.go index 0172b6af6..dc0278b5d 100644 --- a/internal/gitaly/service/cleanup/server.go +++ b/internal/gitaly/service/cleanup/server.go @@ -3,6 +3,8 @@ package cleanup import ( "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/catfile" + "gitlab.com/gitlab-org/gitaly/internal/git/localrepo" + "gitlab.com/gitlab-org/gitaly/internal/git/repository" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) @@ -21,3 +23,7 @@ func NewServer(cfg config.Cfg, gitCmdFactory git.CommandFactory, catfileCache ca catfileCache: catfileCache, } } + +func (s *server) localrepo(repo repository.GitRepo) *localrepo.Repo { + return localrepo.New(s.gitCmdFactory, s.catfileCache, repo, s.cfg) +} |