diff options
Diffstat (limited to 'models/git_diff.go')
-rw-r--r-- | models/git_diff.go | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/models/git_diff.go b/models/git_diff.go index ed114b75..4b4d1234 100644 --- a/models/git_diff.go +++ b/models/git_diff.go @@ -11,10 +11,12 @@ import ( "os" "os/exec" "strings" + "time" + + "github.com/Unknwon/com" "github.com/gogits/git" - "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/process" ) @@ -117,8 +119,8 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { // Parse line number. ranges := strings.Split(ss[len(ss)-2][1:], " ") - leftLine, _ = base.StrTo(strings.Split(ranges[0], ",")[0][1:]).Int() - rightLine, _ = base.StrTo(strings.Split(ranges[1], ",")[0]).Int() + leftLine, _ = com.StrTo(strings.Split(ranges[0], ",")[0][1:]).Int() + rightLine, _ = com.StrTo(strings.Split(ranges[1], ",")[0]).Int() continue case line[0] == '+': curFile.Addition++ @@ -170,10 +172,6 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { } } - // In case process became zombie. - if err := process.Kill(pid); err != nil { - log.Error("git_diff.ParsePatch(Kill): %v", err) - } return diff, nil } @@ -201,10 +199,30 @@ func GetDiff(repoPath, commitid string) (*Diff, error) { cmd.Stdout = wr cmd.Stdin = os.Stdin cmd.Stderr = os.Stderr + + done := make(chan error) go func() { - cmd.Run() + cmd.Start() + done <- cmd.Wait() wr.Close() }() defer rd.Close() - return ParsePatch(process.Add(fmt.Sprintf("GetDiff(%s)", repoPath), cmd), cmd, rd) + + desc := fmt.Sprintf("GetDiff(%s)", repoPath) + pid := process.Add(desc, cmd) + go func() { + // In case process became zombie. + select { + case <-time.After(5 * time.Minute): + if errKill := process.Kill(pid); errKill != nil { + log.Error(4, "git_diff.ParsePatch(Kill): %v", err) + } + <-done + // return "", ErrExecTimeout.Error(), ErrExecTimeout + case err = <-done: + process.Remove(pid) + } + }() + + return ParsePatch(pid, cmd, rd) } |