Browse Source

Code fix for PR #3748

pull/3981/head
Unknwon 8 years ago
parent
commit
2994272e91
No known key found for this signature in database
GPG Key ID: FB9F411CDD69BEC1
  1. 2
      README.md
  2. 2
      gogs.go
  3. 67
      routers/repo/http.go
  4. 2
      templates/.VERSION

2
README.md

@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
##### Current tip version: 0.9.112 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions ~~or submit a task on [alpha stage automated binary building system](https://build.gogs.io/)~~)
##### Current tip version: 0.9.113 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions ~~or submit a task on [alpha stage automated binary building system](https://build.gogs.io/)~~)
| Web | UI | Preview |
|:-------------:|:-------:|:-------:|

2
gogs.go

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting"
)
const APP_VER = "0.9.112.1223"
const APP_VER = "0.9.113.1223"
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())

67
routers/repo/http.go

@ -165,18 +165,29 @@ func HTTP(ctx *context.Context) {
}
}
callback := func(rpc string, input []byte) {
callback := func(rpc string, input *os.File) {
if rpc != "receive-pack" || isWiki {
return
}
var lastLine int64 = 0
var (
head = make([]byte, 4) // 00+size
n int
err error
)
for {
head := input[lastLine : lastLine+2]
n, err = input.Read(head)
if err != nil && err != io.EOF {
log.Error(4, "read head: %v", err)
return
} else if n < 4 {
break
}
if head[0] == '0' && head[1] == '0' {
size, err := strconv.ParseInt(string(input[lastLine+2:lastLine+4]), 16, 32)
size, err := strconv.ParseInt(string(head[2:4]), 16, 32)
if err != nil {
log.Error(4, "%v", err)
log.Error(4, "parse size: %v", err)
return
}
@ -185,7 +196,16 @@ func HTTP(ctx *context.Context) {
break
}
line := input[lastLine : lastLine+size]
line := make([]byte, size)
n, err = input.Read(line)
if err != nil {
log.Error(4, "read line: %v", err)
return
} else if n < int(size) {
log.Error(4, "didn't read enough bytes: expect %d got %d", size, n)
break
}
idx := bytes.IndexRune(line, '\000')
if idx > -1 {
line = line[:idx]
@ -193,7 +213,7 @@ func HTTP(ctx *context.Context) {
fields := strings.Fields(string(line))
if len(fields) >= 3 {
oldCommitId := fields[0][4:]
oldCommitId := fields[0]
newCommitId := fields[1]
refFullName := fields[2]
@ -211,7 +231,6 @@ func HTTP(ctx *context.Context) {
}
}
lastLine = lastLine + size
} else {
break
}
@ -230,7 +249,7 @@ func HTTP(ctx *context.Context) {
type serviceConfig struct {
UploadPack bool
ReceivePack bool
OnSucceed func(rpc string, input []byte)
OnSucceed func(rpc string, input *os.File)
}
type serviceHandler struct {
@ -347,10 +366,10 @@ func serviceRPC(h serviceHandler, service string) {
h.w.Header().Set("Content-Type", fmt.Sprintf("application/x-git-%s-result", service))
var (
reqBody = h.r.Body
input []byte
br io.Reader
err error
reqBody = h.r.Body
tmpFilename string
br io.Reader
err error
)
// Handle GZIP.
@ -371,7 +390,6 @@ func serviceRPC(h serviceHandler, service string) {
return
}
defer os.Remove(tmpfile.Name())
defer tmpfile.Close()
_, err = io.Copy(tmpfile, reqBody)
if err != nil {
@ -379,23 +397,42 @@ func serviceRPC(h serviceHandler, service string) {
h.w.WriteHeader(http.StatusInternalServerError)
return
}
tmpfile.Close()
tmpFilename = tmpfile.Name()
tmpfile, err = os.Open(tmpFilename)
if err != nil {
log.GitLogger.Error(2, "fail to open temporary file: %v", err)
h.w.WriteHeader(http.StatusInternalServerError)
return
}
defer tmpfile.Close()
br = tmpfile
} else {
br = reqBody
}
var stderr bytes.Buffer
cmd := exec.Command("git", service, "--stateless-rpc", h.dir)
cmd.Dir = h.dir
cmd.Stdout = h.w
cmd.Stderr = &stderr
cmd.Stdin = br
if err := cmd.Run(); err != nil {
log.GitLogger.Error(2, "fail to serve RPC(%s): %v", service, err)
log.GitLogger.Error(2, "fail to serve RPC(%s): %v - %s", service, err, stderr)
h.w.WriteHeader(http.StatusInternalServerError)
return
}
if h.cfg.OnSucceed != nil {
input, err := os.Open(tmpFilename)
if err != nil {
log.GitLogger.Error(2, "fail to open temporary file: %v", err)
h.w.WriteHeader(http.StatusInternalServerError)
return
}
defer input.Close()
h.cfg.OnSucceed(service, input)
}
}

2
templates/.VERSION

@ -1 +1 @@
0.9.112.1223
0.9.113.1223
Loading…
Cancel
Save