diff options
author | Martin Scholz <martin.scholz83@outlook.com> | 2022-02-11 13:47:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-11 13:47:22 +0100 |
commit | 26718a785ac49f17eab51ad0f5324d036b810f73 (patch) | |
tree | 9c8371e01460dacf8e65c88b3526e2123525c717 /modules/git/repo_compare.go | |
parent | 393ea86ae192325e45d7fac0fc6a277da8fb0fca (diff) | |
download | gitea-26718a785ac49f17eab51ad0f5324d036b810f73.tar.gz gitea-26718a785ac49f17eab51ad0f5324d036b810f73.zip |
Change git.cmd to RunWithContext (#18693)
Change all `cmd...Pipeline` commands to `cmd.RunWithContext`.
#18553
Co-authored-by: Martin Scholz <martin.scholz@versasec.com>
Diffstat (limited to 'modules/git/repo_compare.go')
-rw-r--r-- | modules/git/repo_compare.go | 55 |
1 files changed, 44 insertions, 11 deletions
diff --git a/modules/git/repo_compare.go b/modules/git/repo_compare.go index dddc158dcc..aa8015af14 100644 --- a/modules/git/repo_compare.go +++ b/modules/git/repo_compare.go @@ -147,13 +147,23 @@ func (repo *Repository) GetDiffNumChangedFiles(base, head string, directComparis } if err := NewCommand(repo.Ctx, "diff", "-z", "--name-only", base+separator+head). - RunInDirPipeline(repo.Path, w, stderr); err != nil { + RunWithContext(&RunContext{ + Timeout: -1, + Dir: repo.Path, + Stdout: w, + Stderr: stderr, + }); err != nil { if strings.Contains(stderr.String(), "no merge base") { // git >= 2.28 now returns an error if base and head have become unrelated. // previously it would return the results of git diff -z --name-only base head so let's try that... w = &lineCountWriter{} stderr.Reset() - if err = NewCommand(repo.Ctx, "diff", "-z", "--name-only", base, head).RunInDirPipeline(repo.Path, w, stderr); err == nil { + if err = NewCommand(repo.Ctx, "diff", "-z", "--name-only", base, head).RunWithContext(&RunContext{ + Timeout: -1, + Dir: repo.Path, + Stdout: w, + Stderr: stderr, + }); err == nil { return w.numLines, nil } } @@ -238,28 +248,46 @@ func (repo *Repository) GetDiffOrPatch(base, head string, w io.Writer, patch, bi // GetDiff generates and returns patch data between given revisions, optimized for human readability func (repo *Repository) GetDiff(base, head string, w io.Writer) error { - return NewCommand(repo.Ctx, "diff", "-p", base, head). - RunInDirPipeline(repo.Path, w, nil) + return NewCommand(repo.Ctx, "diff", "-p", base, head).RunWithContext(&RunContext{ + Timeout: -1, + Dir: repo.Path, + Stdout: w, + }) } // GetDiffBinary generates and returns patch data between given revisions, including binary diffs. func (repo *Repository) GetDiffBinary(base, head string, w io.Writer) error { if CheckGitVersionAtLeast("1.7.7") == nil { - return NewCommand(repo.Ctx, "diff", "-p", "--binary", "--histogram", base, head). - RunInDirPipeline(repo.Path, w, nil) + return NewCommand(repo.Ctx, "diff", "-p", "--binary", "--histogram", base, head).RunWithContext(&RunContext{ + Timeout: -1, + Dir: repo.Path, + Stdout: w, + }) } - return NewCommand(repo.Ctx, "diff", "-p", "--binary", "--patience", base, head). - RunInDirPipeline(repo.Path, w, nil) + return NewCommand(repo.Ctx, "diff", "-p", "--binary", "--patience", base, head).RunWithContext(&RunContext{ + Timeout: -1, + Dir: repo.Path, + Stdout: w, + }) } // GetPatch generates and returns format-patch data between given revisions, able to be used with `git apply` func (repo *Repository) GetPatch(base, head string, w io.Writer) error { stderr := new(bytes.Buffer) err := NewCommand(repo.Ctx, "format-patch", "--binary", "--stdout", base+"..."+head). - RunInDirPipeline(repo.Path, w, stderr) + RunWithContext(&RunContext{ + Timeout: -1, + Dir: repo.Path, + Stdout: w, + Stderr: stderr, + }) if err != nil && bytes.Contains(stderr.Bytes(), []byte("no merge base")) { return NewCommand(repo.Ctx, "format-patch", "--binary", "--stdout", base, head). - RunInDirPipeline(repo.Path, w, nil) + RunWithContext(&RunContext{ + Timeout: -1, + Dir: repo.Path, + Stdout: w, + }) } return err } @@ -268,7 +296,12 @@ func (repo *Repository) GetPatch(base, head string, w io.Writer) error { func (repo *Repository) GetDiffFromMergeBase(base, head string, w io.Writer) error { stderr := new(bytes.Buffer) err := NewCommand(repo.Ctx, "diff", "-p", "--binary", base+"..."+head). - RunInDirPipeline(repo.Path, w, stderr) + RunWithContext(&RunContext{ + Timeout: -1, + Dir: repo.Path, + Stdout: w, + Stderr: stderr, + }) if err != nil && bytes.Contains(stderr.Bytes(), []byte("no merge base")) { return repo.GetDiffBinary(base, head, w) } |