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-06-16 16:38:59 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-23 09:13:31 +0300
commitb4a7f8cc4892da19562b1928b7977f1447a4c177 (patch)
tree53d5a86d21f9a6affdec5bee87cae0b509de3026
parent296cebd9d2f567b28aa49a046b3cee29e1e0ca7c (diff)
git: Simplify construction of standard streams
Now that the command package accepts options, it becomes easier for us to pass standard streams to `New()` by just assembling them into an array of `command.Option`s, as well. Refactor the code to do so.
-rw-r--r--internal/git/command_factory.go7
-rw-r--r--internal/git/command_options.go11
2 files changed, 6 insertions, 12 deletions
diff --git a/internal/git/command_factory.go b/internal/git/command_factory.go
index 0e222c677..a18c9fd63 100644
--- a/internal/git/command_factory.go
+++ b/internal/git/command_factory.go
@@ -397,12 +397,7 @@ func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo repository.Gi
execCommand := exec.Command(execEnv.BinaryPath, args...)
execCommand.Dir = dir
- command, err := command.New(ctx, execCommand,
- command.WithStdin(config.stdin),
- command.WithStdout(config.stdout),
- command.WithStderr(config.stderr),
- command.WithEnvironment(env),
- )
+ command, err := command.New(ctx, execCommand, append(config.commandOpts, command.WithEnvironment(env))...)
if err != nil {
return nil, err
}
diff --git a/internal/git/command_options.go b/internal/git/command_options.go
index 44aecd810..ffa7e402c 100644
--- a/internal/git/command_options.go
+++ b/internal/git/command_options.go
@@ -9,6 +9,7 @@ import (
"regexp"
"strings"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/command"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/storage"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
@@ -168,9 +169,7 @@ func ConvertConfigOptions(options []string) ([]ConfigPair, error) {
type cmdCfg struct {
env []string
globals []GlobalOption
- stdin io.Reader
- stdout io.Writer
- stderr io.Writer
+ commandOpts []command.Option
hooksConfigured bool
}
@@ -181,7 +180,7 @@ type CmdOpt func(context.Context, config.Cfg, CommandFactory, *cmdCfg) error
// command suitable for `Write()`ing to.
func WithStdin(r io.Reader) CmdOpt {
return func(_ context.Context, _ config.Cfg, _ CommandFactory, c *cmdCfg) error {
- c.stdin = r
+ c.commandOpts = append(c.commandOpts, command.WithStdin(r))
return nil
}
}
@@ -189,7 +188,7 @@ func WithStdin(r io.Reader) CmdOpt {
// WithStdout sets the command's stdout.
func WithStdout(w io.Writer) CmdOpt {
return func(_ context.Context, _ config.Cfg, _ CommandFactory, c *cmdCfg) error {
- c.stdout = w
+ c.commandOpts = append(c.commandOpts, command.WithStdout(w))
return nil
}
}
@@ -197,7 +196,7 @@ func WithStdout(w io.Writer) CmdOpt {
// WithStderr sets the command's stderr.
func WithStderr(w io.Writer) CmdOpt {
return func(_ context.Context, _ config.Cfg, _ CommandFactory, c *cmdCfg) error {
- c.stderr = w
+ c.commandOpts = append(c.commandOpts, command.WithStderr(w))
return nil
}
}