aboutsummaryrefslogtreecommitdiffstats
path: root/routers/repo/http.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2014-04-11 10:27:13 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2014-04-11 10:27:13 +0800
commitdb39e58a139ef8581b4b61d2d4a68b4e5324acdf (patch)
tree7c73c2b6fa71ec1a970fe17f67e10af49e6ec9c9 /routers/repo/http.go
parent8faa0dbcd77ec17bbf88041f46e2fc48f6ca6f31 (diff)
downloadgitea-db39e58a139ef8581b4b61d2d4a68b4e5324acdf.tar.gz
gitea-db39e58a139ef8581b4b61d2d4a68b4e5324acdf.zip
add actions for http push
Diffstat (limited to 'routers/repo/http.go')
-rw-r--r--routers/repo/http.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/routers/repo/http.go b/routers/repo/http.go
index 5aa3139f85..d15c66e022 100644
--- a/routers/repo/http.go
+++ b/routers/repo/http.go
@@ -1,6 +1,7 @@
package repo
import (
+ "bytes"
"fmt"
"io"
"io/ioutil"
@@ -54,6 +55,8 @@ func Http(ctx *middleware.Context, params martini.Params) {
// only public pull don't need auth
var askAuth = !(!repo.IsPrivate && isPull)
+ var authUser *models.User
+
// check access
if askAuth {
baHead := ctx.Req.Header.Get("Authorization")
@@ -76,7 +79,7 @@ func Http(ctx *middleware.Context, params martini.Params) {
return
}
- authUser, err := models.GetUserByName(authUsername)
+ authUser, err = models.GetUserByName(authUsername)
if err != nil {
ctx.Handle(401, "no basic auth and digit auth", nil)
return
@@ -114,8 +117,20 @@ func Http(ctx *middleware.Context, params martini.Params) {
}
config := Config{base.RepoRootPath, "git", true, true, func(rpc string, input []byte) {
- //fmt.Println("rpc:", rpc)
- //fmt.Println("input:", string(input))
+ if rpc == "receive-pack" {
+ firstLine := bytes.IndexRune(input, '\n')
+ fmt.Println("firstLine", firstLine)
+ if firstLine > -1 {
+ fields := strings.Fields(string(input[:firstLine]))
+ if len(fields) > 3 {
+ oldCommitId := fields[0][4:]
+ newCommitId := fields[1]
+ refName := fields[2]
+
+ models.Update(refName, oldCommitId, newCommitId, username, reponame, authUser.Id)
+ }
+ }
+ }
}}
handler := HttpBackend(&config)