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-12-14 10:02:51 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-12-14 10:19:34 +0300
commit13cc11d3df95dec0b3b2c4af66bf63fd4a2ffc19 (patch)
tree5232ffcd8bcaeeeb86ce4bfcbaf2c627995f6394
parentcfc2ad676520669e329819b7e9e7e55e91678169 (diff)
git: Remove `git.Cmd` interface
Now that we have removed the split between the `git.SubCmd` and the `git.SubSubCmd` structures it doesn't make sense anymore to have the `git.Cmd` interface. Let's remove it and just use `git.SubCmd` directly.
-rw-r--r--internal/git/catfile/testhelper_test.go4
-rw-r--r--internal/git/command.go6
-rw-r--r--internal/git/command_factory.go14
-rw-r--r--internal/git/command_factory_cgroup_test.go2
-rw-r--r--internal/git/gittest/intercepting_command_factory.go4
-rw-r--r--internal/git/localrepo/repo.go4
-rw-r--r--internal/git/repository.go4
-rw-r--r--internal/gitaly/service/diff/commit.go2
-rw-r--r--internal/gitaly/service/remote/update_remote_mirror_test.go15
9 files changed, 23 insertions, 32 deletions
diff --git a/internal/git/catfile/testhelper_test.go b/internal/git/catfile/testhelper_test.go
index 50a6a39e5..d50176d90 100644
--- a/internal/git/catfile/testhelper_test.go
+++ b/internal/git/catfile/testhelper_test.go
@@ -35,11 +35,11 @@ func newRepoExecutor(t *testing.T, cfg config.Cfg, repo repository.GitRepo) git.
}
}
-func (e *repoExecutor) Exec(ctx context.Context, cmd git.Cmd, opts ...git.CmdOpt) (*command.Command, error) {
+func (e *repoExecutor) Exec(ctx context.Context, cmd git.SubCmd, opts ...git.CmdOpt) (*command.Command, error) {
return e.gitCmdFactory.New(ctx, e.GitRepo, cmd, opts...)
}
-func (e *repoExecutor) ExecAndWait(ctx context.Context, cmd git.Cmd, opts ...git.CmdOpt) error {
+func (e *repoExecutor) ExecAndWait(ctx context.Context, cmd git.SubCmd, opts ...git.CmdOpt) error {
command, err := e.Exec(ctx, cmd, opts...)
if err != nil {
return err
diff --git a/internal/git/command.go b/internal/git/command.go
index 06360cdee..d88f661d0 100644
--- a/internal/git/command.go
+++ b/internal/git/command.go
@@ -16,12 +16,6 @@ var (
actionRegex = regexp.MustCompile(`^[[:alnum:]]+[-[:alnum:]]*$`)
)
-// Cmd is an interface for safe git commands
-type Cmd interface {
- CommandArgs() ([]string, error)
- Subcommand() string
-}
-
// SubCmd represents a specific git command
type SubCmd struct {
// Name is the name of the Git command to run, e.g. "log", "cat-flie" or "worktree".
diff --git a/internal/git/command_factory.go b/internal/git/command_factory.go
index abdc167eb..b006addee 100644
--- a/internal/git/command_factory.go
+++ b/internal/git/command_factory.go
@@ -22,9 +22,9 @@ import (
// CommandFactory is designed to create and run git commands in a protected and fully managed manner.
type CommandFactory interface {
// New creates a new command for the repo repository.
- New(ctx context.Context, repo repository.GitRepo, sc Cmd, opts ...CmdOpt) (*command.Command, error)
+ New(ctx context.Context, repo repository.GitRepo, sc SubCmd, opts ...CmdOpt) (*command.Command, error)
// NewWithoutRepo creates a command without a target repository.
- NewWithoutRepo(ctx context.Context, sc Cmd, opts ...CmdOpt) (*command.Command, error)
+ NewWithoutRepo(ctx context.Context, sc SubCmd, opts ...CmdOpt) (*command.Command, error)
// GetExecutionEnvironment returns parameters required to execute Git commands.
GetExecutionEnvironment(context.Context) ExecutionEnvironment
// HooksPath returns the path where Gitaly's Git hooks reside.
@@ -237,12 +237,12 @@ func (cf *ExecCommandFactory) Collect(metrics chan<- prometheus.Metric) {
}
// New creates a new command for the repo repository.
-func (cf *ExecCommandFactory) New(ctx context.Context, repo repository.GitRepo, sc Cmd, opts ...CmdOpt) (*command.Command, error) {
+func (cf *ExecCommandFactory) New(ctx context.Context, repo repository.GitRepo, sc SubCmd, opts ...CmdOpt) (*command.Command, error) {
return cf.newCommand(ctx, repo, sc, opts...)
}
// NewWithoutRepo creates a command without a target repository.
-func (cf *ExecCommandFactory) NewWithoutRepo(ctx context.Context, sc Cmd, opts ...CmdOpt) (*command.Command, error) {
+func (cf *ExecCommandFactory) NewWithoutRepo(ctx context.Context, sc SubCmd, opts ...CmdOpt) (*command.Command, error) {
return cf.newCommand(ctx, nil, sc, opts...)
}
@@ -374,7 +374,7 @@ func (cf *ExecCommandFactory) GitVersion(ctx context.Context) (Version, error) {
// command will be run in the context of that repository. Note that this sets up arguments and
// environment variables for git, but doesn't run in the directory itself. If a directory
// is given, then the command will be run in that directory.
-func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo repository.GitRepo, sc Cmd, opts ...CmdOpt) (*command.Command, error) {
+func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo repository.GitRepo, sc SubCmd, opts ...CmdOpt) (*command.Command, error) {
config, err := cf.combineOpts(ctx, sc, opts)
if err != nil {
return nil, err
@@ -427,7 +427,7 @@ func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo repository.Gi
return command, nil
}
-func (cf *ExecCommandFactory) combineOpts(ctx context.Context, sc Cmd, opts []CmdOpt) (cmdCfg, error) {
+func (cf *ExecCommandFactory) combineOpts(ctx context.Context, sc SubCmd, opts []CmdOpt) (cmdCfg, error) {
var config cmdCfg
commandDescription, ok := commandDescriptions[sc.Subcommand()]
@@ -448,7 +448,7 @@ func (cf *ExecCommandFactory) combineOpts(ctx context.Context, sc Cmd, opts []Cm
return config, nil
}
-func (cf *ExecCommandFactory) combineArgs(ctx context.Context, gitConfig []config.GitConfig, sc Cmd, cc cmdCfg) (_ []string, err error) {
+func (cf *ExecCommandFactory) combineArgs(ctx context.Context, gitConfig []config.GitConfig, sc SubCmd, cc cmdCfg) (_ []string, err error) {
var args []string
defer func() {
diff --git a/internal/git/command_factory_cgroup_test.go b/internal/git/command_factory_cgroup_test.go
index cf3ebbc72..9a42b7cc9 100644
--- a/internal/git/command_factory_cgroup_test.go
+++ b/internal/git/command_factory_cgroup_test.go
@@ -65,7 +65,7 @@ func TestNewCommandAddsToCgroup(t *testing.T) {
var manager mockCgroupsManager
gitCmdFactory := gittest.NewCommandFactory(t, cfg, git.WithCgroupsManager(&manager))
- cmd, err := gitCmdFactory.New(ctx, repo, &git.SubCmd{
+ cmd, err := gitCmdFactory.New(ctx, repo, git.SubCmd{
Name: "rev-parse",
Flags: []git.Option{
git.Flag{Name: "--is-bare-repository"},
diff --git a/internal/git/gittest/intercepting_command_factory.go b/internal/git/gittest/intercepting_command_factory.go
index d4fed3a86..87813ed43 100644
--- a/internal/git/gittest/intercepting_command_factory.go
+++ b/internal/git/gittest/intercepting_command_factory.go
@@ -106,14 +106,14 @@ func NewInterceptingCommandFactory(
}
// New creates a new Git command for the given repository using the intercepting script.
-func (f *InterceptingCommandFactory) New(ctx context.Context, repo repository.GitRepo, sc git.Cmd, opts ...git.CmdOpt) (*command.Command, error) {
+func (f *InterceptingCommandFactory) New(ctx context.Context, repo repository.GitRepo, sc git.SubCmd, opts ...git.CmdOpt) (*command.Command, error) {
return f.interceptingCommandFactory.New(ctx, repo, sc, append(
opts, git.WithEnv(f.realCommandFactory.GetExecutionEnvironment(ctx).EnvironmentVariables...),
)...)
}
// NewWithoutRepo creates a new Git command using the intercepting script.
-func (f *InterceptingCommandFactory) NewWithoutRepo(ctx context.Context, sc git.Cmd, opts ...git.CmdOpt) (*command.Command, error) {
+func (f *InterceptingCommandFactory) NewWithoutRepo(ctx context.Context, sc git.SubCmd, opts ...git.CmdOpt) (*command.Command, error) {
return f.interceptingCommandFactory.NewWithoutRepo(ctx, sc, append(
opts, git.WithEnv(f.realCommandFactory.GetExecutionEnvironment(ctx).EnvironmentVariables...),
)...)
diff --git a/internal/git/localrepo/repo.go b/internal/git/localrepo/repo.go
index dbb06cc62..1d1790b3a 100644
--- a/internal/git/localrepo/repo.go
+++ b/internal/git/localrepo/repo.go
@@ -75,13 +75,13 @@ func NewTestRepo(tb testing.TB, cfg config.Cfg, repo repository.GitRepo, factory
// Exec creates a git command with the given args and Repo, executed in the
// Repo. It validates the arguments in the command before executing.
-func (repo *Repo) Exec(ctx context.Context, cmd git.Cmd, opts ...git.CmdOpt) (*command.Command, error) {
+func (repo *Repo) Exec(ctx context.Context, cmd git.SubCmd, opts ...git.CmdOpt) (*command.Command, error) {
return repo.gitCmdFactory.New(ctx, repo, cmd, opts...)
}
// ExecAndWait is similar to Exec, but waits for the command to exit before
// returning.
-func (repo *Repo) ExecAndWait(ctx context.Context, cmd git.Cmd, opts ...git.CmdOpt) error {
+func (repo *Repo) ExecAndWait(ctx context.Context, cmd git.SubCmd, opts ...git.CmdOpt) error {
command, err := repo.Exec(ctx, cmd, opts...)
if err != nil {
return err
diff --git a/internal/git/repository.go b/internal/git/repository.go
index 8f969bdf5..767e25bc1 100644
--- a/internal/git/repository.go
+++ b/internal/git/repository.go
@@ -52,8 +52,8 @@ type Repository interface {
// repository.
type RepositoryExecutor interface {
repository.GitRepo
- Exec(ctx context.Context, cmd Cmd, opts ...CmdOpt) (*command.Command, error)
- ExecAndWait(ctx context.Context, cmd Cmd, opts ...CmdOpt) error
+ Exec(ctx context.Context, cmd SubCmd, opts ...CmdOpt) (*command.Command, error)
+ ExecAndWait(ctx context.Context, cmd SubCmd, opts ...CmdOpt) error
GitVersion(ctx context.Context) (Version, error)
ObjectHash(ctx context.Context) (ObjectHash, error)
}
diff --git a/internal/gitaly/service/diff/commit.go b/internal/gitaly/service/diff/commit.go
index f26f787d7..343b03c8f 100644
--- a/internal/gitaly/service/diff/commit.go
+++ b/internal/gitaly/service/diff/commit.go
@@ -211,7 +211,7 @@ func validateRequest(in requestWithLeftRightCommitIds) error {
return nil
}
-func (s *server) eachDiff(ctx context.Context, repo *gitalypb.Repository, subCmd git.Cmd, limits diff.Limits, callback func(*diff.Diff) error) error {
+func (s *server) eachDiff(ctx context.Context, repo *gitalypb.Repository, subCmd git.SubCmd, limits diff.Limits, callback func(*diff.Diff) error) error {
diffConfig := git.ConfigPair{Key: "diff.noprefix", Value: "false"}
cmd, err := s.gitCmdFactory.New(ctx, repo, subCmd, git.WithConfig(diffConfig))
diff --git a/internal/gitaly/service/remote/update_remote_mirror_test.go b/internal/gitaly/service/remote/update_remote_mirror_test.go
index 8fc7670dc..677e3c993 100644
--- a/internal/gitaly/service/remote/update_remote_mirror_test.go
+++ b/internal/gitaly/service/remote/update_remote_mirror_test.go
@@ -30,10 +30,10 @@ import (
type commandFactoryWrapper struct {
git.CommandFactory
- newFunc func(context.Context, repository.GitRepo, git.Cmd, ...git.CmdOpt) (*command.Command, error)
+ newFunc func(context.Context, repository.GitRepo, git.SubCmd, ...git.CmdOpt) (*command.Command, error)
}
-func (w commandFactoryWrapper) New(ctx context.Context, repo repository.GitRepo, sc git.Cmd, opts ...git.CmdOpt) (*command.Command, error) {
+func (w commandFactoryWrapper) New(ctx context.Context, repo repository.GitRepo, sc git.SubCmd, opts ...git.CmdOpt) (*command.Command, error) {
return w.newFunc(ctx, repo, sc, opts...)
}
@@ -329,17 +329,14 @@ func TestUpdateRemoteMirror(t *testing.T) {
wrapCommandFactory: func(tb testing.TB, original git.CommandFactory) git.CommandFactory {
return commandFactoryWrapper{
CommandFactory: original,
- newFunc: func(ctx context.Context, repo repository.GitRepo, sc git.Cmd, opts ...git.CmdOpt) (*command.Command, error) {
- if sc.Subcommand() == "push" {
- subCmd, ok := sc.(git.SubCmd)
- require.True(tb, ok)
-
+ newFunc: func(ctx context.Context, repo repository.GitRepo, sc git.SubCmd, opts ...git.CmdOpt) (*command.Command, error) {
+ if sc.Name == "push" {
// This is really hacky: we extract the
// remote name from the subcommands
// arguments. But honestly, the whole way of
// how we hijack the command factory is kind
// of hacky in the first place.
- remoteName := subCmd.Args[0]
+ remoteName := sc.Args[0]
require.Contains(tb, remoteName, "inmemory-")
// Make the branch diverge on the remote before actually performing the pushes the RPC
@@ -431,7 +428,7 @@ func TestUpdateRemoteMirror(t *testing.T) {
firstPush := true
return commandFactoryWrapper{
CommandFactory: original,
- newFunc: func(ctx context.Context, repo repository.GitRepo, sc git.Cmd, opts ...git.CmdOpt) (*command.Command, error) {
+ newFunc: func(ctx context.Context, repo repository.GitRepo, sc git.SubCmd, opts ...git.CmdOpt) (*command.Command, error) {
if sc.Subcommand() == "push" && firstPush {
firstPush = false
args, err := sc.CommandArgs()