@@ -11,13 +11,11 @@ import (
1111 "fmt"
1212 "io"
1313 "os"
14- "os/exec"
1514 "regexp"
1615 "strconv"
1716 "strings"
1817
1918 "code.gitea.io/gitea/modules/log"
20- "code.gitea.io/gitea/modules/process"
2119)
2220
2321// RawDiffType type of a raw diff.
@@ -55,43 +53,41 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff
5553 if len (file ) > 0 {
5654 fileArgs = append (fileArgs , "--" , file )
5755 }
58- // FIXME: graceful: These commands should have a timeout
59- ctx , _ , finished := process .GetManager ().AddContext (repo .Ctx , fmt .Sprintf ("GetRawDiffForFile: [repo_path: %s]" , repo .Path ))
60- defer finished ()
6156
62- var cmd * exec. Cmd
57+ var args [] string
6358 switch diffType {
6459 case RawDiffNormal :
6560 if len (startCommit ) != 0 {
66- cmd = exec . CommandContext ( ctx , GitExecutable , append ([]string {"diff" , "-M" , startCommit , endCommit }, fileArgs ... ) ... )
61+ args = append ([]string {"diff" , "-M" , startCommit , endCommit }, fileArgs ... )
6762 } else if commit .ParentCount () == 0 {
68- cmd = exec . CommandContext ( ctx , GitExecutable , append ([]string {"show" , endCommit }, fileArgs ... ) ... )
63+ args = append ([]string {"show" , endCommit }, fileArgs ... )
6964 } else {
7065 c , _ := commit .Parent (0 )
71- cmd = exec . CommandContext ( ctx , GitExecutable , append ([]string {"diff" , "-M" , c .ID .String (), endCommit }, fileArgs ... ) ... )
66+ args = append ([]string {"diff" , "-M" , c .ID .String (), endCommit }, fileArgs ... )
7267 }
7368 case RawDiffPatch :
7469 if len (startCommit ) != 0 {
7570 query := fmt .Sprintf ("%s...%s" , endCommit , startCommit )
76- cmd = exec . CommandContext ( ctx , GitExecutable , append ([]string {"format-patch" , "--no-signature" , "--stdout" , "--root" , query }, fileArgs ... ) ... )
71+ args = append ([]string {"format-patch" , "--no-signature" , "--stdout" , "--root" , query }, fileArgs ... )
7772 } else if commit .ParentCount () == 0 {
78- cmd = exec . CommandContext ( ctx , GitExecutable , append ([]string {"format-patch" , "--no-signature" , "--stdout" , "--root" , endCommit }, fileArgs ... ) ... )
73+ args = append ([]string {"format-patch" , "--no-signature" , "--stdout" , "--root" , endCommit }, fileArgs ... )
7974 } else {
8075 c , _ := commit .Parent (0 )
8176 query := fmt .Sprintf ("%s...%s" , endCommit , c .ID .String ())
82- cmd = exec . CommandContext ( ctx , GitExecutable , append ([]string {"format-patch" , "--no-signature" , "--stdout" , query }, fileArgs ... ) ... )
77+ args = append ([]string {"format-patch" , "--no-signature" , "--stdout" , query }, fileArgs ... )
8378 }
8479 default :
8580 return fmt .Errorf ("invalid diffType: %s" , diffType )
8681 }
8782
8883 stderr := new (bytes.Buffer )
89-
90- cmd .Dir = repo .Path
91- cmd .Stdout = writer
92- cmd .Stderr = stderr
93-
94- if err = cmd .Run (); err != nil {
84+ cmd := NewCommandContextNoGlobals (repo .Ctx , args ... )
85+ if err = cmd .RunWithContext (& RunContext {
86+ Timeout : - 1 ,
87+ Dir : repo .Path ,
88+ Stdout : writer ,
89+ Stderr : stderr ,
90+ }); err != nil {
9591 return fmt .Errorf ("Run: %v - %s" , err , stderr )
9692 }
9793 return nil
0 commit comments