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>2023-06-01 14:23:04 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2023-06-02 15:05:59 +0300
commitbf56aa362f18e5255248f4c34d221175ea9de474 (patch)
tree6a7ce4b75d556973bec14b407780ae0db2cc9498
parent83be32a7dc83976e7638d7bd6f25e0364847a13e (diff)
helper: Move `RepoPathEqual()` into storage module
Move the `RepoPathEqual()` helper function into the storage module. This is a more natural fit given that the functionality acts on the storage repository interface and contains knowledge around storage paths.
-rw-r--r--internal/gitaly/service/repository/fetch.go4
-rw-r--r--internal/gitaly/storage/locator.go6
-rw-r--r--internal/gitaly/storage/locator_test.go53
-rw-r--r--internal/helper/repo.go9
-rw-r--r--internal/helper/repo_test.go64
5 files changed, 61 insertions, 75 deletions
diff --git a/internal/gitaly/service/repository/fetch.go b/internal/gitaly/service/repository/fetch.go
index d5e7846cf..8d910505f 100644
--- a/internal/gitaly/service/repository/fetch.go
+++ b/internal/gitaly/service/repository/fetch.go
@@ -9,7 +9,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v16/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/remoterepo"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/service"
- "gitlab.com/gitlab-org/gitaly/v16/internal/helper"
+ "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"
)
@@ -49,7 +49,7 @@ func (s *server) FetchSourceBranch(ctx context.Context, req *gitalypb.FetchSourc
// are local. We can thus optimize and locally resolve the reference
// instead of using an RPC call. We also know that we can always skip
// the fetch as the object will be available.
- if helper.RepoPathEqual(req.GetRepository(), req.GetSourceRepository()) {
+ if storage.RepoPathEqual(req.GetRepository(), req.GetSourceRepository()) {
var err error
sourceOid, err = targetRepo.ResolveRevision(ctx, git.Revision(req.GetSourceBranch()))
diff --git a/internal/gitaly/storage/locator.go b/internal/gitaly/storage/locator.go
index 47d5866d1..550802c0f 100644
--- a/internal/gitaly/storage/locator.go
+++ b/internal/gitaly/storage/locator.go
@@ -17,6 +17,12 @@ type Repository interface {
GetGitAlternateObjectDirectories() []string
}
+// RepoPathEqual compares if two repositories are in the same location
+func RepoPathEqual(a, b Repository) bool {
+ return a.GetStorageName() == b.GetStorageName() &&
+ a.GetRelativePath() == b.GetRelativePath()
+}
+
// Locator allows to get info about location of the repository or storage at the local file system.
type Locator interface {
// GetRepoPath returns the full path of the repository referenced by an RPC Repository message.
diff --git a/internal/gitaly/storage/locator_test.go b/internal/gitaly/storage/locator_test.go
index 15af782b1..506a8ec52 100644
--- a/internal/gitaly/storage/locator_test.go
+++ b/internal/gitaly/storage/locator_test.go
@@ -8,6 +8,59 @@ import (
"gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
)
+func TestRepoPathEqual(t *testing.T) {
+ t.Parallel()
+
+ testCases := []struct {
+ desc string
+ a, b *gitalypb.Repository
+ equal bool
+ }{
+ {
+ desc: "equal",
+ a: &gitalypb.Repository{
+ StorageName: "default",
+ RelativePath: "repo.git",
+ },
+ b: &gitalypb.Repository{
+ StorageName: "default",
+ RelativePath: "repo.git",
+ },
+ equal: true,
+ },
+ {
+ desc: "different storage",
+ a: &gitalypb.Repository{
+ StorageName: "default",
+ RelativePath: "repo.git",
+ },
+ b: &gitalypb.Repository{
+ StorageName: "storage2",
+ RelativePath: "repo.git",
+ },
+ equal: false,
+ },
+ {
+ desc: "different path",
+ a: &gitalypb.Repository{
+ StorageName: "default",
+ RelativePath: "repo.git",
+ },
+ b: &gitalypb.Repository{
+ StorageName: "default",
+ RelativePath: "repo2.git",
+ },
+ equal: false,
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.desc, func(t *testing.T) {
+ assert.Equal(t, tc.equal, RepoPathEqual(tc.a, tc.b))
+ })
+ }
+}
+
func TestValidateRelativePath(t *testing.T) {
for _, tc := range []struct {
path string
diff --git a/internal/helper/repo.go b/internal/helper/repo.go
deleted file mode 100644
index 810cefffe..000000000
--- a/internal/helper/repo.go
+++ /dev/null
@@ -1,9 +0,0 @@
-package helper
-
-import "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage"
-
-// RepoPathEqual compares if two repositories are in the same location
-func RepoPathEqual(a, b storage.Repository) bool {
- return a.GetStorageName() == b.GetStorageName() &&
- a.GetRelativePath() == b.GetRelativePath()
-}
diff --git a/internal/helper/repo_test.go b/internal/helper/repo_test.go
deleted file mode 100644
index 1da084b50..000000000
--- a/internal/helper/repo_test.go
+++ /dev/null
@@ -1,64 +0,0 @@
-package helper
-
-import (
- "testing"
-
- "github.com/stretchr/testify/assert"
- "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper"
- "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
-)
-
-func TestMain(m *testing.M) {
- testhelper.Run(m)
-}
-
-func TestRepoPathEqual(t *testing.T) {
- testCases := []struct {
- desc string
- a, b *gitalypb.Repository
- equal bool
- }{
- {
- desc: "equal",
- a: &gitalypb.Repository{
- StorageName: "default",
- RelativePath: "repo.git",
- },
- b: &gitalypb.Repository{
- StorageName: "default",
- RelativePath: "repo.git",
- },
- equal: true,
- },
- {
- desc: "different storage",
- a: &gitalypb.Repository{
- StorageName: "default",
- RelativePath: "repo.git",
- },
- b: &gitalypb.Repository{
- StorageName: "storage2",
- RelativePath: "repo.git",
- },
- equal: false,
- },
- {
- desc: "different path",
- a: &gitalypb.Repository{
- StorageName: "default",
- RelativePath: "repo.git",
- },
- b: &gitalypb.Repository{
- StorageName: "default",
- RelativePath: "repo2.git",
- },
- equal: false,
- },
- }
-
- for _, tc := range testCases {
- t.Run(tc.desc, func(t *testing.T) {
- assert.Equal(t, tc.equal, RepoPathEqual(tc.a, tc.b))
- })
- }
-}