@@ -11,13 +11,11 @@ import (
11
11
"fmt"
12
12
"io"
13
13
"os"
14
- "os/exec"
15
14
"regexp"
16
15
"strconv"
17
16
"strings"
18
17
19
18
"code.gitea.io/gitea/modules/log"
20
- "code.gitea.io/gitea/modules/process"
21
19
)
22
20
23
21
// RawDiffType type of a raw diff.
@@ -55,43 +53,41 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff
55
53
if len (file ) > 0 {
56
54
fileArgs = append (fileArgs , "--" , file )
57
55
}
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 ()
61
56
62
- var cmd * exec. Cmd
57
+ var args [] string
63
58
switch diffType {
64
59
case RawDiffNormal :
65
60
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 ... )
67
62
} else if commit .ParentCount () == 0 {
68
- cmd = exec . CommandContext ( ctx , GitExecutable , append ([]string {"show" , endCommit }, fileArgs ... ) ... )
63
+ args = append ([]string {"show" , endCommit }, fileArgs ... )
69
64
} else {
70
65
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 ... )
72
67
}
73
68
case RawDiffPatch :
74
69
if len (startCommit ) != 0 {
75
70
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 ... )
77
72
} 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 ... )
79
74
} else {
80
75
c , _ := commit .Parent (0 )
81
76
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 ... )
83
78
}
84
79
default :
85
80
return fmt .Errorf ("invalid diffType: %s" , diffType )
86
81
}
87
82
88
83
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 {
95
91
return fmt .Errorf ("Run: %v - %s" , err , stderr )
96
92
}
97
93
return nil
0 commit comments