summaryrefslogtreecommitdiffstats
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
parente323604d781268a39febced13a2fb6caae2d126c (diff)
downloadgitea-6696610aea48482b6c2f258cc43f595d550e7477.tar.gz
gitea-6696610aea48482b6c2f258cc43f595d550e7477.zip
Fix zombie
-rw-r--r--CONTRIBUTING.md2
-rw-r--r--models/git_diff.go41
2 files changed, 19 insertions, 24 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 86f9b8e9b6..0a8b26f1c2 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -2,8 +2,6 @@
> Thanks [drone](https://github.com/drone/drone) because this guidelines sheet is forked from its [CONTRIBUTING.md](https://github.com/drone/drone/blob/master/CONTRIBUTING.md).
-**This document is pre^2 release, we're not ready for receiving contribution until v0.5.0 release.**
-
Want to hack on Gogs? Awesome! Here are instructions to get you started. They are probably not perfect, please let us know if anything feels wrong or incomplete.
## Contribution guidelines
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)
}