diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-12-14 10:10:58 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-12-14 10:21:28 +0300 |
commit | a4c23d2d7557bbf28f058689815e2560f632b95f (patch) | |
tree | 8d36d8b8c80e20b7920b67c14b0a9319e0aa5a8e | |
parent | eccf7f1536d2c844e64734037feb8a4066046093 (diff) |
git: Rename `SubCmd` structure to `Command`
The `SubCmd` structure is misnamed: the "config" part in "git config" is
not a subcommand, but it is what Git calls a "command", see git(1)
section "GIT COMMANDS". So the structure has been misnamed from the
beginning.
Rename the structure to be called `Command`.
94 files changed, 166 insertions, 166 deletions
diff --git a/internal/git/catfile/commit.go b/internal/git/catfile/commit.go index 586e34751..66402c037 100644 --- a/internal/git/catfile/commit.go +++ b/internal/git/catfile/commit.go @@ -39,7 +39,7 @@ func GetCommitWithTrailers( // We use the commit ID here instead of revision. This way we still get // trailers if the revision is not a SHA but e.g. a tag name. - showCmd, err := gitCmdFactory.New(ctx, repo, git.SubCmd{ + showCmd, err := gitCmdFactory.New(ctx, repo, git.Command{ Name: "show", Args: []string{commit.Id}, Flags: []git.Option{ diff --git a/internal/git/catfile/object_content_reader.go b/internal/git/catfile/object_content_reader.go index 53f9ec6b2..3a2d59ad5 100644 --- a/internal/git/catfile/object_content_reader.go +++ b/internal/git/catfile/object_content_reader.go @@ -60,7 +60,7 @@ func newObjectContentReader( counter *prometheus.CounterVec, ) (*objectContentReader, error) { batchCmd, err := repo.Exec(ctx, - git.SubCmd{ + git.Command{ Name: "cat-file", Flags: []git.Option{ git.Flag{Name: "--batch"}, diff --git a/internal/git/catfile/object_info_reader.go b/internal/git/catfile/object_info_reader.go index 80d7d5683..d0e6cb1fc 100644 --- a/internal/git/catfile/object_info_reader.go +++ b/internal/git/catfile/object_info_reader.go @@ -141,7 +141,7 @@ func newObjectInfoReader( counter *prometheus.CounterVec, ) (*objectInfoReader, error) { batchCmd, err := repo.Exec(ctx, - git.SubCmd{ + git.Command{ Name: "cat-file", Flags: []git.Option{ git.Flag{Name: "--batch-check"}, diff --git a/internal/git/catfile/testhelper_test.go b/internal/git/catfile/testhelper_test.go index d50176d90..dd226a468 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.SubCmd, opts ...git.CmdOpt) (*command.Command, error) { +func (e *repoExecutor) Exec(ctx context.Context, cmd git.Command, opts ...git.CmdOpt) (*command.Command, error) { return e.gitCmdFactory.New(ctx, e.GitRepo, cmd, opts...) } -func (e *repoExecutor) ExecAndWait(ctx context.Context, cmd git.SubCmd, opts ...git.CmdOpt) error { +func (e *repoExecutor) ExecAndWait(ctx context.Context, cmd git.Command, 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 4bdf035e6..f5645fc96 100644 --- a/internal/git/command.go +++ b/internal/git/command.go @@ -16,8 +16,8 @@ var ( actionRegex = regexp.MustCompile(`^[[:alnum:]]+[-[:alnum:]]*$`) ) -// SubCmd represents a specific git command -type SubCmd struct { +// Command represent a Git command. +type Command struct { // Name is the name of the Git command to run, e.g. "log", "cat-flie" or "worktree". Name string // Action is the action of the Git command, e.g. "set-url" in `git remote set-url` @@ -39,23 +39,23 @@ type SubCmd struct { } // CommandArgs checks all arguments in the sub command and validates them -func (sc SubCmd) CommandArgs() ([]string, error) { +func (c Command) CommandArgs() ([]string, error) { var safeArgs []string - commandDescription, ok := commandDescriptions[sc.Name] + commandDescription, ok := commandDescriptions[c.Name] if !ok { - return nil, fmt.Errorf("invalid sub command name %q: %w", sc.Name, ErrInvalidArg) + return nil, fmt.Errorf("invalid sub command name %q: %w", c.Name, ErrInvalidArg) } - safeArgs = append(safeArgs, sc.Name) + safeArgs = append(safeArgs, c.Name) - if sc.Action != "" { - if !actionRegex.MatchString(sc.Action) { - return nil, fmt.Errorf("invalid action %q: %w", sc.Action, ErrInvalidArg) + if c.Action != "" { + if !actionRegex.MatchString(c.Action) { + return nil, fmt.Errorf("invalid action %q: %w", c.Action, ErrInvalidArg) } - safeArgs = append(safeArgs, sc.Action) + safeArgs = append(safeArgs, c.Action) } - commandArgs, err := commandDescription.args(sc.Flags, sc.Args, sc.PostSepArgs) + commandArgs, err := commandDescription.args(c.Flags, c.Args, c.PostSepArgs) if err != nil { return nil, err } diff --git a/internal/git/command_factory.go b/internal/git/command_factory.go index aa93c7fb5..d288929c8 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 SubCmd, opts ...CmdOpt) (*command.Command, error) + New(ctx context.Context, repo repository.GitRepo, sc Command, opts ...CmdOpt) (*command.Command, error) // NewWithoutRepo creates a command without a target repository. - NewWithoutRepo(ctx context.Context, sc SubCmd, opts ...CmdOpt) (*command.Command, error) + NewWithoutRepo(ctx context.Context, sc Command, 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 SubCmd, opts ...CmdOpt) (*command.Command, error) { +func (cf *ExecCommandFactory) New(ctx context.Context, repo repository.GitRepo, sc Command, 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 SubCmd, opts ...CmdOpt) (*command.Command, error) { +func (cf *ExecCommandFactory) NewWithoutRepo(ctx context.Context, sc Command, 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 SubCmd, opts ...CmdOpt) (*command.Command, error) { +func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo repository.GitRepo, sc Command, 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 SubCmd, opts []CmdOpt) (cmdCfg, error) { +func (cf *ExecCommandFactory) combineOpts(ctx context.Context, sc Command, opts []CmdOpt) (cmdCfg, error) { var config cmdCfg commandDescription, ok := commandDescriptions[sc.Name] @@ -448,7 +448,7 @@ func (cf *ExecCommandFactory) combineOpts(ctx context.Context, sc SubCmd, opts [ return config, nil } -func (cf *ExecCommandFactory) combineArgs(ctx context.Context, gitConfig []config.GitConfig, sc SubCmd, cc cmdCfg) (_ []string, err error) { +func (cf *ExecCommandFactory) combineArgs(ctx context.Context, gitConfig []config.GitConfig, sc Command, 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 9a42b7cc9..60c2e25ef 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.Command{ Name: "rev-parse", Flags: []git.Option{ git.Flag{Name: "--is-bare-repository"}, diff --git a/internal/git/command_factory_test.go b/internal/git/command_factory_test.go index b262ac7cd..3356fe467 100644 --- a/internal/git/command_factory_test.go +++ b/internal/git/command_factory_test.go @@ -44,7 +44,7 @@ func TestGitCommandProxy(t *testing.T) { require.NoError(t, err) defer cleanup() - cmd, err := gitCmdFactory.NewWithoutRepo(ctx, git.SubCmd{ + cmd, err := gitCmdFactory.NewWithoutRepo(ctx, git.Command{ Name: "clone", Args: []string{"http://gitlab.com/bogus-repo", dir}, }, git.WithDisabledHooks()) @@ -82,7 +82,7 @@ func TestExecCommandFactory_globalGitConfigIgnored(t *testing.T) { {desc: "system", filter: "--system"}, } { t.Run(tc.desc, func(t *testing.T) { - cmd, err := gitCmdFactory.NewWithoutRepo(ctx, git.SubCmd{ + cmd, err := gitCmdFactory.NewWithoutRepo(ctx, git.Command{ Name: "config", Flags: []git.Option{git.Flag{Name: "--list"}, git.Flag{Name: tc.filter}}, }, git.WithEnv("HOME="+tmpHome)) @@ -201,7 +201,7 @@ func TestExecCommandFactory_gitConfiguration(t *testing.T) { defer cleanup() var stdout bytes.Buffer - cmd, err := commandFactory.New(ctx, repo, git.SubCmd{ + cmd, err := commandFactory.New(ctx, repo, git.Command{ Name: "config", Flags: []git.Option{ git.Flag{Name: "--list"}, @@ -571,7 +571,7 @@ func TestExecCommandFactory_config(t *testing.T) { gitCmdFactory := gittest.NewCommandFactory(t, cfg) var stdout bytes.Buffer - cmd, err := gitCmdFactory.New(ctx, repo, git.SubCmd{ + cmd, err := gitCmdFactory.New(ctx, repo, git.Command{ Name: "config", Flags: []git.Option{ git.Flag{Name: "--list"}, @@ -693,7 +693,7 @@ func TestFsckConfiguration(t *testing.T) { // Create fsck command with configured ignore rules options. cmd, err := gitCmdFactory.New(ctx, repoProto, - git.SubCmd{Name: "fsck"}, + git.Command{Name: "fsck"}, ) require.NoError(t, err) diff --git a/internal/git/command_options_test.go b/internal/git/command_options_test.go index 5bdf7fcaa..b3e9e58ae 100644 --- a/internal/git/command_options_test.go +++ b/internal/git/command_options_test.go @@ -273,7 +273,7 @@ func TestWithConfig(t *testing.T) { for expectedKey, expectedValue := range tc.expectedValues { var stdout bytes.Buffer - configCmd, err := gitCmdFactory.NewWithoutRepo(ctx, SubCmd{ + configCmd, err := gitCmdFactory.NewWithoutRepo(ctx, Command{ Name: "config", Args: []string{expectedKey}, }, WithStdout(&stdout), option) @@ -302,7 +302,7 @@ func TestExecCommandFactoryGitalyConfigOverrides(t *testing.T) { var stdout bytes.Buffer cmd, err := gitCmdFactory.NewWithoutRepo(ctx, - SubCmd{ + Command{ Name: "config", Args: []string{"foo.bar"}, }, @@ -405,7 +405,7 @@ func TestWithConfigEnv(t *testing.T) { for expectedKey, expectedValue := range tc.expectedValues { var stdout bytes.Buffer - configCmd, err := gitCmdFactory.NewWithoutRepo(ctx, SubCmd{ + configCmd, err := gitCmdFactory.NewWithoutRepo(ctx, Command{ Name: "config", Args: []string{expectedKey}, }, WithStdout(&stdout), option) diff --git a/internal/git/gitattributes/check_attr.go b/internal/git/gitattributes/check_attr.go index 8dc2ebb6c..d51420afa 100644 --- a/internal/git/gitattributes/check_attr.go +++ b/internal/git/gitattributes/check_attr.go @@ -30,7 +30,7 @@ type CheckAttrCmd struct { // CheckAttr creates a CheckAttrCmd that checks the given list of attribute names. func CheckAttr(ctx context.Context, repo git.RepositoryExecutor, names []string) (*CheckAttrCmd, func(), error) { - cmd, err := repo.Exec(ctx, git.SubCmd{ + cmd, err := repo.Exec(ctx, git.Command{ Name: "check-attr", Flags: []git.Option{ git.Flag{Name: "--stdin"}, diff --git a/internal/git/gitpipe/catfile_info.go b/internal/git/gitpipe/catfile_info.go index 42ea63b80..24465f4c8 100644 --- a/internal/git/gitpipe/catfile_info.go +++ b/internal/git/gitpipe/catfile_info.go @@ -210,7 +210,7 @@ func CatfileInfoAllObjects( } var stderr bytes.Buffer - cmd, err := repo.Exec(ctx, git.SubCmd{ + cmd, err := repo.Exec(ctx, git.Command{ Name: "cat-file", Flags: []git.Option{ batchCheckOption, diff --git a/internal/git/gitpipe/diff_tree.go b/internal/git/gitpipe/diff_tree.go index deeb0e60c..c8a7ad654 100644 --- a/internal/git/gitpipe/diff_tree.go +++ b/internal/git/gitpipe/diff_tree.go @@ -74,7 +74,7 @@ func DiffTree( var stderr strings.Builder cmd, err := repo.Exec(ctx, - git.SubCmd{ + git.Command{ Name: "diff-tree", Flags: flags, Args: []string{leftRevision, rightRevision}, diff --git a/internal/git/gitpipe/ls_tree.go b/internal/git/gitpipe/ls_tree.go index 38c15a8c7..98d8a35b6 100644 --- a/internal/git/gitpipe/ls_tree.go +++ b/internal/git/gitpipe/ls_tree.go @@ -83,7 +83,7 @@ func LsTree( var stderr strings.Builder cmd, err := repo.Exec(ctx, - git.SubCmd{ + git.Command{ Name: "ls-tree", Flags: flags, Args: []string{revision}, diff --git a/internal/git/gitpipe/revision.go b/internal/git/gitpipe/revision.go index 64102a4af..fc88f01d9 100644 --- a/internal/git/gitpipe/revision.go +++ b/internal/git/gitpipe/revision.go @@ -287,7 +287,7 @@ func Revlist( var stderr strings.Builder revlist, err := repo.Exec(ctx, - git.SubCmd{ + git.Command{ Name: "rev-list", Flags: flags, Args: revisions, @@ -426,7 +426,7 @@ func ForEachRef( flags = append(flags, git.ValueFlag{Name: "--count", Value: strconv.Itoa(cfg.count)}) } - forEachRef, err := repo.Exec(ctx, git.SubCmd{ + forEachRef, err := repo.Exec(ctx, git.Command{ Name: "for-each-ref", Flags: flags, Args: patterns, diff --git a/internal/git/gittest/intercepting_command_factory.go b/internal/git/gittest/intercepting_command_factory.go index 87813ed43..378ef99c9 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.SubCmd, opts ...git.CmdOpt) (*command.Command, error) { +func (f *InterceptingCommandFactory) New(ctx context.Context, repo repository.GitRepo, sc git.Command, 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.SubCmd, opts ...git.CmdOpt) (*command.Command, error) { +func (f *InterceptingCommandFactory) NewWithoutRepo(ctx context.Context, sc git.Command, 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/gittest/intercepting_command_factory_test.go b/internal/git/gittest/intercepting_command_factory_test.go index a8a8a5fd9..6fa1b256e 100644 --- a/internal/git/gittest/intercepting_command_factory_test.go +++ b/internal/git/gittest/intercepting_command_factory_test.go @@ -24,7 +24,7 @@ func TestInterceptingCommandFactory(t *testing.T) { t.Run("New", func(t *testing.T) { var stdout bytes.Buffer - cmd, err := factory.New(ctx, repoProto, git.SubCmd{ + cmd, err := factory.New(ctx, repoProto, git.Command{ Name: "rev-parse", Args: []string{"something"}, }, git.WithStdout(&stdout)) @@ -35,7 +35,7 @@ func TestInterceptingCommandFactory(t *testing.T) { t.Run("NewWithoutRepo", func(t *testing.T) { var stdout bytes.Buffer - cmd, err := factory.NewWithoutRepo(ctx, git.SubCmd{ + cmd, err := factory.NewWithoutRepo(ctx, git.Command{ Name: "rev-parse", Args: []string{"something"}, Flags: []git.Option{ diff --git a/internal/git/hooks_options_test.go b/internal/git/hooks_options_test.go index 24ebed76b..504d78bc5 100644 --- a/internal/git/hooks_options_test.go +++ b/internal/git/hooks_options_test.go @@ -21,7 +21,7 @@ func TestWithRefHook(t *testing.T) { ctx := testhelper.Context(t) opt := git.WithRefTxHook(repo) - subCmd := git.SubCmd{Name: "update-ref", Args: []string{"refs/heads/master", git.ObjectHashSHA1.ZeroOID.String()}} + subCmd := git.Command{Name: "update-ref", Args: []string{"refs/heads/master", git.ObjectHashSHA1.ZeroOID.String()}} for _, tt := range []struct { name string @@ -70,7 +70,7 @@ func TestWithPackObjectsHookEnv(t *testing.T) { protocol := "protocol" opt := git.WithPackObjectsHookEnv(repo, protocol) - subCmd := git.SubCmd{Name: "upload-pack", Args: []string{"a/b/c"}} + subCmd := git.Command{Name: "upload-pack", Args: []string{"a/b/c"}} ctx = grpcmetadata.AppendToOutgoingContext(ctx, "user_id", userID, "username", username) ctx = metadata.OutgoingToIncoming(ctx) diff --git a/internal/git/housekeeping/clean_stale_data.go b/internal/git/housekeeping/clean_stale_data.go index 424717e5d..9bf70d1d5 100644 --- a/internal/git/housekeeping/clean_stale_data.go +++ b/internal/git/housekeeping/clean_stale_data.go @@ -199,7 +199,7 @@ func pruneEmptyConfigSections(ctx context.Context, repo *localrepo.Repo) (_ int, var configOutputs []string for _, path := range []string{configPath, configWriter.Path()} { var configOutput bytes.Buffer - if err := repo.ExecAndWait(ctx, git.SubCmd{ + if err := repo.ExecAndWait(ctx, git.Command{ Name: "config", Flags: []git.Option{ git.ValueFlag{Name: "-f", Value: path}, diff --git a/internal/git/housekeeping/commit_graph.go b/internal/git/housekeeping/commit_graph.go index 898fadda6..afabc43a6 100644 --- a/internal/git/housekeeping/commit_graph.go +++ b/internal/git/housekeeping/commit_graph.go @@ -69,7 +69,7 @@ func WriteCommitGraph(ctx context.Context, repo *localrepo.Repo, cfg WriteCommit } var stderr bytes.Buffer - if err := repo.ExecAndWait(ctx, git.SubCmd{ + if err := repo.ExecAndWait(ctx, git.Command{ Name: "commit-graph", Action: "write", Flags: flags, diff --git a/internal/git/housekeeping/objects.go b/internal/git/housekeeping/objects.go index 517e4dc86..370c01560 100644 --- a/internal/git/housekeeping/objects.go +++ b/internal/git/housekeeping/objects.go @@ -38,7 +38,7 @@ func RepackObjects(ctx context.Context, repo *localrepo.Repo, cfg RepackObjectsC ) } - if err := repo.ExecAndWait(ctx, git.SubCmd{ + if err := repo.ExecAndWait(ctx, git.Command{ Name: "repack", Flags: append([]git.Option{ git.Flag{Name: "-d"}, diff --git a/internal/git/housekeeping/optimize_repository.go b/internal/git/housekeeping/optimize_repository.go index f55cefb26..52fe8b156 100644 --- a/internal/git/housekeeping/optimize_repository.go +++ b/internal/git/housekeeping/optimize_repository.go @@ -192,7 +192,7 @@ func pruneIfNeeded(ctx context.Context, repo *localrepo.Repo, strategy Optimizat return false, nil } - if err := repo.ExecAndWait(ctx, git.SubCmd{ + if err := repo.ExecAndWait(ctx, git.Command{ Name: "prune", Flags: []git.Option{ // By default, this prunes all unreachable objects regardless of when they @@ -215,7 +215,7 @@ func packRefsIfNeeded(ctx context.Context, repo *localrepo.Repo, strategy Optimi } var stderr bytes.Buffer - if err := repo.ExecAndWait(ctx, git.SubCmd{ + if err := repo.ExecAndWait(ctx, git.Command{ Name: "pack-refs", Flags: []git.Option{ git.Flag{Name: "--all"}, diff --git a/internal/git/housekeeping/worktrees.go b/internal/git/housekeeping/worktrees.go index af1f12863..adf53e685 100644 --- a/internal/git/housekeeping/worktrees.go +++ b/internal/git/housekeeping/worktrees.go @@ -98,7 +98,7 @@ var errUnknownWorktree = errors.New("unknown worktree") func removeWorktree(ctx context.Context, repo *localrepo.Repo, name string) error { var stderr bytes.Buffer - err := repo.ExecAndWait(ctx, git.SubCmd{ + err := repo.ExecAndWait(ctx, git.Command{ Name: "worktree", Action: "remove", Flags: []git.Option{git.Flag{Name: "--force"}}, @@ -161,7 +161,7 @@ func cleanDisconnectedWorktrees(ctx context.Context, repo *localrepo.Repo) error return nil } - return repo.ExecAndWait(ctx, git.SubCmd{ + return repo.ExecAndWait(ctx, git.Command{ Name: "worktree", Action: "prune", }, git.WithRefTxHook(repo)) diff --git a/internal/git/localrepo/config.go b/internal/git/localrepo/config.go index 56c965ed8..7edd7d1f7 100644 --- a/internal/git/localrepo/config.go +++ b/internal/git/localrepo/config.go @@ -44,7 +44,7 @@ func (repo *Repo) SetConfig(ctx context.Context, key, value string, txManager tr } }() - if err := repo.ExecAndWait(ctx, git.SubCmd{ + if err := repo.ExecAndWait(ctx, git.Command{ Name: "config", Flags: []git.Option{ git.Flag{Name: "--replace-all"}, @@ -104,7 +104,7 @@ func (repo *Repo) UnsetMatchingConfig( // There is no way to directly unset all keys matching a given regular expression, so we // need to go the indirect route and first discover all matching keys via `--get-regex`. var stdout bytes.Buffer - if err := repo.ExecAndWait(ctx, git.SubCmd{ + if err := repo.ExecAndWait(ctx, git.Command{ Name: "config", Flags: []git.Option{ git.Flag{Name: "--name-only"}, @@ -139,7 +139,7 @@ func (repo *Repo) UnsetMatchingConfig( } keySeen[key] = true - if err := repo.ExecAndWait(ctx, git.SubCmd{ + if err := repo.ExecAndWait(ctx, git.Command{ Name: "config", Flags: []git.Option{ git.Flag{Name: "--unset-all"}, diff --git a/internal/git/localrepo/objects.go b/internal/git/localrepo/objects.go index 43198b0e9..315eb727a 100644 --- a/internal/git/localrepo/objects.go +++ b/internal/git/localrepo/objects.go @@ -27,7 +27,7 @@ func (repo *Repo) WriteBlob(ctx context.Context, path string, content io.Reader) stderr := &bytes.Buffer{} cmd, err := repo.Exec(ctx, - git.SubCmd{ + git.Command{ Name: "hash-object", Flags: []git.Option{ git.ValueFlag{Name: "--path", Value: path}, @@ -149,7 +149,7 @@ func (repo *Repo) WriteTag( content := strings.NewReader(tagBuf) cmd, err := repo.Exec(ctx, - git.SubCmd{ + git.Command{ Name: "mktag", }, git.WithStdin(content), @@ -190,7 +190,7 @@ func (repo *Repo) ReadObject(ctx context.Context, oid git.ObjectID) ([]byte, err stdout := &bytes.Buffer{} stderr := &bytes.Buffer{} cmd, err := repo.Exec(ctx, - git.SubCmd{ + git.Command{ Name: "cat-file", Flags: []git.Option{git.Flag{Name: "-p"}}, Args: []string{oid.String()}, @@ -273,7 +273,7 @@ func (repo *Repo) IsAncestor(ctx context.Context, parent, child git.Revision) (b stderr := &bytes.Buffer{} if err := repo.ExecAndWait(ctx, - git.SubCmd{ + git.Command{ Name: "merge-base", Flags: []git.Option{git.Flag{Name: "--is-ancestor"}}, Args: []string{parent.String(), child.String()}, diff --git a/internal/git/localrepo/refs.go b/internal/git/localrepo/refs.go index 0c8e4a29a..61bc2237a 100644 --- a/internal/git/localrepo/refs.go +++ b/internal/git/localrepo/refs.go @@ -42,7 +42,7 @@ func (repo *Repo) ResolveRevision(ctx context.Context, revision git.Revision) (g var stdout bytes.Buffer if err := repo.ExecAndWait(ctx, - git.SubCmd{ + git.Command{ Name: "rev-parse", Flags: []git.Option{git.Flag{Name: "--verify"}}, Args: []string{revision.String()}, @@ -107,7 +107,7 @@ func (repo *Repo) getReferences(ctx context.Context, limit uint, patterns ...str flags = append(flags, git.Flag{Name: fmt.Sprintf("--count=%d", limit)}) } - cmd, err := repo.Exec(ctx, git.SubCmd{ + cmd, err := repo.Exec(ctx, git.Command{ Name: "for-each-ref", Flags: flags, Args: patterns, @@ -155,7 +155,7 @@ func (repo *Repo) UpdateRef(ctx context.Context, reference git.ReferenceName, ne var stderr bytes.Buffer if err := repo.ExecAndWait(ctx, - git.SubCmd{ + git.Command{ Name: "update-ref", Flags: []git.Option{git.Flag{Name: "-z"}, git.Flag{Name: "--stdin"}}, }, @@ -264,7 +264,7 @@ func (repo *Repo) GetRemoteReferences(ctx context.Context, remote string, opts . stdout := &bytes.Buffer{} stderr := &bytes.Buffer{} if err := repo.ExecAndWait(ctx, - git.SubCmd{ + git.Command{ Name: "ls-remote", Flags: []git.Option{ git.Flag{Name: "--refs"}, @@ -374,7 +374,7 @@ func (repo *Repo) GetDefaultBranch(ctx context.Context) (git.ReferenceName, erro func (repo *Repo) headReference(ctx context.Context) (git.ReferenceName, error) { var headRef []byte - cmd, err := repo.Exec(ctx, git.SubCmd{ + cmd, err := repo.Exec(ctx, git.Command{ Name: "rev-parse", Flags: []git.Option{git.Flag{Name: "--symbolic-full-name"}}, Args: []string{"HEAD"}, diff --git a/internal/git/localrepo/refs_test.go b/internal/git/localrepo/refs_test.go index 7a9bafcc0..a98009fdf 100644 --- a/internal/git/localrepo/refs_test.go +++ b/internal/git/localrepo/refs_test.go @@ -613,7 +613,7 @@ func TestRepo_SetDefaultBranch_errors(t *testing.T) { <-ch var stderr bytes.Buffer - err = repo.ExecAndWait(ctx, git.SubCmd{ + err = repo.ExecAndWait(ctx, git.Command{ Name: "symbolic-ref", Args: []string{"HEAD", "refs/heads/otherbranch"}, }, git.WithRefTxHook(repo), git.WithStderr(&stderr)) diff --git a/internal/git/localrepo/remote.go b/internal/git/localrepo/remote.go index 236ef3363..4e264ba9e 100644 --- a/internal/git/localrepo/remote.go +++ b/internal/git/localrepo/remote.go @@ -95,7 +95,7 @@ func (repo *Repo) FetchRemote(ctx context.Context, remoteName string, opts Fetch commandOptions = append(commandOptions, opts.CommandOptions...) cmd, err := repo.gitCmdFactory.New(ctx, repo, - git.SubCmd{ + git.Command{ Name: "fetch", Flags: opts.buildFlags(), Args: []string{remoteName}, @@ -155,7 +155,7 @@ func (repo *Repo) FetchInternal( commandOptions = append(commandOptions, opts.CommandOptions...) if err := repo.ExecAndWait(ctx, - git.SubCmd{ + git.Command{ Name: "fetch", Flags: opts.buildFlags(), Args: append( @@ -250,7 +250,7 @@ func (repo *Repo) Push(ctx context.Context, remote string, refspecs []string, op stderr := &bytes.Buffer{} if err := repo.ExecAndWait(ctx, - git.SubCmd{ + git.Command{ Name: "push", Flags: flags, Args: append([]string{remote}, refspecs...), diff --git a/internal/git/localrepo/repo.go b/internal/git/localrepo/repo.go index 1d1790b3a..557f25b59 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.SubCmd, opts ...git.CmdOpt) (*command.Command, error) { +func (repo *Repo) Exec(ctx context.Context, cmd git.Command, 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.SubCmd, opts ...git.CmdOpt) error { +func (repo *Repo) ExecAndWait(ctx context.Context, cmd git.Command, opts ...git.CmdOpt) error { command, err := repo.Exec(ctx, cmd, opts...) if err != nil { return err @@ -194,7 +194,7 @@ func (repo *Repo) Size(ctx context.Context, opts ...RepoSizeOption) (int64, erro ) if err := repo.ExecAndWait(ctx, - git.SubCmd{ + git.Command{ Name: "rev-list", Flags: options, }, diff --git a/internal/git/log/last_commit.go b/internal/git/log/last_commit.go index eacc030cb..6287d522f 100644 --- a/internal/git/log/last_commit.go +++ b/internal/git/log/last_commit.go @@ -22,7 +22,7 @@ func LastCommitForPath( path string, options *gitalypb.GlobalOptions, ) (*gitalypb.GitCommit, error) { - cmd, err := gitCmdFactory.New(ctx, repo, git.SubCmd{ + cmd, err := gitCmdFactory.New(ctx, repo, git.Command{ Name: "log", Flags: []git.Option{git.Flag{Name: "--format=%H"}, git.Flag{Name: "--max-count=1"}}, Args: []string{revision.String()}, @@ -47,7 +47,7 @@ func GitLogCommand(ctx context.Context, gitCmdFactory git.CommandFactory, repo r args[i] = revision.String() } - return gitCmdFactory.New(ctx, repo, git.SubCmd{ + return gitCmdFactory.New(ctx, repo, git.Command{ Name: "log", Flags: append([]git.Option{git.Flag{Name: "--pretty=%H"}}, extraArgs...), Args: args, diff --git a/internal/git/lstree/list_entries.go b/internal/git/lstree/list_entries.go index 24156c7a7..fa40720fe 100644 --- a/internal/git/lstree/list_entries.go +++ b/internal/git/lstree/list_entries.go @@ -51,7 +51,7 @@ func ListEntries( } var stderr bytes.Buffer - cmd, err := repo.Exec(ctx, git.SubCmd{ + cmd, err := repo.Exec(ctx, git.Command{ Name: "ls-tree", Args: []string{fmt.Sprintf("%s:%s", treeish, cfg.RelativePath)}, Flags: flags, diff --git a/internal/git/object_id.go b/internal/git/object_id.go index 4d53eeb4f..0649aea5d 100644 --- a/internal/git/object_id.go +++ b/internal/git/object_id.go @@ -85,7 +85,7 @@ func ObjectHashByProto(format gitalypb.ObjectFormat) (ObjectHash, error) { func DetectObjectHash(ctx context.Context, repoExecutor RepositoryExecutor) (ObjectHash, error) { var stdout, stderr bytes.Buffer - if err := repoExecutor.ExecAndWait(ctx, SubCmd{ + if err := repoExecutor.ExecAndWait(ctx, Command{ Name: "rev-parse", Flags: []Option{ Flag{"--show-object-format"}, diff --git a/internal/git/objectpool/create.go b/internal/git/objectpool/create.go index ea8616a77..1117825f8 100644 --- a/internal/git/objectpool/create.go +++ b/internal/git/objectpool/create.go @@ -53,7 +53,7 @@ func Create( var stderr bytes.Buffer cmd, err := gitCmdFactory.NewWithoutRepo(ctx, - git.SubCmd{ + git.Command{ Name: "clone", Flags: []git.Option{ git.Flag{Name: "--quiet"}, diff --git a/internal/git/objectpool/fetch.go b/internal/git/objectpool/fetch.go index 54451c0c9..23f3d02d1 100644 --- a/internal/git/objectpool/fetch.go +++ b/internal/git/objectpool/fetch.go @@ -64,7 +64,7 @@ func (o *ObjectPool) FetchFromOrigin(ctx context.Context, origin *localrepo.Repo var stderr bytes.Buffer if err := o.Repo.ExecAndWait(ctx, - git.SubCmd{ + git.Command{ Name: "fetch", Flags: []git.Option{ git.Flag{Name: "--quiet"}, @@ -127,7 +127,7 @@ func (o *ObjectPool) pruneReferences(ctx context.Context, origin *localrepo.Repo // Instead we ask for a dry-run, parse the output and queue up every reference into a // git-update-ref(1) process. While ugly, it works around the performance issues. prune, err := o.Repo.Exec(ctx, - git.SubCmd{ + git.Command{ Name: "remote", Action: "prune", Args: []string{"origin"}, @@ -242,7 +242,7 @@ const danglingObjectNamespace = "refs/dangling/" // an object is still used anywhere, so the only safe thing to do is to // assume that every object _is_ used. func (o *ObjectPool) rescueDanglingObjects(ctx context.Context) (returnedErr error) { - fsck, err := o.Repo.Exec(ctx, git.SubCmd{ + fsck, err := o.Repo.Exec(ctx, git.Command{ Name: "fsck", Flags: []git.Option{git.Flag{Name: "--connectivity-only"}, git.Flag{Name: "--dangling"}}, }) @@ -313,7 +313,7 @@ func (o *ObjectPool) logStats(ctx context.Context, logger *logrus.Entry) error { } fields["repository_info"] = repoInfo - forEachRef, err := o.Repo.Exec(ctx, git.SubCmd{ + forEachRef, err := o.Repo.Exec(ctx, git.Command{ Name: "for-each-ref", Flags: []git.Option{git.Flag{Name: "--format=%(objecttype)%00%(refname)"}}, Args: []string{"refs/"}, diff --git a/internal/git/reference.go b/internal/git/reference.go index 225231188..01506f65c 100644 --- a/internal/git/reference.go +++ b/internal/git/reference.go @@ -130,7 +130,7 @@ func NewSymbolicReference(name ReferenceName, target string) Reference { // well-formed using git-check-ref-format func CheckRefFormat(ctx context.Context, gitCmdFactory CommandFactory, refName string) (bool, error) { cmd, err := gitCmdFactory.NewWithoutRepo(ctx, - SubCmd{ + Command{ Name: "check-ref-format", Args: []string{refName}, }, diff --git a/internal/git/repository.go b/internal/git/repository.go index 767e25bc1..7af7b4ac9 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 SubCmd, opts ...CmdOpt) (*command.Command, error) - ExecAndWait(ctx context.Context, cmd SubCmd, opts ...CmdOpt) error + Exec(ctx context.Context, cmd Command, opts ...CmdOpt) (*command.Command, error) + ExecAndWait(ctx context.Context, cmd Command, opts ...CmdOpt) error GitVersion(ctx context.Context) (Version, error) ObjectHash(ctx context.Context) (ObjectHash, error) } diff --git a/internal/git/updateref/updateref.go b/internal/git/updateref/updateref.go index 2f65c3b56..2f4f24a25 100644 --- a/internal/git/updateref/updateref.go +++ b/internal/git/updateref/updateref.go @@ -185,7 +185,7 @@ func New(ctx context.Context, repo git.RepositoryExecutor, opts ...UpdaterOpt) ( var stderr bytes.Buffer cmd, err := repo.Exec(ctx, - git.SubCmd{ + git.Command{ Name: "update-ref", Flags: cmdFlags, }, diff --git a/internal/gitaly/linguist/linguist.go b/internal/gitaly/linguist/linguist.go index 0bd9bfd46..4b227d427 100644 --- a/internal/gitaly/linguist/linguist.go +++ b/internal/gitaly/linguist/linguist.go @@ -188,7 +188,7 @@ func (inst *Instance) needsFullRecalculation(ctx context.Context, cachedID, comm return true, nil } - err := inst.repo.ExecAndWait(ctx, git.SubCmd{ + err := inst.repo.ExecAndWait(ctx, git.Command{ Name: "diff", Flags: []git.Option{git.Flag{Name: "--quiet"}}, Args: []string{fmt.Sprintf("%v..%v", cachedID, commitID)}, diff --git a/internal/gitaly/service/blob/lfs_pointers_test.go b/internal/gitaly/service/blob/lfs_pointers_test.go index 18edf9746..5ff60c722 100644 --- a/internal/gitaly/service/blob/lfs_pointers_test.go +++ b/internal/gitaly/service/blob/lfs_pointers_test.go @@ -266,7 +266,7 @@ size 12345` // repository's normal object directory. repo := localrepo.NewTestRepo(t, cfg, repoProto) var buffer, stderr bytes.Buffer - err = repo.ExecAndWait(ctx, git.SubCmd{ + err = repo.ExecAndWait(ctx, git.Command{ Name: "hash-object", Flags: []git.Option{ git.Flag{Name: "-w"}, diff --git a/internal/gitaly/service/cleanup/internalrefs/cleaner.go b/internal/gitaly/service/cleanup/internalrefs/cleaner.go index 14b5f2b02..8aacd73f3 100644 --- a/internal/gitaly/service/cleanup/internalrefs/cleaner.go +++ b/internal/gitaly/service/cleanup/internalrefs/cleaner.go @@ -138,7 +138,7 @@ func buildLookupTable(ctx context.Context, repo git.RepositoryExecutor) (map[str internalRefPrefixes = append(internalRefPrefixes, refPrefix) } - cmd, err := repo.Exec(ctx, git.SubCmd{ + cmd, err := repo.Exec(ctx, git.Command{ Name: "for-each-ref", Flags: []git.Option{git.ValueFlag{Name: "--format", Value: "%(objectname) %(refname)"}}, Args: internalRefPrefixes, diff --git a/internal/gitaly/service/commit/count_commits.go b/internal/gitaly/service/commit/count_commits.go index f5508ab65..e63984745 100644 --- a/internal/gitaly/service/commit/count_commits.go +++ b/internal/gitaly/service/commit/count_commits.go @@ -20,7 +20,7 @@ func (s *server) CountCommits(ctx context.Context, in *gitalypb.CountCommitsRequ return nil, structerr.NewInvalidArgument("%w", err) } - subCmd := git.SubCmd{Name: "rev-list", Flags: []git.Option{git.Flag{Name: "--count"}}} + subCmd := git.Command{Name: "rev-list", Flags: []git.Option{git.Flag{Name: "--count"}}} if in.GetAll() { subCmd.Flags = append(subCmd.Flags, git.Flag{Name: "--all"}) diff --git a/internal/gitaly/service/commit/count_diverging_commits.go b/internal/gitaly/service/commit/count_diverging_commits.go index e00461cc9..ca71d2ecf 100644 --- a/internal/gitaly/service/commit/count_diverging_commits.go +++ b/internal/gitaly/service/commit/count_diverging_commits.go @@ -48,8 +48,8 @@ func (s *server) validateCountDivergingCommitsRequest(req *gitalypb.CountDivergi return nil } -func buildRevListCountCmd(from, to string, maxCount int) git.SubCmd { - subCmd := git.SubCmd{ +func buildRevListCountCmd(from, to string, maxCount int) git.Command { + subCmd := git.Command{ Name: "rev-list", Flags: []git.Option{git.Flag{Name: "--count"}, git.Flag{Name: "--left-right"}}, Args: []string{fmt.Sprintf("%s...%s", from, to)}, diff --git a/internal/gitaly/service/commit/find_commit_test.go b/internal/gitaly/service/commit/find_commit_test.go index cb7c1deee..d946325d9 100644 --- a/internal/gitaly/service/commit/find_commit_test.go +++ b/internal/gitaly/service/commit/find_commit_test.go @@ -316,7 +316,7 @@ func benchmarkFindCommit(b *testing.B, withCache bool) { // get a list of revisions gitCmdFactory := gittest.NewCommandFactory(b, cfg) logCmd, err := gitCmdFactory.New(ctx, repo, - git.SubCmd{Name: "log", Flags: []git.Option{git.Flag{Name: "--format=format:%H"}}}) + git.Command{Name: "log", Flags: []git.Option{git.Flag{Name: "--format=format:%H"}}}) require.NoError(b, err) logScanner := bufio.NewScanner(logCmd) @@ -355,7 +355,7 @@ func TestFindCommitWithCache(t *testing.T) { gitCmdFactory := gittest.NewCommandFactory(t, cfg) logCmd, err := gitCmdFactory.New(ctx, gittest.RewrittenRepository(t, ctx, cfg, repo), - git.SubCmd{Name: "log", Flags: []git.Option{git.Flag{Name: "--format=format:%H"}}}) + git.Command{Name: "log", Flags: []git.Option{git.Flag{Name: "--format=format:%H"}}}) require.NoError(t, err) logScanner := bufio.NewScanner(logCmd) diff --git a/internal/gitaly/service/commit/find_commits.go b/internal/gitaly/service/commit/find_commits.go index d436cee19..0b8bc7c1b 100644 --- a/internal/gitaly/service/commit/find_commits.go +++ b/internal/gitaly/service/commit/find_commits.go @@ -218,7 +218,7 @@ func streamCommits(getCommits *GetCommits, stream gitalypb.CommitService_FindCom return chunker.Flush() } -func getLogCommandSubCmd(req *gitalypb.FindCommitsRequest) git.SubCmd { +func getLogCommandSubCmd(req *gitalypb.FindCommitsRequest) git.Command { logFormatOption := "--format=%H" // To split the commits by '\x01' instead of '\n' if req.GetIncludeShortstat() { @@ -228,7 +228,7 @@ func getLogCommandSubCmd(req *gitalypb.FindCommitsRequest) git.SubCmd { logFormatOption += "%x00%(trailers:unfold,separator=%x00)" } - subCmd := git.SubCmd{Name: "log", Flags: []git.Option{git.Flag{Name: logFormatOption}}} + subCmd := git.Command{Name: "log", Flags: []git.Option{git.Flag{Name: logFormatOption}}} // We will perform the offset in Go because --follow doesn't play well with --skip. // See: https://gitlab.com/gitlab-org/gitlab-ce/issues/3574#note_3040520 diff --git a/internal/gitaly/service/commit/isancestor.go b/internal/gitaly/service/commit/isancestor.go index 7721d801e..1f3e268ac 100644 --- a/internal/gitaly/service/commit/isancestor.go +++ b/internal/gitaly/service/commit/isancestor.go @@ -42,7 +42,7 @@ func (s *server) commitIsAncestorName(ctx context.Context, repo *gitalypb.Reposi "childSha": childID, }).Debug("commitIsAncestor") - cmd, err := s.gitCmdFactory.New(ctx, repo, git.SubCmd{ + cmd, err := s.gitCmdFactory.New(ctx, repo, git.Command{ Name: "merge-base", Flags: []git.Option{git.Flag{Name: "--is-ancestor"}}, Args: []string{ancestorID, childID}, }) diff --git a/internal/gitaly/service/commit/languages.go b/internal/gitaly/service/commit/languages.go index 6970176a0..97f52f2f1 100644 --- a/internal/gitaly/service/commit/languages.go +++ b/internal/gitaly/service/commit/languages.go @@ -116,7 +116,7 @@ func (s *server) checkRevision(ctx context.Context, repo git.RepositoryExecutor, var stdout, stderr bytes.Buffer revParse, err := repo.Exec(ctx, - git.SubCmd{Name: "rev-parse", Args: []string{revision}}, + git.Command{Name: "rev-parse", Args: []string{revision}}, git.WithStdout(&stdout), git.WithStderr(&stderr), ) @@ -137,7 +137,7 @@ func (s *server) checkRevision(ctx context.Context, repo git.RepositoryExecutor, } func (s *server) disambiguateRevision(ctx context.Context, repo git.RepositoryExecutor, revision string) (string, error) { - cmd, err := repo.Exec(ctx, git.SubCmd{ + cmd, err := repo.Exec(ctx, git.Command{ Name: "for-each-ref", Flags: []git.Option{git.Flag{Name: "--format=%(refname)"}}, Args: []string{"**/" + revision}, diff --git a/internal/gitaly/service/commit/list_files.go b/internal/gitaly/service/commit/list_files.go index d97c95a9c..cc9b52ff7 100644 --- a/internal/gitaly/service/commit/list_files.go +++ b/internal/gitaly/service/commit/list_files.go @@ -69,7 +69,7 @@ func validateListFilesRequest(in *gitalypb.ListFilesRequest) error { } func (s *server) listFiles(repo git.RepositoryExecutor, revision string, stream gitalypb.CommitService_ListFilesServer) error { - cmd, err := repo.Exec(stream.Context(), git.SubCmd{ + cmd, err := repo.Exec(stream.Context(), git.Command{ Name: "ls-tree", Flags: []git.Option{ git.Flag{Name: "-z"}, diff --git a/internal/gitaly/service/commit/list_last_commits_for_tree.go b/internal/gitaly/service/commit/list_last_commits_for_tree.go index 9269e41a3..4e2d69151 100644 --- a/internal/gitaly/service/commit/list_last_commits_for_tree.go +++ b/internal/gitaly/service/commit/list_last_commits_for_tree.go @@ -115,7 +115,7 @@ func (s *server) newLSTreeParser(in *gitalypb.ListLastCommitsForTreeRequest, str } opts := git.ConvertGlobalOptions(in.GetGlobalOptions()) - cmd, err := s.gitCmdFactory.New(stream.Context(), in.GetRepository(), git.SubCmd{ + cmd, err := s.gitCmdFactory.New(stream.Context(), in.GetRepository(), git.Command{ Name: "ls-tree", Flags: []git.Option{git.Flag{Name: "-z"}, git.Flag{Name: "--full-name"}}, Args: []string{in.GetRevision(), path}, diff --git a/internal/gitaly/service/commit/raw_blame.go b/internal/gitaly/service/commit/raw_blame.go index 220152f04..a11a77594 100644 --- a/internal/gitaly/service/commit/raw_blame.go +++ b/internal/gitaly/service/commit/raw_blame.go @@ -30,7 +30,7 @@ func (s *server) RawBlame(in *gitalypb.RawBlameRequest, stream gitalypb.CommitSe flags = append(flags, git.ValueFlag{Name: "-L", Value: blameRange}) } - cmd, err := s.gitCmdFactory.New(ctx, in.Repository, git.SubCmd{ + cmd, err := s.gitCmdFactory.New(ctx, in.Repository, git.Command{ Name: "blame", Flags: flags, Args: []string{revision}, diff --git a/internal/gitaly/service/commit/stats.go b/internal/gitaly/service/commit/stats.go index f38772d15..59e52996b 100644 --- a/internal/gitaly/service/commit/stats.go +++ b/internal/gitaly/service/commit/stats.go @@ -55,7 +55,7 @@ func (s *server) commitStats(ctx context.Context, in *gitalypb.CommitStatsReques args = append(args, commit.Id+"^", commit.Id) } - cmd, err := repo.Exec(ctx, git.SubCmd{ + cmd, err := repo.Exec(ctx, git.Command{ Name: "diff", Flags: []git.Option{git.Flag{Name: "--numstat"}}, Args: args, diff --git a/internal/gitaly/service/conflicts/resolve_conflicts_test.go b/internal/gitaly/service/conflicts/resolve_conflicts_test.go index 026ae1afd..f4a89660c 100644 --- a/internal/gitaly/service/conflicts/resolve_conflicts_test.go +++ b/internal/gitaly/service/conflicts/resolve_conflicts_test.go @@ -458,7 +458,7 @@ func TestResolveConflictsIdenticalContent(t *testing.T) { } var conflictContents bytes.Buffer - err = repo.ExecAndWait(ctx, git.SubCmd{ + err = repo.ExecAndWait(ctx, git.Command{ Name: "merge-file", Flags: []git.Option{ git.Flag{Name: "--quiet"}, diff --git a/internal/gitaly/service/diff/commit.go b/internal/gitaly/service/diff/commit.go index 343b03c8f..3624a4873 100644 --- a/internal/gitaly/service/diff/commit.go +++ b/internal/gitaly/service/diff/commit.go @@ -36,7 +36,7 @@ func (s *server) CommitDiff(in *gitalypb.CommitDiffRequest, stream gitalypb.Diff ignoreWhitespaceChange := in.GetIgnoreWhitespaceChange() paths := in.GetPaths() - cmd := git.SubCmd{ + cmd := git.Command{ Name: "diff", Flags: []git.Option{ git.Flag{Name: "--patch"}, @@ -135,7 +135,7 @@ func (s *server) CommitDelta(in *gitalypb.CommitDeltaRequest, stream gitalypb.Di rightSha := in.RightCommitId paths := in.GetPaths() - cmd := git.SubCmd{ + cmd := git.Command{ Name: "diff", Flags: []git.Option{ git.Flag{Name: "--raw"}, @@ -211,7 +211,7 @@ func validateRequest(in requestWithLeftRightCommitIds) error { return nil } -func (s *server) eachDiff(ctx context.Context, repo *gitalypb.Repository, subCmd git.SubCmd, limits diff.Limits, callback func(*diff.Diff) error) error { +func (s *server) eachDiff(ctx context.Context, repo *gitalypb.Repository, subCmd git.Command, 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/diff/find_changed_paths.go b/internal/gitaly/service/diff/find_changed_paths.go index 94f8edbda..cd024a07a 100644 --- a/internal/gitaly/service/diff/find_changed_paths.go +++ b/internal/gitaly/service/diff/find_changed_paths.go @@ -54,7 +54,7 @@ func (s *server) FindChangedPaths(in *gitalypb.FindChangedPathsRequest, stream g requests[i] = str } - cmd, err := s.gitCmdFactory.New(stream.Context(), in.Repository, git.SubCmd{ + cmd, err := s.gitCmdFactory.New(stream.Context(), in.Repository, git.Command{ Name: "diff-tree", Flags: []git.Option{ git.Flag{Name: "-z"}, diff --git a/internal/gitaly/service/diff/numstat.go b/internal/gitaly/service/diff/numstat.go index 32925e803..952dc74ea 100644 --- a/internal/gitaly/service/diff/numstat.go +++ b/internal/gitaly/service/diff/numstat.go @@ -19,7 +19,7 @@ func (s *server) DiffStats(in *gitalypb.DiffStatsRequest, stream gitalypb.DiffSe } var batch []*gitalypb.DiffStats - cmd, err := s.gitCmdFactory.New(stream.Context(), in.Repository, git.SubCmd{ + cmd, err := s.gitCmdFactory.New(stream.Context(), in.Repository, git.Command{ Name: "diff", Flags: []git.Option{git.Flag{Name: "--numstat"}, git.Flag{Name: "-z"}}, Args: []string{in.LeftCommitId, in.RightCommitId}, diff --git a/internal/gitaly/service/diff/raw.go b/internal/gitaly/service/diff/raw.go index 960dd4e7c..8f985e7fb 100644 --- a/internal/gitaly/service/diff/raw.go +++ b/internal/gitaly/service/diff/raw.go @@ -15,7 +15,7 @@ func (s *server) RawDiff(in *gitalypb.RawDiffRequest, stream gitalypb.DiffServic return structerr.NewInvalidArgument("%w", err) } - subCmd := git.SubCmd{ + subCmd := git.Command{ Name: "diff", Flags: []git.Option{git.Flag{Name: "--full-index"}}, Args: []string{in.LeftCommitId, in.RightCommitId}, @@ -33,7 +33,7 @@ func (s *server) RawPatch(in *gitalypb.RawPatchRequest, stream gitalypb.DiffServ return structerr.NewInvalidArgument("%w", err) } - subCmd := git.SubCmd{ + subCmd := git.Command{ Name: "format-patch", Flags: []git.Option{git.Flag{Name: "--stdout"}, git.ValueFlag{Name: "--signature", Value: "GitLab"}}, Args: []string{in.LeftCommitId + ".." + in.RightCommitId}, @@ -46,7 +46,7 @@ func (s *server) RawPatch(in *gitalypb.RawPatchRequest, stream gitalypb.DiffServ return sendRawOutput(stream.Context(), s.gitCmdFactory, in.Repository, sw, subCmd) } -func sendRawOutput(ctx context.Context, gitCmdFactory git.CommandFactory, repo *gitalypb.Repository, sender io.Writer, subCmd git.SubCmd) error { +func sendRawOutput(ctx context.Context, gitCmdFactory git.CommandFactory, repo *gitalypb.Repository, sender io.Writer, subCmd git.Command) error { cmd, err := gitCmdFactory.New(ctx, repo, subCmd) if err != nil { return structerr.NewInternal("cmd: %w", err) diff --git a/internal/gitaly/service/hook/pack_objects.go b/internal/gitaly/service/hook/pack_objects.go index 9730b3337..83a7a986b 100644 --- a/internal/gitaly/service/hook/pack_objects.go +++ b/internal/gitaly/service/hook/pack_objects.go @@ -331,8 +331,8 @@ func (p *packObjectsArgs) globals() []git.GlobalOption { return globals } -func (p *packObjectsArgs) subcmd() git.SubCmd { - sc := git.SubCmd{ +func (p *packObjectsArgs) subcmd() git.Command { + sc := git.Command{ Name: "pack-objects", Flags: []git.Option{git.Flag{Name: "--stdout"}}, } diff --git a/internal/gitaly/service/objectpool/alternates.go b/internal/gitaly/service/objectpool/alternates.go index e1e540feb..0bdc788b1 100644 --- a/internal/gitaly/service/objectpool/alternates.go +++ b/internal/gitaly/service/objectpool/alternates.go @@ -210,7 +210,7 @@ func (s *server) removeAlternatesIfOk(ctx context.Context, repo *localrepo.Repo, // The choice here of git rev-list is for performance reasons. // git fsck --connectivity-only performed badly for large // repositories. The reasons are detailed in https://lore.kernel.org/git/9304B938-4A59-456B-B091-DBBCAA1823B2@gmail.com/ - cmd, err = repo.Exec(ctx, git.SubCmd{ + cmd, err = repo.Exec(ctx, git.Command{ Name: "rev-list", Flags: []git.Option{ git.Flag{Name: "--objects"}, @@ -219,7 +219,7 @@ func (s *server) removeAlternatesIfOk(ctx context.Context, repo *localrepo.Repo, }, }) } else { - cmd, err = repo.Exec(ctx, git.SubCmd{ + cmd, err = repo.Exec(ctx, git.Command{ Name: "fsck", Flags: []git.Option{git.Flag{Name: "--connectivity-only"}}, }, git.WithConfig(git.ConfigPair{ diff --git a/internal/gitaly/service/objectpool/reduplicate.go b/internal/gitaly/service/objectpool/reduplicate.go index e12c89717..438b39d92 100644 --- a/internal/gitaly/service/objectpool/reduplicate.go +++ b/internal/gitaly/service/objectpool/reduplicate.go @@ -15,7 +15,7 @@ func (s *server) ReduplicateRepository(ctx context.Context, req *gitalypb.Redupl return nil, helper.ErrInvalidArgumentf("%w", err) } - cmd, err := s.gitCmdFactory.New(ctx, repository, git.SubCmd{ + cmd, err := s.gitCmdFactory.New(ctx, repository, git.Command{ Name: "repack", Flags: []git.Option{ git.Flag{Name: "--quiet"}, diff --git a/internal/gitaly/service/operations/apply_patch.go b/internal/gitaly/service/operations/apply_patch.go index 6f90027ba..a46196581 100644 --- a/internal/gitaly/service/operations/apply_patch.go +++ b/internal/gitaly/service/operations/apply_patch.go @@ -110,7 +110,7 @@ func (s *Server) userApplyPatch(ctx context.Context, header *gitalypb.UserApplyP var stdout, stderr bytes.Buffer if err := repo.ExecAndWait(ctx, - git.SubCmd{ + git.Command{ Name: "am", Flags: []git.Option{ git.Flag{Name: "--quiet"}, @@ -145,7 +145,7 @@ func (s *Server) userApplyPatch(ctx context.Context, header *gitalypb.UserApplyP var revParseStdout, revParseStderr bytes.Buffer if err := repo.ExecAndWait(ctx, - git.SubCmd{ + git.Command{ Name: "rev-parse", Flags: []git.Option{ git.Flag{Name: "--quiet"}, @@ -212,7 +212,7 @@ func (s *Server) addWorktree(ctx context.Context, repo *localrepo.Repo, worktree } var stderr bytes.Buffer - if err := repo.ExecAndWait(ctx, git.SubCmd{ + if err := repo.ExecAndWait(ctx, git.Command{ Name: "worktree", Action: "add", Flags: flags, @@ -226,7 +226,7 @@ func (s *Server) addWorktree(ctx context.Context, repo *localrepo.Repo, worktree func (s *Server) removeWorktree(ctx context.Context, repo *gitalypb.Repository, worktreeName string) error { cmd, err := s.gitCmdFactory.New(ctx, repo, - git.SubCmd{ + git.Command{ Name: "worktree", Action: "remove", Flags: []git.Option{git.Flag{Name: "--force"}}, diff --git a/internal/gitaly/service/ref/find_all_tags_test.go b/internal/gitaly/service/ref/find_all_tags_test.go index 3cde6d743..9ebcc258c 100644 --- a/internal/gitaly/service/ref/find_all_tags_test.go +++ b/internal/gitaly/service/ref/find_all_tags_test.go @@ -593,12 +593,12 @@ func TestFindAllTags_sorted(t *testing.T) { require.NoError(t, err) require.NoError(t, repo.UpdateRef(ctx, "refs/tags/annotated", annotatedTagID, git.ObjectHashSHA1.ZeroOID)) - require.NoError(t, repo.ExecAndWait(ctx, git.SubCmd{ + require.NoError(t, repo.ExecAndWait(ctx, git.Command{ Name: "tag", Args: []string{"v1.2.0", headCommit.Id}, }, git.WithDisabledHooks())) - require.NoError(t, repo.ExecAndWait(ctx, git.SubCmd{ + require.NoError(t, repo.ExecAndWait(ctx, git.Command{ Name: "tag", Args: []string{"v1.10.0", headCommit.Id}, }, git.WithDisabledHooks())) diff --git a/internal/gitaly/service/ref/find_tag.go b/internal/gitaly/service/ref/find_tag.go index 00e288b8d..1316420bb 100644 --- a/internal/gitaly/service/ref/find_tag.go +++ b/internal/gitaly/service/ref/find_tag.go @@ -68,7 +68,7 @@ func parseTagLine(ctx context.Context, objectReader catfile.ObjectContentReader, func (s *server) findTag(ctx context.Context, repo git.RepositoryExecutor, tagName []byte) (*gitalypb.Tag, error) { tagCmd, err := repo.Exec(ctx, - git.SubCmd{ + git.Command{ Name: "tag", Flags: []git.Option{ git.Flag{Name: "-l"}, git.ValueFlag{Name: "--format", Value: tagFormat}, diff --git a/internal/gitaly/service/ref/pack_refs.go b/internal/gitaly/service/ref/pack_refs.go index 3a4cabb39..d4c0685fb 100644 --- a/internal/gitaly/service/ref/pack_refs.go +++ b/internal/gitaly/service/ref/pack_refs.go @@ -27,7 +27,7 @@ func validatePackRefsRequest(in *gitalypb.PackRefsRequest) error { } func (s *server) packRefs(ctx context.Context, repository repository.GitRepo) error { - cmd, err := s.gitCmdFactory.New(ctx, repository, git.SubCmd{ + cmd, err := s.gitCmdFactory.New(ctx, repository, git.Command{ Name: "pack-refs", Flags: []git.Option{git.Flag{Name: "--all"}}, }) diff --git a/internal/gitaly/service/ref/refexists.go b/internal/gitaly/service/ref/refexists.go index 36cc79549..c8210930e 100644 --- a/internal/gitaly/service/ref/refexists.go +++ b/internal/gitaly/service/ref/refexists.go @@ -32,7 +32,7 @@ func (s *server) RefExists(ctx context.Context, in *gitalypb.RefExistsRequest) ( } func (s *server) refExists(ctx context.Context, repo *gitalypb.Repository, ref string) (bool, error) { - cmd, err := s.gitCmdFactory.New(ctx, repo, git.SubCmd{ + cmd, err := s.gitCmdFactory.New(ctx, repo, git.Command{ Name: "show-ref", Flags: []git.Option{git.Flag{Name: "--verify"}, git.Flag{Name: "--quiet"}}, Args: []string{ref}, diff --git a/internal/gitaly/service/ref/refnames.go b/internal/gitaly/service/ref/refnames.go index 8ac27f6fa..4f9b45755 100644 --- a/internal/gitaly/service/ref/refnames.go +++ b/internal/gitaly/service/ref/refnames.go @@ -79,7 +79,7 @@ func (s *server) listRefNames(ctx context.Context, chunker *chunk.Chunker, prefi flags = append(flags, git.Flag{Name: arg}) } - cmd, err := s.gitCmdFactory.New(ctx, repo, git.SubCmd{ + cmd, err := s.gitCmdFactory.New(ctx, repo, git.Command{ Name: "for-each-ref", Flags: flags, Args: []string{prefix}, diff --git a/internal/gitaly/service/ref/refs.go b/internal/gitaly/service/ref/refs.go index 757fa86c4..455367d28 100644 --- a/internal/gitaly/service/ref/refs.go +++ b/internal/gitaly/service/ref/refs.go @@ -47,7 +47,7 @@ func (s *server) findRefs(ctx context.Context, writer lines.Sender, repo git.Rep options = append(options, opts.cmdArgs...) } - cmd, err := repo.Exec(ctx, git.SubCmd{ + cmd, err := repo.Exec(ctx, git.Command{ Name: "for-each-ref", Flags: options, Args: patterns, diff --git a/internal/gitaly/service/remote/find_remote_repository.go b/internal/gitaly/service/remote/find_remote_repository.go index 39785b8c9..6e904ea21 100644 --- a/internal/gitaly/service/remote/find_remote_repository.go +++ b/internal/gitaly/service/remote/find_remote_repository.go @@ -16,7 +16,7 @@ func (s *server) FindRemoteRepository(ctx context.Context, req *gitalypb.FindRem } cmd, err := s.gitCmdFactory.NewWithoutRepo(ctx, - git.SubCmd{ + git.Command{ Name: "ls-remote", Args: []string{ req.GetRemote(), diff --git a/internal/gitaly/service/remote/find_remote_root_ref.go b/internal/gitaly/service/remote/find_remote_root_ref.go index bf2086536..edf6a8a00 100644 --- a/internal/gitaly/service/remote/find_remote_root_ref.go +++ b/internal/gitaly/service/remote/find_remote_root_ref.go @@ -46,7 +46,7 @@ func (s *server) findRemoteRootRefCmd(ctx context.Context, request *gitalypb.Fin } return s.gitCmdFactory.New(ctx, request.Repository, - git.SubCmd{ + git.Command{ Name: "remote", Action: "show", Args: []string{"inmemory"}, diff --git a/internal/gitaly/service/remote/update_remote_mirror_test.go b/internal/gitaly/service/remote/update_remote_mirror_test.go index 10f4d1024..ba13a5930 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.SubCmd, ...git.CmdOpt) (*command.Command, error) + newFunc func(context.Context, repository.GitRepo, git.Command, ...git.CmdOpt) (*command.Command, error) } -func (w commandFactoryWrapper) New(ctx context.Context, repo repository.GitRepo, sc git.SubCmd, opts ...git.CmdOpt) (*command.Command, error) { +func (w commandFactoryWrapper) New(ctx context.Context, repo repository.GitRepo, sc git.Command, opts ...git.CmdOpt) (*command.Command, error) { return w.newFunc(ctx, repo, sc, opts...) } @@ -329,7 +329,7 @@ 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.SubCmd, opts ...git.CmdOpt) (*command.Command, error) { + newFunc: func(ctx context.Context, repo repository.GitRepo, sc git.Command, opts ...git.CmdOpt) (*command.Command, error) { if sc.Name == "push" { // This is really hacky: we extract the // remote name from the subcommands @@ -342,7 +342,7 @@ func TestUpdateRemoteMirror(t *testing.T) { // Make the branch diverge on the remote before actually performing the pushes the RPC // is attempting to perform to simulate a ref diverging after the RPC has performed // its checks. - cmd, err := original.New(ctx, repo, git.SubCmd{ + cmd, err := original.New(ctx, repo, git.Command{ Name: "push", Flags: []git.Option{git.Flag{Name: "--force"}}, Args: []string{remoteName, "refs/heads/non-diverging:refs/heads/diverging"}, @@ -428,7 +428,7 @@ func TestUpdateRemoteMirror(t *testing.T) { firstPush := true return commandFactoryWrapper{ CommandFactory: original, - newFunc: func(ctx context.Context, repo repository.GitRepo, sc git.SubCmd, opts ...git.CmdOpt) (*command.Command, error) { + newFunc: func(ctx context.Context, repo repository.GitRepo, sc git.Command, opts ...git.CmdOpt) (*command.Command, error) { if sc.Name == "push" && firstPush { firstPush = false args, err := sc.CommandArgs() diff --git a/internal/gitaly/service/repository/archive.go b/internal/gitaly/service/repository/archive.go index c1136f7b5..622d7c3e8 100644 --- a/internal/gitaly/service/repository/archive.go +++ b/internal/gitaly/service/repository/archive.go @@ -223,7 +223,7 @@ func (s *server) handleArchive(ctx context.Context, p archiveParams) error { config = append(config, smudgeGitConfig) } - archiveCommand, err := s.gitCmdFactory.New(ctx, p.in.GetRepository(), git.SubCmd{ + archiveCommand, err := s.gitCmdFactory.New(ctx, p.in.GetRepository(), git.Command{ Name: "archive", Flags: []git.Option{git.ValueFlag{Name: "--format", Value: p.format}, git.ValueFlag{Name: "--prefix", Value: p.in.GetPrefix() + "/"}}, Args: args, diff --git a/internal/gitaly/service/repository/calculate_checksum.go b/internal/gitaly/service/repository/calculate_checksum.go index 3e02712ac..bc080e20b 100644 --- a/internal/gitaly/service/repository/calculate_checksum.go +++ b/internal/gitaly/service/repository/calculate_checksum.go @@ -24,7 +24,7 @@ func (s *server) CalculateChecksum(ctx context.Context, in *gitalypb.CalculateCh return nil, err } - cmd, err := s.gitCmdFactory.New(ctx, repo, git.SubCmd{Name: "show-ref", Flags: []git.Option{git.Flag{Name: "--head"}}}) + cmd, err := s.gitCmdFactory.New(ctx, repo, git.Command{Name: "show-ref", Flags: []git.Option{git.Flag{Name: "--head"}}}) if err != nil { return nil, helper.ErrInternalf("gitCommand: %w", err) } @@ -54,7 +54,7 @@ func (s *server) CalculateChecksum(ctx context.Context, in *gitalypb.CalculateCh func (s *server) isValidRepo(ctx context.Context, repo *gitalypb.Repository) bool { stdout := &bytes.Buffer{} cmd, err := s.gitCmdFactory.New(ctx, repo, - git.SubCmd{ + git.Command{ Name: "rev-parse", Flags: []git.Option{ git.Flag{Name: "--is-bare-repository"}, diff --git a/internal/gitaly/service/repository/create_bundle.go b/internal/gitaly/service/repository/create_bundle.go index f4573c29a..d0ce8ecf7 100644 --- a/internal/gitaly/service/repository/create_bundle.go +++ b/internal/gitaly/service/repository/create_bundle.go @@ -22,7 +22,7 @@ func (s *server) CreateBundle(req *gitalypb.CreateBundleRequest, stream gitalypb return helper.ErrInternalf("running Cleanup on repository: %w", err) } - cmd, err := s.gitCmdFactory.New(ctx, repository, git.SubCmd{ + cmd, err := s.gitCmdFactory.New(ctx, repository, git.Command{ Name: "bundle", Action: "create", Flags: []git.Option{git.OutputToStdout, git.Flag{Name: "--all"}}, diff --git a/internal/gitaly/service/repository/create_bundle_from_ref_list.go b/internal/gitaly/service/repository/create_bundle_from_ref_list.go index 1e483b2c7..768b2aae3 100644 --- a/internal/gitaly/service/repository/create_bundle_from_ref_list.go +++ b/internal/gitaly/service/repository/create_bundle_from_ref_list.go @@ -49,7 +49,7 @@ func (s *server) CreateBundleFromRefList(stream gitalypb.RepositoryService_Creat repo := s.localrepo(repository) cmd, err := repo.Exec(ctx, - git.SubCmd{ + git.Command{ Name: "bundle", Action: "create", Flags: []git.Option{ diff --git a/internal/gitaly/service/repository/create_fork.go b/internal/gitaly/service/repository/create_fork.go index ac4701dd6..d67916832 100644 --- a/internal/gitaly/service/repository/create_fork.go +++ b/internal/gitaly/service/repository/create_fork.go @@ -40,7 +40,7 @@ func (s *server) CreateFork(ctx context.Context, req *gitalypb.CreateForkRequest // no easy choice but to use git-clone(1). var stderr strings.Builder cmd, err := s.gitCmdFactory.NewWithoutRepo(ctx, - git.SubCmd{ + git.Command{ Name: "clone", Flags: []git.Option{ git.Flag{Name: "--bare"}, diff --git a/internal/gitaly/service/repository/create_repository_from_bundle.go b/internal/gitaly/service/repository/create_repository_from_bundle.go index 5bcce0174..9db3ecef6 100644 --- a/internal/gitaly/service/repository/create_repository_from_bundle.go +++ b/internal/gitaly/service/repository/create_repository_from_bundle.go @@ -58,7 +58,7 @@ func (s *server) CreateRepositoryFromBundle(stream gitalypb.RepositoryService_Cr if err := s.createRepository(ctx, repo, func(repo *gitalypb.Repository) error { var stderr bytes.Buffer - cmd, err := s.gitCmdFactory.New(ctx, repo, git.SubCmd{ + cmd, err := s.gitCmdFactory.New(ctx, repo, git.Command{ Name: "fetch", Flags: []git.Option{ git.Flag{Name: "--quiet"}, diff --git a/internal/gitaly/service/repository/create_repository_from_url.go b/internal/gitaly/service/repository/create_repository_from_url.go index 06d84170a..eb86bddb1 100644 --- a/internal/gitaly/service/repository/create_repository_from_url.go +++ b/internal/gitaly/service/repository/create_repository_from_url.go @@ -74,7 +74,7 @@ func (s *server) cloneFromURLCommand( } return s.gitCmdFactory.NewWithoutRepo(ctx, - git.SubCmd{ + git.Command{ Name: "clone", Flags: cloneFlags, Args: []string{urlString, repositoryFullPath}, diff --git a/internal/gitaly/service/repository/fetch_bundle.go b/internal/gitaly/service/repository/fetch_bundle.go index 452f86d16..8f234156e 100644 --- a/internal/gitaly/service/repository/fetch_bundle.go +++ b/internal/gitaly/service/repository/fetch_bundle.go @@ -106,7 +106,7 @@ func (s *server) updateHeadFromBundle(ctx context.Context, repo *localrepo.Repo, // findBundleHead tries to extract HEAD and its target from a bundle. Returns // nil when HEAD is not found. func (s *server) findBundleHead(ctx context.Context, repo git.RepositoryExecutor, bundlePath string) (*git.Reference, error) { - cmd, err := repo.Exec(ctx, git.SubCmd{ + cmd, err := repo.Exec(ctx, git.Command{ Name: "bundle", Action: "list-heads", Args: []string{bundlePath, "HEAD"}, diff --git a/internal/gitaly/service/repository/fetch_remote.go b/internal/gitaly/service/repository/fetch_remote.go index c1d50f796..f6d2656f2 100644 --- a/internal/gitaly/service/repository/fetch_remote.go +++ b/internal/gitaly/service/repository/fetch_remote.go @@ -112,7 +112,7 @@ func (s *server) FetchRemote(ctx context.Context, req *gitalypb.FetchRemoteReque if err := transaction.RunOnContext(ctx, func(tx txinfo.Transaction) error { hash := voting.NewVoteHash() - if err := repo.ExecAndWait(ctx, git.SubCmd{ + if err := repo.ExecAndWait(ctx, git.Command{ Name: "for-each-ref", }, git.WithStdout(hash)); err != nil { return fmt.Errorf("cannot compute references vote: %w", err) diff --git a/internal/gitaly/service/repository/fsck.go b/internal/gitaly/service/repository/fsck.go index 005eb52e0..15a759a7c 100644 --- a/internal/gitaly/service/repository/fsck.go +++ b/internal/gitaly/service/repository/fsck.go @@ -18,7 +18,7 @@ func (s *server) Fsck(ctx context.Context, req *gitalypb.FsckRequest) (*gitalypb var stdout, stderr bytes.Buffer cmd, err := s.gitCmdFactory.New(ctx, repository, - git.SubCmd{Name: "fsck"}, + git.Command{Name: "fsck"}, git.WithStdout(&stdout), git.WithStderr(&stderr), ) diff --git a/internal/gitaly/service/repository/fullpath.go b/internal/gitaly/service/repository/fullpath.go index e16c0b39f..1bb4ccc20 100644 --- a/internal/gitaly/service/repository/fullpath.go +++ b/internal/gitaly/service/repository/fullpath.go @@ -46,7 +46,7 @@ func (s *server) FullPath(ctx context.Context, request *gitalypb.FullPathRequest repo := s.localrepo(repository) var stdout strings.Builder - err := repo.ExecAndWait(ctx, git.SubCmd{ + err := repo.ExecAndWait(ctx, git.Command{ Name: "config", Args: []string{fullPathKey}, }, git.WithStdout(&stdout)) diff --git a/internal/gitaly/service/repository/gc.go b/internal/gitaly/service/repository/gc.go index befe0dad5..87aca6b99 100644 --- a/internal/gitaly/service/repository/gc.go +++ b/internal/gitaly/service/repository/gc.go @@ -70,7 +70,7 @@ func (s *server) gc(ctx context.Context, in *gitalypb.GarbageCollectRequest) err } cmd, err := s.gitCmdFactory.New(ctx, in.GetRepository(), - git.SubCmd{Name: "gc", Flags: flags}, + git.Command{Name: "gc", Flags: flags}, git.WithConfig(config...), ) if err != nil { @@ -165,7 +165,7 @@ func (s *server) fixRef(ctx context.Context, repo *localrepo.Repo, objectInfoRea } // The name is a valid sha, recreate the ref - return repo.ExecAndWait(ctx, git.SubCmd{ + return repo.ExecAndWait(ctx, git.Command{ Name: "update-ref", Args: []string{name, sha}, }, git.WithRefTxHook(repo)) diff --git a/internal/gitaly/service/repository/license.go b/internal/gitaly/service/repository/license.go index 5809329c9..86ffee1c4 100644 --- a/internal/gitaly/service/repository/license.go +++ b/internal/gitaly/service/repository/license.go @@ -184,7 +184,7 @@ func (f *gitFiler) ReadFile(path string) ([]byte, error) { func (f *gitFiler) ReadDir(string) ([]filer.File, error) { var stderr bytes.Buffer - cmd, err := f.repo.Exec(f.ctx, git.SubCmd{ + cmd, err := f.repo.Exec(f.ctx, git.Command{ Name: "ls-tree", Flags: []git.Option{ git.Flag{Name: "-z"}, diff --git a/internal/gitaly/service/repository/merge_base.go b/internal/gitaly/service/repository/merge_base.go index 42121fafc..257aabd71 100644 --- a/internal/gitaly/service/repository/merge_base.go +++ b/internal/gitaly/service/repository/merge_base.go @@ -26,7 +26,7 @@ func (s *server) FindMergeBase(ctx context.Context, req *gitalypb.FindMergeBaseR } cmd, err := s.gitCmdFactory.New(ctx, repository, - git.SubCmd{ + git.Command{ Name: "merge-base", Args: revisions, }, diff --git a/internal/gitaly/service/repository/midx.go b/internal/gitaly/service/repository/midx.go index c74a46d00..1fcfe0119 100644 --- a/internal/gitaly/service/repository/midx.go +++ b/internal/gitaly/service/repository/midx.go @@ -65,7 +65,7 @@ func (s *server) safeMidxCommand(ctx context.Context, repo repository.GitRepo, c func (s *server) midxWrite(ctx context.Context, repo repository.GitRepo) error { cmd, err := s.gitCmdFactory.New(ctx, repo, - git.SubCmd{ + git.Command{ Name: "multi-pack-index", Action: "write", }, @@ -100,7 +100,7 @@ func (s *server) midxVerify(ctx context.Context, repo repository.GitRepo) error ctxlogger := ctxlogrus.Extract(ctx) cmd, err := s.gitCmdFactory.New(ctx, repo, - git.SubCmd{ + git.Command{ Name: "multi-pack-index", Action: "verify", }, @@ -136,7 +136,7 @@ func (s *server) midxRewrite(ctx context.Context, repo repository.GitRepo) error func (s *server) midxExpire(ctx context.Context, repo repository.GitRepo) error { cmd, err := s.gitCmdFactory.New(ctx, repo, - git.SubCmd{ + git.Command{ Name: "multi-pack-index", Action: "expire", }, @@ -177,7 +177,7 @@ func (s *server) midxRepack(ctx context.Context, repo repository.GitRepo) error // will only be respected if git version is >=2.28.0. // Bitmap index 'repack.writeBitmaps' is not yet supported. cmd, err := s.gitCmdFactory.New(ctx, repo, - git.SubCmd{ + git.Command{ Name: "multi-pack-index", Action: "repack", Flags: []git.Option{ diff --git a/internal/gitaly/service/repository/prune_unreachable_objects.go b/internal/gitaly/service/repository/prune_unreachable_objects.go index 7d7a85f19..4fb0b927d 100644 --- a/internal/gitaly/service/repository/prune_unreachable_objects.go +++ b/internal/gitaly/service/repository/prune_unreachable_objects.go @@ -32,7 +32,7 @@ func (s *server) PruneUnreachableObjects( return nil, err } - if err := repo.ExecAndWait(ctx, git.SubCmd{ + if err := repo.ExecAndWait(ctx, git.Command{ Name: "prune", Flags: []git.Option{ git.ValueFlag{Name: "--expire", Value: "30.minutes.ago"}, diff --git a/internal/gitaly/service/repository/raw_changes.go b/internal/gitaly/service/repository/raw_changes.go index 510b1f137..23f9ff1dc 100644 --- a/internal/gitaly/service/repository/raw_changes.go +++ b/internal/gitaly/service/repository/raw_changes.go @@ -69,7 +69,7 @@ func (s *server) getRawChanges(stream gitalypb.RepositoryService_GetRawChangesSe ctx := stream.Context() - diffCmd, err := repo.Exec(ctx, git.SubCmd{ + diffCmd, err := repo.Exec(ctx, git.Command{ Name: "diff", Flags: []git.Option{git.Flag{Name: "--raw"}, git.Flag{Name: "-z"}}, Args: []string{from, to}, diff --git a/internal/gitaly/service/repository/search_files.go b/internal/gitaly/service/repository/search_files.go index 9f4924390..bc11fe030 100644 --- a/internal/gitaly/service/repository/search_files.go +++ b/internal/gitaly/service/repository/search_files.go @@ -33,7 +33,7 @@ func (s *server) SearchFilesByContent(req *gitalypb.SearchFilesByContentRequest, ctx := stream.Context() cmd, err := s.gitCmdFactory.New(ctx, req.GetRepository(), - git.SubCmd{Name: "grep", Flags: []git.Option{ + git.Command{Name: "grep", Flags: []git.Option{ git.Flag{Name: "--ignore-case"}, git.Flag{Name: "-I"}, git.Flag{Name: "--line-number"}, @@ -117,7 +117,7 @@ func (s *server) SearchFilesByName(req *gitalypb.SearchFilesByNameRequest, strea cmd, err := s.gitCmdFactory.New( ctx, req.GetRepository(), - git.SubCmd{Name: "ls-tree", Flags: []git.Option{ + git.Command{Name: "ls-tree", Flags: []git.Option{ git.Flag{Name: "--full-tree"}, git.Flag{Name: "--name-status"}, git.Flag{Name: "-r"}, diff --git a/internal/gitaly/service/repository/util.go b/internal/gitaly/service/repository/util.go index c33206bc7..0eb7e31af 100644 --- a/internal/gitaly/service/repository/util.go +++ b/internal/gitaly/service/repository/util.go @@ -20,7 +20,7 @@ import ( ) func (s *server) removeOriginInRepo(ctx context.Context, repository *gitalypb.Repository) error { - cmd, err := s.gitCmdFactory.New(ctx, repository, git.SubCmd{Name: "remote", Args: []string{"remove", "origin"}}, git.WithRefTxHook(repository)) + cmd, err := s.gitCmdFactory.New(ctx, repository, git.Command{Name: "remote", Args: []string{"remove", "origin"}}, git.WithRefTxHook(repository)) if err != nil { return fmt.Errorf("remote cmd start: %w", err) } @@ -96,7 +96,7 @@ func (s *server) createRepository( } stderr := &bytes.Buffer{} - cmd, err := s.gitCmdFactory.NewWithoutRepo(ctx, git.SubCmd{ + cmd, err := s.gitCmdFactory.NewWithoutRepo(ctx, git.Command{ Name: "init", Flags: append([]git.Option{ git.Flag{Name: "--bare"}, diff --git a/internal/gitaly/service/repository/util_test.go b/internal/gitaly/service/repository/util_test.go index 8f086e3cc..167ae53ba 100644 --- a/internal/gitaly/service/repository/util_test.go +++ b/internal/gitaly/service/repository/util_test.go @@ -74,7 +74,7 @@ func TestCreateRepository(t *testing.T) { seed: func(t *testing.T, repo *gitalypb.Repository, _ string) error { // We're using the command factory on purpose here to assert that we // can execute regular Git commands on the temporary repository. - cmd, err := gitCmdFactory.New(ctx, repo, git.SubCmd{ + cmd, err := gitCmdFactory.New(ctx, repo, git.Command{ Name: "config", Args: []string{"custom.key", "value"}, }) diff --git a/internal/gitaly/service/smarthttp/inforefs.go b/internal/gitaly/service/smarthttp/inforefs.go index 72ff3bb89..ef04ad60a 100644 --- a/internal/gitaly/service/smarthttp/inforefs.go +++ b/internal/gitaly/service/smarthttp/inforefs.go @@ -70,7 +70,7 @@ func (s *server) handleInfoRefs(ctx context.Context, service, repoPath string, r } cmdOpts = append(cmdOpts, git.WithConfig(config...)) - cmd, err := s.gitCmdFactory.New(ctx, req.GetRepository(), git.SubCmd{ + cmd, err := s.gitCmdFactory.New(ctx, req.GetRepository(), git.Command{ Name: service, Flags: []git.Option{git.Flag{Name: "--stateless-rpc"}, git.Flag{Name: "--advertise-refs"}}, Args: []string{repoPath}, diff --git a/internal/gitaly/service/smarthttp/receive_pack.go b/internal/gitaly/service/smarthttp/receive_pack.go index a44469f5c..bb3b5624e 100644 --- a/internal/gitaly/service/smarthttp/receive_pack.go +++ b/internal/gitaly/service/smarthttp/receive_pack.go @@ -51,7 +51,7 @@ func (s *server) PostReceivePack(stream gitalypb.SmartHTTPService_PostReceivePac } cmd, err := s.gitCmdFactory.New(ctx, req.GetRepository(), - git.SubCmd{ + git.Command{ Name: "receive-pack", Flags: []git.Option{git.Flag{Name: "--stateless-rpc"}}, Args: []string{repoPath}, diff --git a/internal/gitaly/service/smarthttp/upload_pack.go b/internal/gitaly/service/smarthttp/upload_pack.go index af64f5b03..488242f9f 100644 --- a/internal/gitaly/service/smarthttp/upload_pack.go +++ b/internal/gitaly/service/smarthttp/upload_pack.go @@ -146,7 +146,7 @@ func (s *server) runUploadPack(ctx context.Context, req basicPostUploadPackReque git.WithPackObjectsHookEnv(req.GetRepository(), "http"), } - cmd, err := s.gitCmdFactory.New(ctx, req.GetRepository(), git.SubCmd{ + cmd, err := s.gitCmdFactory.New(ctx, req.GetRepository(), git.Command{ Name: "upload-pack", Flags: []git.Option{git.Flag{Name: "--stateless-rpc"}}, Args: []string{repoPath}, diff --git a/internal/gitaly/service/ssh/monitor_stdin_command.go b/internal/gitaly/service/ssh/monitor_stdin_command.go index f3bf43a70..6e04bbdb1 100644 --- a/internal/gitaly/service/ssh/monitor_stdin_command.go +++ b/internal/gitaly/service/ssh/monitor_stdin_command.go @@ -17,7 +17,7 @@ func monitorStdinCommand( repo *gitalypb.Repository, stdin io.Reader, stdout, stderr io.Writer, - sc git.SubCmd, + sc git.Command, opts ...git.CmdOpt, ) (*command.Command, *pktline.ReadMonitor, error) { stdinPipe, monitor, cleanup, err := pktline.NewReadMonitor(ctx, stdin) diff --git a/internal/gitaly/service/ssh/receive_pack.go b/internal/gitaly/service/ssh/receive_pack.go index 0dc444564..bf4a63de5 100644 --- a/internal/gitaly/service/ssh/receive_pack.go +++ b/internal/gitaly/service/ssh/receive_pack.go @@ -77,7 +77,7 @@ func (s *server) sshReceivePack(stream gitalypb.SSHService_SSHReceivePackServer, } cmd, err := s.gitCmdFactory.New(ctx, req.GetRepository(), - git.SubCmd{ + git.Command{ Name: "receive-pack", Args: []string{repoPath}, }, diff --git a/internal/gitaly/service/ssh/upload_archive.go b/internal/gitaly/service/ssh/upload_archive.go index e85d03b90..8996014cf 100644 --- a/internal/gitaly/service/ssh/upload_archive.go +++ b/internal/gitaly/service/ssh/upload_archive.go @@ -53,7 +53,7 @@ func (s *server) sshUploadArchive(stream gitalypb.SSHService_SSHUploadArchiveSer return stream.Send(&gitalypb.SSHUploadArchiveResponse{Stderr: p}) }) - cmd, monitor, err := monitorStdinCommand(ctx, s.gitCmdFactory, req.GetRepository(), stdin, stdout, stderr, git.SubCmd{ + cmd, monitor, err := monitorStdinCommand(ctx, s.gitCmdFactory, req.GetRepository(), stdin, stdout, stderr, git.Command{ Name: "upload-archive", Args: []string{repoPath}, }) diff --git a/internal/gitaly/service/ssh/upload_pack.go b/internal/gitaly/service/ssh/upload_pack.go index c1f0ca3a4..8ae224ed9 100644 --- a/internal/gitaly/service/ssh/upload_pack.go +++ b/internal/gitaly/service/ssh/upload_pack.go @@ -128,7 +128,7 @@ func (s *server) sshUploadPack(rpcContext context.Context, req sshUploadPackRequ var stderrBuilder strings.Builder stderr = io.MultiWriter(stderr, &stderrBuilder) - cmd, monitor, err := monitorStdinCommand(ctx, s.gitCmdFactory, repo, stdin, stdout, stderr, git.SubCmd{ + cmd, monitor, err := monitorStdinCommand(ctx, s.gitCmdFactory, repo, stdin, stdout, stderr, git.Command{ Name: "upload-pack", Args: []string{repoPath}, }, commandOpts...) |