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>2021-07-19 08:59:27 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-07-20 09:48:15 +0300
commit8140a6f12055196681b83ebc635ddda0ed127e5a (patch)
treea8e3a076f886b95c65cf3a977693fa9a5f331317
parent39634c849f6d245bab960a6a611b06f9ad73e5c7 (diff)
gitaly-git2go: Unify code to open Git2Go repository
In order to make it easier to change the way how we open Git2Go repositories across all gitaly-git2go subcommands, this commit unifies the logic into a single `git2goutil.OpenRepository()` function. No functional change is expected from this commit given that it still does the same thing as all codesites did before.
-rw-r--r--cmd/gitaly-git2go/apply.go3
-rw-r--r--cmd/gitaly-git2go/cherry_pick.go3
-rw-r--r--cmd/gitaly-git2go/cherry_pick_test.go3
-rw-r--r--cmd/gitaly-git2go/commit/commit.go3
-rw-r--r--cmd/gitaly-git2go/conflicts/conflicts.go3
-rw-r--r--cmd/gitaly-git2go/git2goutil/repo.go10
-rw-r--r--cmd/gitaly-git2go/merge.go3
-rw-r--r--cmd/gitaly-git2go/merge_test.go5
-rw-r--r--cmd/gitaly-git2go/rebase.go3
-rw-r--r--cmd/gitaly-git2go/rebase_test.go3
-rw-r--r--cmd/gitaly-git2go/resolve_conflicts.go3
-rw-r--r--cmd/gitaly-git2go/revert.go3
-rw-r--r--cmd/gitaly-git2go/revert_test.go3
-rw-r--r--cmd/gitaly-git2go/set_config.go4
-rw-r--r--cmd/gitaly-git2go/submodule.go3
-rw-r--r--cmd/gitaly-git2go/testhelper/testhelper.go3
16 files changed, 41 insertions, 17 deletions
diff --git a/cmd/gitaly-git2go/apply.go b/cmd/gitaly-git2go/apply.go
index 532bc898d..e2e42d656 100644
--- a/cmd/gitaly-git2go/apply.go
+++ b/cmd/gitaly-git2go/apply.go
@@ -16,6 +16,7 @@ import (
"path/filepath"
git "github.com/libgit2/git2go/v31"
+ "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/git2goutil"
"gitlab.com/gitlab-org/gitaly/v14/internal/git2go"
)
@@ -69,7 +70,7 @@ func (cmd *applySubcommand) Run(ctx context.Context, stdin io.Reader, stdout io.
}
func (cmd *applySubcommand) apply(ctx context.Context, params git2go.ApplyParams) (string, error) {
- repo, err := git.OpenRepository(params.Repository)
+ repo, err := git2goutil.OpenRepository(params.Repository)
if err != nil {
return "", fmt.Errorf("open repository: %w", err)
}
diff --git a/cmd/gitaly-git2go/cherry_pick.go b/cmd/gitaly-git2go/cherry_pick.go
index 31c070a76..b186c7d6e 100644
--- a/cmd/gitaly-git2go/cherry_pick.go
+++ b/cmd/gitaly-git2go/cherry_pick.go
@@ -11,6 +11,7 @@ import (
"io"
git "github.com/libgit2/git2go/v31"
+ "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/git2goutil"
"gitlab.com/gitlab-org/gitaly/v14/internal/git2go"
)
@@ -64,7 +65,7 @@ func (cmd *cherryPickSubcommand) cherryPick(ctx context.Context, r *git2go.Cherr
return "", err
}
- repo, err := git.OpenRepository(r.Repository)
+ repo, err := git2goutil.OpenRepository(r.Repository)
if err != nil {
return "", fmt.Errorf("could not open repository: %w", err)
}
diff --git a/cmd/gitaly-git2go/cherry_pick_test.go b/cmd/gitaly-git2go/cherry_pick_test.go
index 6e2a79ae9..997c558d7 100644
--- a/cmd/gitaly-git2go/cherry_pick_test.go
+++ b/cmd/gitaly-git2go/cherry_pick_test.go
@@ -10,6 +10,7 @@ import (
git "github.com/libgit2/git2go/v31"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/git2goutil"
cmdtesthelper "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/internal/git2go"
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config"
@@ -192,7 +193,7 @@ func TestCherryPick(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, tc.expectedCommitID, response.String())
- repo, err := git.OpenRepository(repoPath)
+ repo, err := git2goutil.OpenRepository(repoPath)
require.NoError(t, err)
defer repo.Free()
diff --git a/cmd/gitaly-git2go/commit/commit.go b/cmd/gitaly-git2go/commit/commit.go
index 06a8c4d36..be2d9a585 100644
--- a/cmd/gitaly-git2go/commit/commit.go
+++ b/cmd/gitaly-git2go/commit/commit.go
@@ -10,6 +10,7 @@ import (
"io"
git "github.com/libgit2/git2go/v31"
+ "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/git2goutil"
"gitlab.com/gitlab-org/gitaly/v14/internal/git2go"
)
@@ -28,7 +29,7 @@ func Run(ctx context.Context, stdin io.Reader, stdout io.Writer) error {
}
func commit(ctx context.Context, params git2go.CommitParams) (string, error) {
- repo, err := git.OpenRepository(params.Repository)
+ repo, err := git2goutil.OpenRepository(params.Repository)
if err != nil {
return "", fmt.Errorf("open repository: %w", err)
}
diff --git a/cmd/gitaly-git2go/conflicts/conflicts.go b/cmd/gitaly-git2go/conflicts/conflicts.go
index 96da74958..625eb241d 100644
--- a/cmd/gitaly-git2go/conflicts/conflicts.go
+++ b/cmd/gitaly-git2go/conflicts/conflicts.go
@@ -11,6 +11,7 @@ import (
"os"
git "github.com/libgit2/git2go/v31"
+ "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/git2goutil"
"gitlab.com/gitlab-org/gitaly/v14/internal/git2go"
"gitlab.com/gitlab-org/gitaly/v14/internal/helper"
"google.golang.org/grpc/codes"
@@ -104,7 +105,7 @@ func (cmd *Subcommand) Run(context.Context, io.Reader, io.Writer) error {
return err
}
- repo, err := git.OpenRepository(request.Repository)
+ repo, err := git2goutil.OpenRepository(request.Repository)
if err != nil {
return fmt.Errorf("could not open repository: %w", err)
}
diff --git a/cmd/gitaly-git2go/git2goutil/repo.go b/cmd/gitaly-git2go/git2goutil/repo.go
new file mode 100644
index 000000000..7e20fe524
--- /dev/null
+++ b/cmd/gitaly-git2go/git2goutil/repo.go
@@ -0,0 +1,10 @@
+package git2goutil
+
+import (
+ git "github.com/libgit2/git2go/v31"
+)
+
+// OpenRepository opens the repository located at path as a Git2Go repository.
+func OpenRepository(path string) (*git.Repository, error) {
+ return git.OpenRepository(path)
+}
diff --git a/cmd/gitaly-git2go/merge.go b/cmd/gitaly-git2go/merge.go
index 23a26fe49..3e264d8ad 100644
--- a/cmd/gitaly-git2go/merge.go
+++ b/cmd/gitaly-git2go/merge.go
@@ -13,6 +13,7 @@ import (
git "github.com/libgit2/git2go/v31"
"gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/conflicts"
+ "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/git2goutil"
"gitlab.com/gitlab-org/gitaly/v14/internal/git2go"
)
@@ -36,7 +37,7 @@ func (cmd *mergeSubcommand) Run(context.Context, io.Reader, io.Writer) error {
request.AuthorDate = time.Now()
}
- repo, err := git.OpenRepository(request.Repository)
+ repo, err := git2goutil.OpenRepository(request.Repository)
if err != nil {
return fmt.Errorf("could not open repository: %w", err)
}
diff --git a/cmd/gitaly-git2go/merge_test.go b/cmd/gitaly-git2go/merge_test.go
index e71a0345c..aed3aa34c 100644
--- a/cmd/gitaly-git2go/merge_test.go
+++ b/cmd/gitaly-git2go/merge_test.go
@@ -10,6 +10,7 @@ import (
git "github.com/libgit2/git2go/v31"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/git2goutil"
cmdtesthelper "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v14/internal/git2go"
@@ -211,7 +212,7 @@ func TestMergeTrees(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, tc.expectedResponse, response)
- repo, err := git.OpenRepository(repoPath)
+ repo, err := git2goutil.OpenRepository(repoPath)
require.NoError(t, err)
defer repo.Free()
@@ -325,7 +326,7 @@ func TestMerge_recursive(t *testing.T) {
})
require.NoError(t, err)
- repo, err := git.OpenRepository(repoPath)
+ repo, err := git2goutil.OpenRepository(repoPath)
require.NoError(t, err)
commitOid, err := git.NewOid(response.CommitID)
diff --git a/cmd/gitaly-git2go/rebase.go b/cmd/gitaly-git2go/rebase.go
index c4c0769ed..632a780bb 100644
--- a/cmd/gitaly-git2go/rebase.go
+++ b/cmd/gitaly-git2go/rebase.go
@@ -11,6 +11,7 @@ import (
"io"
git "github.com/libgit2/git2go/v31"
+ "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/git2goutil"
"gitlab.com/gitlab-org/gitaly/v14/internal/git2go"
)
@@ -57,7 +58,7 @@ func (cmd *rebaseSubcommand) rebase(ctx context.Context, request *git2go.RebaseC
return "", err
}
- repo, err := git.OpenRepository(request.Repository)
+ repo, err := git2goutil.OpenRepository(request.Repository)
if err != nil {
return "", fmt.Errorf("open repository: %w", err)
}
diff --git a/cmd/gitaly-git2go/rebase_test.go b/cmd/gitaly-git2go/rebase_test.go
index 29ae11f61..b8995d3bd 100644
--- a/cmd/gitaly-git2go/rebase_test.go
+++ b/cmd/gitaly-git2go/rebase_test.go
@@ -8,6 +8,7 @@ import (
git "github.com/libgit2/git2go/v31"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/git2goutil"
cmdtesthelper "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v14/internal/git2go"
@@ -168,7 +169,7 @@ func TestRebase_rebase(t *testing.T) {
testhelper.ConfigureGitalyGit2GoBin(t, cfg)
executor := git2go.NewExecutor(cfg, config.NewLocator(cfg))
- repo, err := git.OpenRepository(repoPath)
+ repo, err := git2goutil.OpenRepository(repoPath)
require.NoError(t, err)
if tc.setupRepo != nil {
diff --git a/cmd/gitaly-git2go/resolve_conflicts.go b/cmd/gitaly-git2go/resolve_conflicts.go
index bdfd4f864..993152a5c 100644
--- a/cmd/gitaly-git2go/resolve_conflicts.go
+++ b/cmd/gitaly-git2go/resolve_conflicts.go
@@ -14,6 +14,7 @@ import (
"time"
git "github.com/libgit2/git2go/v31"
+ "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/git2goutil"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/conflict"
"gitlab.com/gitlab-org/gitaly/v14/internal/git2go"
)
@@ -35,7 +36,7 @@ func (cmd resolveSubcommand) Run(_ context.Context, r io.Reader, w io.Writer) er
request.AuthorDate = time.Now()
}
- repo, err := git.OpenRepository(request.Repository)
+ repo, err := git2goutil.OpenRepository(request.Repository)
if err != nil {
return fmt.Errorf("could not open repository: %w", err)
}
diff --git a/cmd/gitaly-git2go/revert.go b/cmd/gitaly-git2go/revert.go
index 5c0dab7d9..3e18bb86f 100644
--- a/cmd/gitaly-git2go/revert.go
+++ b/cmd/gitaly-git2go/revert.go
@@ -11,6 +11,7 @@ import (
"io"
git "github.com/libgit2/git2go/v31"
+ "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/git2goutil"
"gitlab.com/gitlab-org/gitaly/v14/internal/git2go"
)
@@ -59,7 +60,7 @@ func (cmd *revertSubcommand) revert(ctx context.Context, request *git2go.RevertC
if err := cmd.verify(ctx, request); err != nil {
return "", err
}
- repo, err := git.OpenRepository(request.Repository)
+ repo, err := git2goutil.OpenRepository(request.Repository)
if err != nil {
return "", fmt.Errorf("open repository: %w", err)
}
diff --git a/cmd/gitaly-git2go/revert_test.go b/cmd/gitaly-git2go/revert_test.go
index 9456df5b0..87811047c 100644
--- a/cmd/gitaly-git2go/revert_test.go
+++ b/cmd/gitaly-git2go/revert_test.go
@@ -10,6 +10,7 @@ import (
git "github.com/libgit2/git2go/v31"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/git2goutil"
cmdtesthelper "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/internal/git2go"
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config"
@@ -205,7 +206,7 @@ func TestRevert_trees(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, tc.expectedCommitID, response.String())
- repo, err := git.OpenRepository(repoPath)
+ repo, err := git2goutil.OpenRepository(repoPath)
require.NoError(t, err)
defer repo.Free()
diff --git a/cmd/gitaly-git2go/set_config.go b/cmd/gitaly-git2go/set_config.go
index 656e3b11d..e1c7b48b8 100644
--- a/cmd/gitaly-git2go/set_config.go
+++ b/cmd/gitaly-git2go/set_config.go
@@ -10,7 +10,7 @@ import (
"fmt"
"io"
- git "github.com/libgit2/git2go/v31"
+ "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/git2goutil"
"gitlab.com/gitlab-org/gitaly/v14/internal/git2go"
)
@@ -26,7 +26,7 @@ func (cmd setConfigSubcommand) setConfig(request git2go.SetConfigCommand) error
return errors.New("missing repository")
}
- git2goRepo, err := git.OpenRepository(request.Repository)
+ git2goRepo, err := git2goutil.OpenRepository(request.Repository)
if err != nil {
return fmt.Errorf("open repository: %w", err)
}
diff --git a/cmd/gitaly-git2go/submodule.go b/cmd/gitaly-git2go/submodule.go
index 0fe7d885c..8a152c2fc 100644
--- a/cmd/gitaly-git2go/submodule.go
+++ b/cmd/gitaly-git2go/submodule.go
@@ -10,6 +10,7 @@ import (
"time"
git "github.com/libgit2/git2go/v31"
+ "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/git2goutil"
"gitlab.com/gitlab-org/gitaly/v14/internal/git2go"
)
@@ -38,7 +39,7 @@ func (cmd *submoduleSubcommand) Run(_ context.Context, _ io.Reader, w io.Writer)
return fmt.Errorf("converting %s to OID: %w", request.CommitSHA, err)
}
- repo, err := git.OpenRepository(request.Repository)
+ repo, err := git2goutil.OpenRepository(request.Repository)
if err != nil {
return fmt.Errorf("open repository: %w", err)
}
diff --git a/cmd/gitaly-git2go/testhelper/testhelper.go b/cmd/gitaly-git2go/testhelper/testhelper.go
index f46a73841..20db57890 100644
--- a/cmd/gitaly-git2go/testhelper/testhelper.go
+++ b/cmd/gitaly-git2go/testhelper/testhelper.go
@@ -8,6 +8,7 @@ import (
git "github.com/libgit2/git2go/v31"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v14/cmd/gitaly-git2go/git2goutil"
)
// DefaultAuthor is the author used by BuildCommit
@@ -18,7 +19,7 @@ var DefaultAuthor = git.Signature{
}
func BuildCommit(t testing.TB, repoPath string, parents []*git.Oid, fileContents map[string]string) *git.Oid {
- repo, err := git.OpenRepository(repoPath)
+ repo, err := git2goutil.OpenRepository(repoPath)
require.NoError(t, err)
defer repo.Free()