diff options
author | Unknwon <u@gogs.io> | 2015-11-30 20:45:55 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-11-30 20:45:55 -0500 |
commit | 830d00066785d131413d1de11ce301bf1f0b818a (patch) | |
tree | dd22bc4ecc89692146776d335d08c04722650f3f /routers/repo/http.go | |
parent | 5d1f5f32d069ee58a9eb89072231d92dc9ec5f74 (diff) | |
download | gitea-830d00066785d131413d1de11ce301bf1f0b818a.tar.gz gitea-830d00066785d131413d1de11ce301bf1f0b818a.zip |
finish wiki
Diffstat (limited to 'routers/repo/http.go')
-rw-r--r-- | routers/repo/http.go | 133 |
1 files changed, 66 insertions, 67 deletions
diff --git a/routers/repo/http.go b/routers/repo/http.go index e8f29ebe86..e6390bc7c5 100644 --- a/routers/repo/http.go +++ b/routers/repo/http.go @@ -36,10 +36,7 @@ func authRequired(ctx *middleware.Context) { func HTTP(ctx *middleware.Context) { username := ctx.Params(":username") - reponame := ctx.Params(":reponame") - if strings.HasSuffix(reponame, ".git") { - reponame = reponame[:len(reponame)-4] - } + reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git") var isPull bool service := ctx.Query("service") @@ -53,6 +50,12 @@ func HTTP(ctx *middleware.Context) { isPull = (ctx.Req.Method == "GET") } + isWiki := false + if strings.HasSuffix(reponame, ".wiki") { + isWiki = true + reponame = reponame[:len(reponame)-5] + } + repoUser, err := models.GetUserByName(username) if err != nil { if models.IsErrUserNotExist(err) { @@ -165,45 +168,46 @@ func HTTP(ctx *middleware.Context) { } callback := func(rpc string, input []byte) { - if rpc == "receive-pack" { - var lastLine int64 = 0 - - for { - head := input[lastLine : lastLine+2] - if head[0] == '0' && head[1] == '0' { - size, err := strconv.ParseInt(string(input[lastLine+2:lastLine+4]), 16, 32) - if err != nil { - log.Error(4, "%v", err) - return - } + if rpc != "receive-pack" || isWiki { + return + } - if size == 0 { - //fmt.Println(string(input[lastLine:])) - break - } + var lastLine int64 = 0 + for { + head := input[lastLine : lastLine+2] + if head[0] == '0' && head[1] == '0' { + size, err := strconv.ParseInt(string(input[lastLine+2:lastLine+4]), 16, 32) + if err != nil { + log.Error(4, "%v", err) + return + } - line := input[lastLine : lastLine+size] - idx := bytes.IndexRune(line, '\000') - if idx > -1 { - line = line[:idx] - } - fields := strings.Fields(string(line)) - if len(fields) >= 3 { - oldCommitId := fields[0][4:] - newCommitId := fields[1] - refName := fields[2] - - // FIXME: handle error. - if err = models.Update(refName, oldCommitId, newCommitId, authUsername, username, reponame, authUser.Id); err == nil { - go models.HookQueue.Add(repo.ID) - go models.AddTestPullRequestTask(repo.ID, strings.TrimPrefix(refName, "refs/heads/")) - } + if size == 0 { + //fmt.Println(string(input[lastLine:])) + break + } + line := input[lastLine : lastLine+size] + idx := bytes.IndexRune(line, '\000') + if idx > -1 { + line = line[:idx] + } + fields := strings.Fields(string(line)) + if len(fields) >= 3 { + oldCommitId := fields[0][4:] + newCommitId := fields[1] + refName := fields[2] + + // FIXME: handle error. + if err = models.Update(refName, oldCommitId, newCommitId, authUsername, username, reponame, authUser.Id); err == nil { + go models.HookQueue.Add(repo.ID) + go models.AddTestPullRequestTask(repo.ID, strings.TrimPrefix(refName, "refs/heads/")) } - lastLine = lastLine + size - } else { - break + } + lastLine = lastLine + size + } else { + break } } } @@ -255,6 +259,29 @@ var routes = []route{ {regexp.MustCompile("(.*?)/objects/pack/pack-[0-9a-f]{40}\\.idx$"), "GET", getIdxFile}, } +func getGitDir(config *Config, fPath string) (string, error) { + root := config.RepoRootPath + if len(root) == 0 { + cwd, err := os.Getwd() + if err != nil { + log.GitLogger.Error(4, err.Error()) + return "", err + } + root = cwd + } + + if !strings.HasSuffix(fPath, ".git") { + fPath = fPath + ".git" + } + + f := filepath.Join(root, fPath) + if _, err := os.Stat(f); os.IsNotExist(err) { + return "", err + } + + return f, nil +} + // Request handling function func HTTPBackend(config *Config) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -268,15 +295,13 @@ func HTTPBackend(config *Config) http.HandlerFunc { file := strings.Replace(r.URL.Path, m[1]+"/", "", 1) dir, err := getGitDir(config, m[1]) - if err != nil { log.GitLogger.Error(4, err.Error()) renderNotFound(w) return } - hr := handler{config, w, r, dir, file} - route.handler(hr) + route.handler(handler{config, w, r, dir, file}) return } } @@ -419,32 +444,6 @@ func sendFile(contentType string, hr handler) { http.ServeFile(w, r, reqFile) } -func getGitDir(config *Config, fPath string) (string, error) { - root := config.RepoRootPath - - if root == "" { - cwd, err := os.Getwd() - - if err != nil { - log.GitLogger.Error(4, err.Error()) - return "", err - } - - root = cwd - } - - if !strings.HasSuffix(fPath, ".git") { - fPath = fPath + ".git" - } - - f := filepath.Join(root, fPath) - if _, err := os.Stat(f); os.IsNotExist(err) { - return "", err - } - - return f, nil -} - func getServiceType(r *http.Request) string { serviceType := r.FormValue("service") |