summaryrefslogtreecommitdiffstats
path: root/modules/git/diff.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-01-23 13:57:52 +0800
committerGitHub <noreply@github.com>2022-01-23 00:57:52 -0500
commit35fdefc1ff253522f101ffb1337437b59676c302 (patch)
tree56f3556eb1ed153af37fb2e965db073272307d94 /modules/git/diff.go
parentf066b293accb8aed5809de87ae56140c90978d66 (diff)
downloadgitea-35fdefc1ff253522f101ffb1337437b59676c302.tar.gz
gitea-35fdefc1ff253522f101ffb1337437b59676c302.zip
Always use git command but not os.Command (#18363)
Diffstat (limited to 'modules/git/diff.go')
-rw-r--r--modules/git/diff.go32
1 files changed, 14 insertions, 18 deletions
diff --git a/modules/git/diff.go b/modules/git/diff.go
index 02ed2c60c4..38aefabf1a 100644
--- a/modules/git/diff.go
+++ b/modules/git/diff.go
@@ -11,13 +11,11 @@ import (
"fmt"
"io"
"os"
- "os/exec"
"regexp"
"strconv"
"strings"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/process"
)
// RawDiffType type of a raw diff.
@@ -55,43 +53,41 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff
if len(file) > 0 {
fileArgs = append(fileArgs, "--", file)
}
- // FIXME: graceful: These commands should have a timeout
- ctx, _, finished := process.GetManager().AddContext(repo.Ctx, fmt.Sprintf("GetRawDiffForFile: [repo_path: %s]", repo.Path))
- defer finished()
- var cmd *exec.Cmd
+ var args []string
switch diffType {
case RawDiffNormal:
if len(startCommit) != 0 {
- cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"diff", "-M", startCommit, endCommit}, fileArgs...)...)
+ args = append([]string{"diff", "-M", startCommit, endCommit}, fileArgs...)
} else if commit.ParentCount() == 0 {
- cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"show", endCommit}, fileArgs...)...)
+ args = append([]string{"show", endCommit}, fileArgs...)
} else {
c, _ := commit.Parent(0)
- cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"diff", "-M", c.ID.String(), endCommit}, fileArgs...)...)
+ args = append([]string{"diff", "-M", c.ID.String(), endCommit}, fileArgs...)
}
case RawDiffPatch:
if len(startCommit) != 0 {
query := fmt.Sprintf("%s...%s", endCommit, startCommit)
- cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"format-patch", "--no-signature", "--stdout", "--root", query}, fileArgs...)...)
+ args = append([]string{"format-patch", "--no-signature", "--stdout", "--root", query}, fileArgs...)
} else if commit.ParentCount() == 0 {
- cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"format-patch", "--no-signature", "--stdout", "--root", endCommit}, fileArgs...)...)
+ args = append([]string{"format-patch", "--no-signature", "--stdout", "--root", endCommit}, fileArgs...)
} else {
c, _ := commit.Parent(0)
query := fmt.Sprintf("%s...%s", endCommit, c.ID.String())
- cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"format-patch", "--no-signature", "--stdout", query}, fileArgs...)...)
+ args = append([]string{"format-patch", "--no-signature", "--stdout", query}, fileArgs...)
}
default:
return fmt.Errorf("invalid diffType: %s", diffType)
}
stderr := new(bytes.Buffer)
-
- cmd.Dir = repo.Path
- cmd.Stdout = writer
- cmd.Stderr = stderr
-
- if err = cmd.Run(); err != nil {
+ cmd := NewCommandContextNoGlobals(repo.Ctx, args...)
+ if err = cmd.RunWithContext(&RunContext{
+ Timeout: -1,
+ Dir: repo.Path,
+ Stdout: writer,
+ Stderr: stderr,
+ }); err != nil {
return fmt.Errorf("Run: %v - %s", err, stderr)
}
return nil