summaryrefslogtreecommitdiffstats
path: root/models/git_diff.go
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-28 22:15:15 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-28 22:15:15 -0400
commit6696610aea48482b6c2f258cc43f595d550e7477 (patch)
treef41bf7120f77e0f2bb9d9cde9bd22ac331138073 /models/git_diff.go
parente323604d781268a39febced13a2fb6caae2d126c (diff)
downloadgitea-6696610aea48482b6c2f258cc43f595d550e7477.tar.gz
gitea-6696610aea48482b6c2f258cc43f595d550e7477.zip
Fix zombie
Diffstat (limited to 'models/git_diff.go')
-rw-r--r--models/git_diff.go41
1 files changed, 19 insertions, 22 deletions
diff --git a/models/git_diff.go b/models/git_diff.go
index 8dd5a8c882..5b5a46a120 100644
--- a/models/git_diff.go
+++ b/models/git_diff.go
@@ -67,7 +67,7 @@ func (diff *Diff) NumFiles() int {
const DIFF_HEAD = "diff --git "
-func ParsePatch(reader io.Reader) (*Diff, error) {
+func ParsePatch(cmd *exec.Cmd, reader io.Reader) (*Diff, error) {
scanner := bufio.NewScanner(reader)
var (
curFile *DiffFile
@@ -168,6 +168,13 @@ func ParsePatch(reader io.Reader) (*Diff, error) {
}
}
+ // In case process became zombie.
+ if !cmd.ProcessState.Exited() {
+ log.Debug("git_diff.ParsePatch: process doesn't exit and now will be killed")
+ if err := cmd.Process.Kill(); err != nil {
+ log.Error("git_diff.ParsePatch: fail to kill zombie process: %v", err)
+ }
+ }
return diff, nil
}
@@ -182,33 +189,23 @@ func GetDiff(repoPath, commitid string) (*Diff, error) {
return nil, err
}
+ rd, wr := io.Pipe()
+ var cmd *exec.Cmd
// First commit of repository.
if commit.ParentCount() == 0 {
- rd, wr := io.Pipe()
- go func() {
- cmd := exec.Command("git", "show", commitid)
- cmd.Dir = repoPath
- cmd.Stdout = wr
- cmd.Stdin = os.Stdin
- cmd.Stderr = os.Stderr
- cmd.Run()
- wr.Close()
- }()
- defer rd.Close()
- return ParsePatch(rd)
+ cmd = exec.Command("git", "show", commitid)
+ } else {
+ c, _ := commit.Parent(0)
+ cmd = exec.Command("git", "diff", c.Id.String(), commitid)
}
-
- rd, wr := io.Pipe()
+ cmd.Dir = repoPath
+ cmd.Stdout = wr
+ cmd.Stdin = os.Stdin
+ cmd.Stderr = os.Stderr
go func() {
- c, _ := commit.Parent(0)
- cmd := exec.Command("git", "diff", c.Id.String(), commitid)
- cmd.Dir = repoPath
- cmd.Stdout = wr
- cmd.Stdin = os.Stdin
- cmd.Stderr = os.Stderr
cmd.Run()
wr.Close()
}()
defer rd.Close()
- return ParsePatch(rd)
+ return ParsePatch(cmd, rd)
}