Skip to content

Commit 4c8d5a5

Browse files
committed
revert change from command.go
1 parent 390dbf8 commit 4c8d5a5

File tree

1 file changed

+15
-38
lines changed

1 file changed

+15
-38
lines changed

modules/git/command.go

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var (
2222
// GlobalCommandArgs global command args for external package setting
2323
GlobalCommandArgs []string
2424

25-
// DefaultCommandExecutionTimeout default command execution timeout duration
25+
// defaultCommandExecutionTimeout default command execution timeout duration
2626
defaultCommandExecutionTimeout = 360 * time.Second
2727
)
2828

@@ -109,71 +109,48 @@ func (c *Command) RunInDirTimeoutEnvFullPipeline(env []string, timeout time.Dura
109109
// RunInDirTimeoutEnvFullPipelineFunc executes the command in given directory with given timeout,
110110
// it pipes stdout and stderr to given io.Writer and passes in an io.Reader as stdin. Between cmd.Start and cmd.Wait the passed in function is run.
111111
func (c *Command) RunInDirTimeoutEnvFullPipelineFunc(env []string, timeout time.Duration, dir string, stdout, stderr io.Writer, stdin io.Reader, fn func(context.Context, context.CancelFunc) error) error {
112-
return c.RunWithContext(&RunContext{
113-
Env: env,
114-
Timeout: timeout,
115-
Dir: dir,
116-
Stdout: stdout,
117-
Stderr: stderr,
118-
Stdin: stdin,
119-
CancelFunc: fn,
120-
})
121-
}
122-
123-
// RunContext represents parameters to run the command
124-
type RunContext struct {
125-
Env []string
126-
Timeout time.Duration
127-
Dir string
128-
Stdout, Stderr io.Writer
129-
Stdin io.Reader
130-
CancelFunc func(context.Context, context.CancelFunc) error
131-
}
132-
133-
// RunWithContext run the command with context
134-
func (c *Command) RunWithContext(rc *RunContext) error {
135-
if rc.Timeout == -1 {
136-
rc.Timeout = defaultCommandExecutionTimeout
112+
if timeout == -1 {
113+
timeout = defaultCommandExecutionTimeout
137114
}
138115

139-
if len(rc.Dir) == 0 {
116+
if len(dir) == 0 {
140117
log(c.String())
141118
} else {
142-
log("%s: %v", rc.Dir, c)
119+
log("%s: %v", dir, c)
143120
}
144121

145-
ctx, cancel := context.WithTimeout(c.parentContext, rc.Timeout)
122+
ctx, cancel := context.WithTimeout(c.parentContext, timeout)
146123
defer cancel()
147124

148125
cmd := exec.CommandContext(ctx, c.name, c.args...)
149-
if rc.Env == nil {
126+
if env == nil {
150127
cmd.Env = append(os.Environ(), fmt.Sprintf("LC_ALL=%s", DefaultLocale))
151128
} else {
152-
cmd.Env = rc.Env
129+
cmd.Env = env
153130
cmd.Env = append(cmd.Env, fmt.Sprintf("LC_ALL=%s", DefaultLocale))
154131
}
155132

156133
// TODO: verify if this is still needed in golang 1.15
157134
if goVersionLessThan115 {
158135
cmd.Env = append(cmd.Env, "GODEBUG=asyncpreemptoff=1")
159136
}
160-
cmd.Dir = rc.Dir
161-
cmd.Stdout = rc.Stdout
162-
cmd.Stderr = rc.Stderr
163-
cmd.Stdin = rc.Stdin
137+
cmd.Dir = dir
138+
cmd.Stdout = stdout
139+
cmd.Stderr = stderr
140+
cmd.Stdin = stdin
164141
if err := cmd.Start(); err != nil {
165142
return err
166143
}
167144

168145
desc := c.desc
169146
if desc == "" {
170-
desc = fmt.Sprintf("%s %s %s [repo_path: %s]", GitExecutable, c.name, strings.Join(c.args, " "), rc.Dir)
147+
desc = fmt.Sprintf("%s %s %s [repo_path: %s]", GitExecutable, c.name, strings.Join(c.args, " "), dir)
171148
}
172149
pid := process.GetManager().Add(desc, cancel)
173150
defer process.GetManager().Remove(pid)
174151

175-
if rc.CancelFunc != nil {
176-
err := rc.CancelFunc(ctx, cancel)
152+
if fn != nil {
153+
err := fn(ctx, cancel)
177154
if err != nil {
178155
cancel()
179156
_ = cmd.Wait()

0 commit comments

Comments
 (0)