mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-28 14:43:52 +03:00
Fix zombie
This commit is contained in:
parent
e323604d78
commit
6696610aea
2 changed files with 20 additions and 25 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
rd, wr := io.Pipe()
|
||||
go func() {
|
||||
cmd = exec.Command("git", "show", commitid)
|
||||
} else {
|
||||
c, _ := commit.Parent(0)
|
||||
cmd := exec.Command("git", "diff", c.Id.String(), commitid)
|
||||
cmd = exec.Command("git", "diff", c.Id.String(), commitid)
|
||||
}
|
||||
cmd.Dir = repoPath
|
||||
cmd.Stdout = wr
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stderr = os.Stderr
|
||||
go func() {
|
||||
cmd.Run()
|
||||
wr.Close()
|
||||
}()
|
||||
defer rd.Close()
|
||||
return ParsePatch(rd)
|
||||
return ParsePatch(cmd, rd)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue