mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-05 03:28:56 +00:00
bug fixed #236
This commit is contained in:
parent
63770d93a1
commit
7dbeee94e3
1 changed files with 8 additions and 22 deletions
|
@ -7,7 +7,6 @@ package repo
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -190,7 +189,6 @@ var routes = []route{
|
||||||
// Request handling function
|
// Request handling function
|
||||||
func HttpBackend(config *Config) http.HandlerFunc {
|
func HttpBackend(config *Config) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
//log.GitLogger.Printf("%s %s %s %s", r.RemoteAddr, r.Method, r.URL.Path, r.Proto)
|
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
if m := route.cr.FindStringSubmatch(r.URL.Path); m != nil {
|
if m := route.cr.FindStringSubmatch(r.URL.Path); m != nil {
|
||||||
if route.method != r.Method {
|
if route.method != r.Method {
|
||||||
|
@ -212,13 +210,13 @@ func HttpBackend(config *Config) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderNotFound(w)
|
renderNotFound(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actual command handling functions
|
// Actual command handling functions
|
||||||
|
|
||||||
func serviceUploadPack(hr handler) {
|
func serviceUploadPack(hr handler) {
|
||||||
serviceRpc("upload-pack", hr)
|
serviceRpc("upload-pack", hr)
|
||||||
}
|
}
|
||||||
|
@ -236,36 +234,24 @@ func serviceRpc(rpc string, hr handler) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
input, _ := ioutil.ReadAll(r.Body)
|
|
||||||
|
|
||||||
w.Header().Set("Content-Type", fmt.Sprintf("application/x-git-%s-result", rpc))
|
w.Header().Set("Content-Type", fmt.Sprintf("application/x-git-%s-result", rpc))
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
|
input, _ := ioutil.ReadAll(r.Body)
|
||||||
|
br := bytes.NewReader(input)
|
||||||
|
|
||||||
args := []string{rpc, "--stateless-rpc", dir}
|
args := []string{rpc, "--stateless-rpc", dir}
|
||||||
cmd := exec.Command(hr.Config.GitBinPath, args...)
|
cmd := exec.Command(hr.Config.GitBinPath, args...)
|
||||||
cmd.Dir = dir
|
cmd.Dir = dir
|
||||||
in, err := cmd.StdinPipe()
|
cmd.Stdout = w
|
||||||
|
cmd.Stdin = br
|
||||||
|
|
||||||
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.GitLogger.Error(err.Error())
|
log.GitLogger.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout, err := cmd.StdoutPipe()
|
|
||||||
if err != nil {
|
|
||||||
log.GitLogger.Error(err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = cmd.Start()
|
|
||||||
if err != nil {
|
|
||||||
log.GitLogger.Error(err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
in.Write(input)
|
|
||||||
io.Copy(w, stdout)
|
|
||||||
cmd.Wait()
|
|
||||||
|
|
||||||
if hr.Config.OnSucceed != nil {
|
if hr.Config.OnSucceed != nil {
|
||||||
hr.Config.OnSucceed(rpc, input)
|
hr.Config.OnSucceed(rpc, input)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue