Skip to content

Commit f370b9b

Browse files
authored
Merge branch 'main' into lunny/fix_cancel_link
2 parents a9d7055 + 26718a7 commit f370b9b

32 files changed

+536
-161
lines changed

integrations/pull_merge_test.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,13 @@ func TestCantMergeUnrelated(t *testing.T) {
274274

275275
stdin := bytes.NewBufferString("Unrelated File")
276276
var stdout strings.Builder
277-
err = git.NewCommand(git.DefaultContext, "hash-object", "-w", "--stdin").RunInDirFullPipeline(path, &stdout, nil, stdin)
277+
err = git.NewCommand(git.DefaultContext, "hash-object", "-w", "--stdin").RunWithContext(&git.RunContext{
278+
Timeout: -1,
279+
Dir: path,
280+
Stdin: stdin,
281+
Stdout: &stdout,
282+
})
283+
278284
assert.NoError(t, err)
279285
sha := strings.TrimSpace(stdout.String())
280286

@@ -301,7 +307,14 @@ func TestCantMergeUnrelated(t *testing.T) {
301307
_, _ = messageBytes.WriteString("\n")
302308

303309
stdout.Reset()
304-
err = git.NewCommand(git.DefaultContext, "commit-tree", treeSha).RunInDirTimeoutEnvFullPipeline(env, -1, path, &stdout, nil, messageBytes)
310+
err = git.NewCommand(git.DefaultContext, "commit-tree", treeSha).
311+
RunWithContext(&git.RunContext{
312+
Env: env,
313+
Timeout: -1,
314+
Dir: path,
315+
Stdin: messageBytes,
316+
Stdout: &stdout,
317+
})
305318
assert.NoError(t, err)
306319
commitSha := strings.TrimSpace(stdout.String())
307320

modules/git/batch_reader.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ func EnsureValidGitRepository(ctx context.Context, repoPath string) error {
3434
stderr := strings.Builder{}
3535
err := NewCommand(ctx, "rev-parse").
3636
SetDescription(fmt.Sprintf("%s rev-parse [repo_path: %s]", GitExecutable, repoPath)).
37-
RunInDirFullPipeline(repoPath, nil, &stderr, nil)
37+
RunWithContext(&RunContext{
38+
Timeout: -1,
39+
Dir: repoPath,
40+
Stderr: &stderr,
41+
})
3842
if err != nil {
3943
return ConcatenateError(err, (&stderr).String())
4044
}
@@ -61,7 +65,13 @@ func CatFileBatchCheck(ctx context.Context, repoPath string) (WriteCloserError,
6165
stderr := strings.Builder{}
6266
err := NewCommand(ctx, "cat-file", "--batch-check").
6367
SetDescription(fmt.Sprintf("%s cat-file --batch-check [repo_path: %s] (%s:%d)", GitExecutable, repoPath, filename, line)).
64-
RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
68+
RunWithContext(&RunContext{
69+
Timeout: -1,
70+
Dir: repoPath,
71+
Stdin: batchStdinReader,
72+
Stdout: batchStdoutWriter,
73+
Stderr: &stderr,
74+
})
6575
if err != nil {
6676
_ = batchStdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
6777
_ = batchStdinReader.CloseWithError(ConcatenateError(err, (&stderr).String()))
@@ -100,7 +110,13 @@ func CatFileBatch(ctx context.Context, repoPath string) (WriteCloserError, *bufi
100110
stderr := strings.Builder{}
101111
err := NewCommand(ctx, "cat-file", "--batch").
102112
SetDescription(fmt.Sprintf("%s cat-file --batch [repo_path: %s] (%s:%d)", GitExecutable, repoPath, filename, line)).
103-
RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
113+
RunWithContext(&RunContext{
114+
Timeout: -1,
115+
Dir: repoPath,
116+
Stdin: batchStdinReader,
117+
Stdout: batchStdoutWriter,
118+
Stderr: &stderr,
119+
})
104120
if err != nil {
105121
_ = batchStdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
106122
_ = batchStdinReader.CloseWithError(ConcatenateError(err, (&stderr).String()))

modules/git/commit.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,12 @@ func GetCommitFileStatus(ctx context.Context, repoPath, commitID string) (*Commi
486486
stderr := new(bytes.Buffer)
487487
args := []string{"log", "--name-status", "-c", "--pretty=format:", "--parents", "--no-renames", "-z", "-1", commitID}
488488

489-
err := NewCommand(ctx, args...).RunInDirPipeline(repoPath, w, stderr)
489+
err := NewCommand(ctx, args...).RunWithContext(&RunContext{
490+
Timeout: -1,
491+
Dir: repoPath,
492+
Stdout: w,
493+
Stderr: stderr,
494+
})
490495
w.Close() // Close writer to exit parsing goroutine
491496
if err != nil {
492497
return nil, ConcatenateError(err, stderr.String())

modules/git/diff.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,12 @@ func GetAffectedFiles(repo *Repository, oldCommitID, newCommitID string, env []s
301301

302302
// Run `git diff --name-only` to get the names of the changed files
303303
err = NewCommand(repo.Ctx, "diff", "--name-only", oldCommitID, newCommitID).
304-
RunInDirTimeoutEnvFullPipelineFunc(env, -1, repo.Path,
305-
stdoutWriter, nil, nil,
306-
func(ctx context.Context, cancel context.CancelFunc) error {
304+
RunWithContext(&RunContext{
305+
Env: env,
306+
Timeout: -1,
307+
Dir: repo.Path,
308+
Stdout: stdoutWriter,
309+
PipelineFunc: func(ctx context.Context, cancel context.CancelFunc) error {
307310
// Close the writer end of the pipe to begin processing
308311
_ = stdoutWriter.Close()
309312
defer func() {
@@ -320,7 +323,8 @@ func GetAffectedFiles(repo *Repository, oldCommitID, newCommitID string, env []s
320323
affectedFiles = append(affectedFiles, path)
321324
}
322325
return scanner.Err()
323-
})
326+
},
327+
})
324328
if err != nil {
325329
log.Error("Unable to get affected files for commits from %s to %s in %s: %v", oldCommitID, newCommitID, repo.Path, err)
326330
}

modules/git/log_name_status.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ func LogNameStatusRepo(ctx context.Context, repository, head, treepath string, p
5555

5656
go func() {
5757
stderr := strings.Builder{}
58-
err := NewCommand(ctx, args...).RunInDirFullPipeline(repository, stdoutWriter, &stderr, nil)
58+
err := NewCommand(ctx, args...).RunWithContext(&RunContext{
59+
Timeout: -1,
60+
Dir: repository,
61+
Stdout: stdoutWriter,
62+
Stderr: &stderr,
63+
})
5964
if err != nil {
6065
_ = stdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
6166
} else {

modules/git/pipeline/catfile.go

+20-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ func CatFileBatchCheck(ctx context.Context, shasToCheckReader *io.PipeReader, ca
2727
stderr := new(bytes.Buffer)
2828
var errbuf strings.Builder
2929
cmd := git.NewCommand(ctx, "cat-file", "--batch-check")
30-
if err := cmd.RunInDirFullPipeline(tmpBasePath, catFileCheckWriter, stderr, shasToCheckReader); err != nil {
30+
if err := cmd.RunWithContext(&git.RunContext{
31+
Timeout: -1,
32+
Dir: tmpBasePath,
33+
Stdin: shasToCheckReader,
34+
Stdout: catFileCheckWriter,
35+
Stderr: stderr,
36+
}); err != nil {
3137
_ = catFileCheckWriter.CloseWithError(fmt.Errorf("git cat-file --batch-check [%s]: %v - %s", tmpBasePath, err, errbuf.String()))
3238
}
3339
}
@@ -40,7 +46,12 @@ func CatFileBatchCheckAllObjects(ctx context.Context, catFileCheckWriter *io.Pip
4046
stderr := new(bytes.Buffer)
4147
var errbuf strings.Builder
4248
cmd := git.NewCommand(ctx, "cat-file", "--batch-check", "--batch-all-objects")
43-
if err := cmd.RunInDirPipeline(tmpBasePath, catFileCheckWriter, stderr); err != nil {
49+
if err := cmd.RunWithContext(&git.RunContext{
50+
Timeout: -1,
51+
Dir: tmpBasePath,
52+
Stdout: catFileCheckWriter,
53+
Stderr: stderr,
54+
}); err != nil {
4455
log.Error("git cat-file --batch-check --batch-all-object [%s]: %v - %s", tmpBasePath, err, errbuf.String())
4556
err = fmt.Errorf("git cat-file --batch-check --batch-all-object [%s]: %v - %s", tmpBasePath, err, errbuf.String())
4657
_ = catFileCheckWriter.CloseWithError(err)
@@ -56,7 +67,13 @@ func CatFileBatch(ctx context.Context, shasToBatchReader *io.PipeReader, catFile
5667

5768
stderr := new(bytes.Buffer)
5869
var errbuf strings.Builder
59-
if err := git.NewCommand(ctx, "cat-file", "--batch").RunInDirFullPipeline(tmpBasePath, catFileBatchWriter, stderr, shasToBatchReader); err != nil {
70+
if err := git.NewCommand(ctx, "cat-file", "--batch").RunWithContext(&git.RunContext{
71+
Timeout: -1,
72+
Dir: tmpBasePath,
73+
Stdout: catFileBatchWriter,
74+
Stdin: shasToBatchReader,
75+
Stderr: stderr,
76+
}); err != nil {
6077
_ = shasToBatchReader.CloseWithError(fmt.Errorf("git rev-list [%s]: %v - %s", tmpBasePath, err, errbuf.String()))
6178
}
6279
}

modules/git/pipeline/lfs_nogogit.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ func FindLFSFile(repo *git.Repository, hash git.SHA1) ([]*LFSResult, error) {
5353

5454
go func() {
5555
stderr := strings.Builder{}
56-
err := git.NewCommand(repo.Ctx, "rev-list", "--all").RunInDirPipeline(repo.Path, revListWriter, &stderr)
56+
err := git.NewCommand(repo.Ctx, "rev-list", "--all").RunWithContext(&git.RunContext{
57+
Timeout: -1,
58+
Dir: repo.Path,
59+
Stdout: revListWriter,
60+
Stderr: &stderr,
61+
})
5762
if err != nil {
5863
_ = revListWriter.CloseWithError(git.ConcatenateError(err, (&stderr).String()))
5964
} else {

modules/git/pipeline/namerev.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ func NameRevStdin(ctx context.Context, shasToNameReader *io.PipeReader, nameRevS
2323

2424
stderr := new(bytes.Buffer)
2525
var errbuf strings.Builder
26-
if err := git.NewCommand(ctx, "name-rev", "--stdin", "--name-only", "--always").RunInDirFullPipeline(tmpBasePath, nameRevStdinWriter, stderr, shasToNameReader); err != nil {
26+
if err := git.NewCommand(ctx, "name-rev", "--stdin", "--name-only", "--always").RunWithContext(&git.RunContext{
27+
Timeout: -1,
28+
Dir: tmpBasePath,
29+
Stdout: nameRevStdinWriter,
30+
Stdin: shasToNameReader,
31+
Stderr: stderr,
32+
}); err != nil {
2733
_ = shasToNameReader.CloseWithError(fmt.Errorf("git name-rev [%s]: %v - %s", tmpBasePath, err, errbuf.String()))
2834
}
2935
}

modules/git/pipeline/revlist.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ func RevListAllObjects(ctx context.Context, revListWriter *io.PipeWriter, wg *sy
2525
stderr := new(bytes.Buffer)
2626
var errbuf strings.Builder
2727
cmd := git.NewCommand(ctx, "rev-list", "--objects", "--all")
28-
if err := cmd.RunInDirPipeline(basePath, revListWriter, stderr); err != nil {
28+
if err := cmd.RunWithContext(&git.RunContext{
29+
Timeout: -1,
30+
Dir: basePath,
31+
Stdout: revListWriter,
32+
Stderr: stderr,
33+
}); err != nil {
2934
log.Error("git rev-list --objects --all [%s]: %v - %s", basePath, err, errbuf.String())
3035
err = fmt.Errorf("git rev-list --objects --all [%s]: %v - %s", basePath, err, errbuf.String())
3136
_ = revListWriter.CloseWithError(err)
@@ -40,7 +45,12 @@ func RevListObjects(ctx context.Context, revListWriter *io.PipeWriter, wg *sync.
4045
stderr := new(bytes.Buffer)
4146
var errbuf strings.Builder
4247
cmd := git.NewCommand(ctx, "rev-list", "--objects", headSHA, "--not", baseSHA)
43-
if err := cmd.RunInDirPipeline(tmpBasePath, revListWriter, stderr); err != nil {
48+
if err := cmd.RunWithContext(&git.RunContext{
49+
Timeout: -1,
50+
Dir: tmpBasePath,
51+
Stdout: revListWriter,
52+
Stderr: stderr,
53+
}); err != nil {
4454
log.Error("git rev-list [%s]: %v - %s", tmpBasePath, err, errbuf.String())
4555
errChan <- fmt.Errorf("git rev-list [%s]: %v - %s", tmpBasePath, err, errbuf.String())
4656
}

modules/git/repo.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,13 @@ func Push(ctx context.Context, repoPath string, opts PushOptions) error {
204204
opts.Timeout = -1
205205
}
206206

207-
err := cmd.RunInDirTimeoutEnvPipeline(opts.Env, opts.Timeout, repoPath, &outbuf, &errbuf)
207+
err := cmd.RunWithContext(&RunContext{
208+
Env: opts.Env,
209+
Timeout: opts.Timeout,
210+
Dir: repoPath,
211+
Stdout: &outbuf,
212+
Stderr: &errbuf,
213+
})
208214
if err != nil {
209215
if strings.Contains(errbuf.String(), "non-fast-forward") {
210216
return &ErrPushOutOfDate{

modules/git/repo_archive.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ func (repo *Repository) CreateArchive(ctx context.Context, format ArchiveType, t
5757
)
5858

5959
var stderr strings.Builder
60-
err := NewCommand(ctx, args...).RunInDirPipeline(repo.Path, target, &stderr)
60+
err := NewCommand(ctx, args...).RunWithContext(&RunContext{
61+
Timeout: -1,
62+
Dir: repo.Path,
63+
Stdout: target,
64+
Stderr: &stderr,
65+
})
6166
if err != nil {
6267
return ConcatenateError(err, stderr.String())
6368
}

modules/git/repo_attribute.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ func (repo *Repository) CheckAttribute(opts CheckAttributeOpts) (map[string]map[
7676

7777
cmd := NewCommand(repo.Ctx, cmdArgs...)
7878

79-
if err := cmd.RunInDirTimeoutEnvPipeline(env, -1, repo.Path, stdOut, stdErr); err != nil {
79+
if err := cmd.RunWithContext(&RunContext{
80+
Env: env,
81+
Timeout: -1,
82+
Dir: repo.Path,
83+
Stdout: stdOut,
84+
Stderr: stdErr,
85+
}); err != nil {
8086
return nil, fmt.Errorf("failed to run check-attr: %v\n%s\n%s", err, stdOut.String(), stdErr.String())
8187
}
8288

@@ -182,9 +188,17 @@ func (c *CheckAttributeReader) Run() error {
182188
_ = c.Close()
183189
}()
184190
stdErr := new(bytes.Buffer)
185-
err := c.cmd.RunInDirTimeoutEnvFullPipelineFunc(c.env, -1, c.Repo.Path, c.stdOut, stdErr, c.stdinReader, func(_ context.Context, _ context.CancelFunc) error {
186-
close(c.running)
187-
return nil
191+
err := c.cmd.RunWithContext(&RunContext{
192+
Env: c.env,
193+
Timeout: -1,
194+
Dir: c.Repo.Path,
195+
Stdin: c.stdinReader,
196+
Stdout: c.stdOut,
197+
Stderr: stdErr,
198+
PipelineFunc: func(_ context.Context, _ context.CancelFunc) error {
199+
close(c.running)
200+
return nil
201+
},
188202
})
189203
if err != nil && c.ctx.Err() != nil && err.Error() != "signal: killed" {
190204
return fmt.Errorf("failed to run attr-check. Error: %w\nStderr: %s", err, stdErr.String())

modules/git/repo_branch_nogogit.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ func walkShowRef(ctx context.Context, repoPath, arg string, skip, limit int, wal
9696
if arg != "" {
9797
args = append(args, arg)
9898
}
99-
err := NewCommand(ctx, args...).RunInDirPipeline(repoPath, stdoutWriter, stderrBuilder)
99+
err := NewCommand(ctx, args...).RunWithContext(&RunContext{
100+
Timeout: -1,
101+
Dir: repoPath,
102+
Stdout: stdoutWriter,
103+
Stderr: stderrBuilder,
104+
})
100105
if err != nil {
101106
if stderrBuilder.Len() == 0 {
102107
_ = stdoutWriter.Close()

modules/git/repo_commit.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,12 @@ func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (
211211
err := NewCommand(repo.Ctx, "log", revision, "--follow",
212212
"--max-count="+strconv.Itoa(setting.Git.CommitsRangeSize*page),
213213
prettyLogFormat, "--", file).
214-
RunInDirPipeline(repo.Path, stdoutWriter, &stderr)
214+
RunWithContext(&RunContext{
215+
Timeout: -1,
216+
Dir: repo.Path,
217+
Stdout: stdoutWriter,
218+
Stderr: &stderr,
219+
})
215220
if err != nil {
216221
_ = stdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
217222
} else {

0 commit comments

Comments
 (0)