diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-06-01 14:14:44 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-06-02 15:05:41 +0300 |
commit | 83be32a7dc83976e7638d7bd6f25e0364847a13e (patch) | |
tree | a49f53f018426a317b23ffd4c484d83687b37528 /internal/git2go | |
parent | f60b4ce67aae4bedfbec3a53e0a0d4770ea74fa2 (diff) |
repository: Move GitRepo interface into storage package
The `repository.GitRepo` interface provides a set of functions that
allow us to locate a repository in our storage. It lives in a separate
package outside of the `internal/git` module in order to avoid a set of
cyclic dependencies. The current location is kind of weird though, as
this interface is inherently tied to our storage details instead of
being a generic Git thing.
Move the definition of the interface into `internal/gitaly/storage` so
that it is defined close to where it is used. This should also be a
relatively safe location as any package that depends on the interface
should implicitly already depend on the storage package given that it
will typically be passed down into any kind of storage locator.
While at it, rename it to `storage.Repository`.
Diffstat (limited to 'internal/git2go')
-rw-r--r-- | internal/git2go/apply.go | 4 | ||||
-rw-r--r-- | internal/git2go/cherry_pick.go | 4 | ||||
-rw-r--r-- | internal/git2go/commit.go | 4 | ||||
-rw-r--r-- | internal/git2go/conflicts.go | 4 | ||||
-rw-r--r-- | internal/git2go/executor.go | 5 | ||||
-rw-r--r-- | internal/git2go/featureflags_test.go | 4 | ||||
-rw-r--r-- | internal/git2go/merge.go | 4 | ||||
-rw-r--r-- | internal/git2go/rebase.go | 4 | ||||
-rw-r--r-- | internal/git2go/resolve_conflicts.go | 4 | ||||
-rw-r--r-- | internal/git2go/revert.go | 4 | ||||
-rw-r--r-- | internal/git2go/submodule.go | 4 |
11 files changed, 22 insertions, 23 deletions
diff --git a/internal/git2go/apply.go b/internal/git2go/apply.go index b1689a95d..b61351eba 100644 --- a/internal/git2go/apply.go +++ b/internal/git2go/apply.go @@ -7,7 +7,7 @@ import ( "io" "gitlab.com/gitlab-org/gitaly/v16/internal/git" - "gitlab.com/gitlab-org/gitaly/v16/internal/git/repository" + "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" ) // ErrMergeConflict is returned when there is a merge conflict. @@ -73,7 +73,7 @@ func (iter *slicePatchIterator) Err() error { return nil } // Apply applies the provided patches and returns the OID of the commit with the patches // applied. -func (b *Executor) Apply(ctx context.Context, repo repository.GitRepo, params ApplyParams) (git.ObjectID, error) { +func (b *Executor) Apply(ctx context.Context, repo storage.Repository, params ApplyParams) (git.ObjectID, error) { reader, writer := io.Pipe() defer writer.Close() diff --git a/internal/git2go/cherry_pick.go b/internal/git2go/cherry_pick.go index dabcd48a1..435d85cbf 100644 --- a/internal/git2go/cherry_pick.go +++ b/internal/git2go/cherry_pick.go @@ -5,7 +5,7 @@ import ( "time" "gitlab.com/gitlab-org/gitaly/v16/internal/git" - "gitlab.com/gitlab-org/gitaly/v16/internal/git/repository" + "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" ) // CherryPickCommand contains parameters to perform a cherry-pick. @@ -31,7 +31,7 @@ type CherryPickCommand struct { } // CherryPick performs a cherry-pick via gitaly-git2go. -func (b *Executor) CherryPick(ctx context.Context, repo repository.GitRepo, m CherryPickCommand) (git.ObjectID, error) { +func (b *Executor) CherryPick(ctx context.Context, repo storage.Repository, m CherryPickCommand) (git.ObjectID, error) { m.SigningKey = b.signingKey return b.runWithGob(ctx, repo, "cherry-pick", m) diff --git a/internal/git2go/commit.go b/internal/git2go/commit.go index 8dda50164..2fb7232ea 100644 --- a/internal/git2go/commit.go +++ b/internal/git2go/commit.go @@ -6,7 +6,7 @@ import ( "fmt" "gitlab.com/gitlab-org/gitaly/v16/internal/git" - "gitlab.com/gitlab-org/gitaly/v16/internal/git/repository" + "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" "gitlab.com/gitlab-org/gitaly/v16/internal/structerr" "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb" ) @@ -125,7 +125,7 @@ type CommitCommand struct { // Commit builds a commit from the actions, writes it to the object database and // returns its object id. -func (b *Executor) Commit(ctx context.Context, repo repository.GitRepo, c CommitCommand) (git.ObjectID, error) { +func (b *Executor) Commit(ctx context.Context, repo storage.Repository, c CommitCommand) (git.ObjectID, error) { c.SigningKey = b.signingKey return b.runWithGob(ctx, repo, "commit", c) diff --git a/internal/git2go/conflicts.go b/internal/git2go/conflicts.go index b7018f0ee..7aa16e905 100644 --- a/internal/git2go/conflicts.go +++ b/internal/git2go/conflicts.go @@ -7,7 +7,7 @@ import ( "errors" "fmt" - "gitlab.com/gitlab-org/gitaly/v16/internal/git/repository" + "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -67,7 +67,7 @@ type ConflictsResult struct { } // Conflicts performs a merge via gitaly-git2go and returns all resulting conflicts. -func (b *Executor) Conflicts(ctx context.Context, repo repository.GitRepo, c ConflictsCommand) (ConflictsResult, error) { +func (b *Executor) Conflicts(ctx context.Context, repo storage.Repository, c ConflictsCommand) (ConflictsResult, error) { if err := c.verify(); err != nil { return ConflictsResult{}, fmt.Errorf("conflicts: %w: %s", ErrInvalidArgument, err.Error()) } diff --git a/internal/git2go/executor.go b/internal/git2go/executor.go index 5ea382faf..c59000020 100644 --- a/internal/git2go/executor.go +++ b/internal/git2go/executor.go @@ -13,7 +13,6 @@ import ( "gitlab.com/gitlab-org/gitaly/v16/internal/featureflag" "gitlab.com/gitlab-org/gitaly/v16/internal/git" "gitlab.com/gitlab-org/gitaly/v16/internal/git/alternates" - "gitlab.com/gitlab-org/gitaly/v16/internal/git/repository" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" glog "gitlab.com/gitlab-org/gitaly/v16/internal/log" @@ -50,7 +49,7 @@ func NewExecutor(cfg config.Cfg, gitCmdFactory git.CommandFactory, locator stora } } -func (b *Executor) run(ctx context.Context, repo repository.GitRepo, stdin io.Reader, subcmd string, args ...string) (*bytes.Buffer, error) { +func (b *Executor) run(ctx context.Context, repo storage.Repository, stdin io.Reader, subcmd string, args ...string) (*bytes.Buffer, error) { repoPath, err := b.locator.GetRepoPath(repo) if err != nil { return nil, fmt.Errorf("gitaly-git2go: %w", err) @@ -105,7 +104,7 @@ func (b *Executor) run(ctx context.Context, repo repository.GitRepo, stdin io.Re // runWithGob runs the specified gitaly-git2go cmd with the request gob-encoded // as input and returns the commit ID as string or an error. -func (b *Executor) runWithGob(ctx context.Context, repo repository.GitRepo, cmd string, request interface{}) (git.ObjectID, error) { +func (b *Executor) runWithGob(ctx context.Context, repo storage.Repository, cmd string, request interface{}) (git.ObjectID, error) { input := &bytes.Buffer{} if err := gob.NewEncoder(input).Encode(request); err != nil { return "", fmt.Errorf("%s: %w", cmd, err) diff --git a/internal/git2go/featureflags_test.go b/internal/git2go/featureflags_test.go index f5c2b7b8f..86d021f12 100644 --- a/internal/git2go/featureflags_test.go +++ b/internal/git2go/featureflags_test.go @@ -11,13 +11,13 @@ import ( "gitlab.com/gitlab-org/gitaly/v16/internal/featureflag" "gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v16/internal/git/localrepo" - "gitlab.com/gitlab-org/gitaly/v16/internal/git/repository" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/config" + "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper/testcfg" ) -func (b *Executor) FeatureFlags(ctx context.Context, repo repository.GitRepo) ([]FeatureFlag, error) { +func (b *Executor) FeatureFlags(ctx context.Context, repo storage.Repository) ([]FeatureFlag, error) { output, err := b.run(ctx, repo, nil, "feature-flags") if err != nil { return nil, err diff --git a/internal/git2go/merge.go b/internal/git2go/merge.go index 01061eeec..d205edc1a 100644 --- a/internal/git2go/merge.go +++ b/internal/git2go/merge.go @@ -6,7 +6,7 @@ import ( "fmt" "time" - "gitlab.com/gitlab-org/gitaly/v16/internal/git/repository" + "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" ) const ( @@ -58,7 +58,7 @@ type MergeResult struct { } // Merge performs a merge via gitaly-git2go. -func (b *Executor) Merge(ctx context.Context, repo repository.GitRepo, m MergeCommand) (MergeResult, error) { +func (b *Executor) Merge(ctx context.Context, repo storage.Repository, m MergeCommand) (MergeResult, error) { if err := m.verify(); err != nil { return MergeResult{}, fmt.Errorf("merge: %w: %s", ErrInvalidArgument, err.Error()) } diff --git a/internal/git2go/rebase.go b/internal/git2go/rebase.go index a07657473..3bdc0e9e6 100644 --- a/internal/git2go/rebase.go +++ b/internal/git2go/rebase.go @@ -4,7 +4,7 @@ import ( "context" "gitlab.com/gitlab-org/gitaly/v16/internal/git" - "gitlab.com/gitlab-org/gitaly/v16/internal/git/repository" + "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" ) // RebaseCommand contains parameters to rebase a branch. @@ -35,7 +35,7 @@ type RebaseCommand struct { } // Rebase performs the rebase via gitaly-git2go -func (b *Executor) Rebase(ctx context.Context, repo repository.GitRepo, r RebaseCommand) (git.ObjectID, error) { +func (b *Executor) Rebase(ctx context.Context, repo storage.Repository, r RebaseCommand) (git.ObjectID, error) { r.SigningKey = b.signingKey return b.runWithGob(ctx, repo, "rebase", r) diff --git a/internal/git2go/resolve_conflicts.go b/internal/git2go/resolve_conflicts.go index 1ba19fc81..57089ed79 100644 --- a/internal/git2go/resolve_conflicts.go +++ b/internal/git2go/resolve_conflicts.go @@ -7,7 +7,7 @@ import ( "fmt" "gitlab.com/gitlab-org/gitaly/v16/internal/git/conflict" - "gitlab.com/gitlab-org/gitaly/v16/internal/git/repository" + "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" ) // ResolveCommand contains arguments to perform a merge commit and resolve any @@ -27,7 +27,7 @@ type ResolveResult struct { } // Resolve will attempt merging and resolving conflicts for the provided request -func (b *Executor) Resolve(ctx context.Context, repo repository.GitRepo, r ResolveCommand) (ResolveResult, error) { +func (b *Executor) Resolve(ctx context.Context, repo storage.Repository, r ResolveCommand) (ResolveResult, error) { r.SigningKey = b.signingKey if err := r.verify(); err != nil { diff --git a/internal/git2go/revert.go b/internal/git2go/revert.go index d3a545729..b3210f730 100644 --- a/internal/git2go/revert.go +++ b/internal/git2go/revert.go @@ -5,7 +5,7 @@ import ( "time" "gitlab.com/gitlab-org/gitaly/v16/internal/git" - "gitlab.com/gitlab-org/gitaly/v16/internal/git/repository" + "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" ) // RevertCommand contains parameters required to execute a revert via gitaly-git2go. @@ -31,7 +31,7 @@ type RevertCommand struct { } // Revert reverts a commit via gitaly-git2go. -func (b *Executor) Revert(ctx context.Context, repo repository.GitRepo, r RevertCommand) (git.ObjectID, error) { +func (b *Executor) Revert(ctx context.Context, repo storage.Repository, r RevertCommand) (git.ObjectID, error) { r.SigningKey = b.signingKey return b.runWithGob(ctx, repo, "revert", r) diff --git a/internal/git2go/submodule.go b/internal/git2go/submodule.go index f0fb54e90..a25335d99 100644 --- a/internal/git2go/submodule.go +++ b/internal/git2go/submodule.go @@ -7,7 +7,7 @@ import ( "fmt" "time" - "gitlab.com/gitlab-org/gitaly/v16/internal/git/repository" + "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" ) // Error strings present in the legacy Ruby implementation @@ -49,7 +49,7 @@ type SubmoduleResult struct { } // Submodule attempts to commit the request submodule change -func (b *Executor) Submodule(ctx context.Context, repo repository.GitRepo, s SubmoduleCommand) (SubmoduleResult, error) { +func (b *Executor) Submodule(ctx context.Context, repo storage.Repository, s SubmoduleCommand) (SubmoduleResult, error) { s.SigningKey = b.signingKey if err := s.verify(); err != nil { |