diff options
author | Meaglith Ma <genedna@gmail.com> | 2014-03-31 17:23:37 +0800 |
---|---|---|
committer | Meaglith Ma <genedna@gmail.com> | 2014-03-31 17:23:37 +0800 |
commit | 1a247340dbea3404431f60a24bb8f8d06d94b1e9 (patch) | |
tree | 80d3ecab43506e03405c742a84dcc61f474e2212 /routers/repo/repo.go | |
parent | 9047cadcd33f95eebafa2f794b895c8406eb80c5 (diff) | |
parent | dd9fb807a46db120ef800d7465f50a73a86df288 (diff) |
Merge pull request #1 from gogits/master
Sync to lastest
Diffstat (limited to 'routers/repo/repo.go')
-rw-r--r-- | routers/repo/repo.go | 72 |
1 files changed, 17 insertions, 55 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go index e7107ad1..1cd3dd86 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -9,7 +9,7 @@ import ( "path/filepath" "strings" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/webdav" @@ -53,20 +53,20 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) { } func Single(ctx *middleware.Context, params martini.Params) { - if !ctx.Repo.IsValid { - return - } + branchName := ctx.Repo.BranchName + commitId := ctx.Repo.CommitId + userName := ctx.Repo.Owner.Name + repoName := ctx.Repo.Repository.Name - branchName := params["branchname"] - userName := params["username"] - repoName := params["reponame"] + repoLink := ctx.Repo.RepoLink + branchLink := ctx.Repo.RepoLink + "/src/" + branchName + rawLink := ctx.Repo.RepoLink + "/raw/" + branchName // Get tree path treename := params["_1"] if len(treename) > 0 && treename[len(treename)-1] == '/' { - ctx.Redirect("/" + ctx.Repo.Owner.LowerName + "/" + - ctx.Repo.Repository.Name + "/src/" + branchName + "/" + treename[:len(treename)-1]) + ctx.Redirect(repoLink + "/src/" + branchName + "/" + treename[:len(treename)-1]) return } @@ -77,30 +77,21 @@ func Single(ctx *middleware.Context, params martini.Params) { if err != nil { ctx.Handle(404, "repo.Single(GetBranches)", err) return - } else if ctx.Repo.Repository.IsBare { - ctx.Data["IsBareRepo"] = true - ctx.HTML(200, "repo/single") - return } + ctx.Data["Branches"] = brs - var commitId string - isViewBranch := models.IsBranchExist(userName, repoName, branchName) - if !isViewBranch { - commitId = branchName - } + isViewBranch := ctx.Repo.IsBranch ctx.Data["IsViewBranch"] = isViewBranch repoFile, err := models.GetTargetFile(userName, repoName, branchName, commitId, treename) + if err != nil && err != models.ErrRepoFileNotExist { ctx.Handle(404, "repo.Single(GetTargetFile)", err) return } - branchLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/src/" + branchName - rawLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/raw/" + branchName - if len(treename) != 0 && repoFile == nil { ctx.Handle(404, "repo.Single", nil) return @@ -142,8 +133,7 @@ func Single(ctx *middleware.Context, params martini.Params) { } else { // Directory and file list. - files, err := models.GetReposFiles(userName, repoName, - branchName, commitId, treename) + files, err := models.GetReposFiles(userName, repoName, ctx.Repo.CommitId, treename) if err != nil { ctx.Handle(404, "repo.Single(GetReposFiles)", err) return @@ -200,18 +190,7 @@ func Single(ctx *middleware.Context, params martini.Params) { } } - // Get latest commit according username and repo name. - commit, err := models.GetCommit(userName, repoName, - branchName, commitId) - if err != nil { - log.Error("repo.Single(GetCommit): %v", err) - ctx.Handle(404, "repo.Single(GetCommit)", err) - return - } - ctx.Data["LastCommit"] = commit - - ctx.Data["CommitId"] = commitId - + ctx.Data["LastCommit"] = ctx.Repo.Commit ctx.Data["Paths"] = Paths ctx.Data["Treenames"] = treenames ctx.Data["BranchLink"] = branchLink @@ -219,11 +198,6 @@ func Single(ctx *middleware.Context, params martini.Params) { } func SingleDownload(ctx *middleware.Context, params martini.Params) { - if !ctx.Repo.IsValid { - ctx.Handle(404, "repo.SingleDownload", nil) - return - } - // Get tree path treename := params["_1"] @@ -263,10 +237,6 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) { } func Http(ctx *middleware.Context, params martini.Params) { - /*if !ctx.Repo.IsValid { - return - }*/ - // TODO: access check username := params["username"] @@ -276,11 +246,9 @@ func Http(ctx *middleware.Context, params martini.Params) { } prefix := path.Join("/", username, params["reponame"]) - server := &webdav.Server{ - Fs: webdav.Dir(models.RepoPath(username, reponame)), - TrimPrefix: prefix, - Listings: true, - } + server := webdav.NewServer( + models.RepoPath(username, reponame), + prefix, true) server.ServeHTTP(ctx.ResponseWriter, ctx.Req) } @@ -293,12 +261,6 @@ func Setting(ctx *middleware.Context, params martini.Params) { ctx.Data["IsRepoToolbarSetting"] = true - if ctx.Repo.Repository.IsBare { - ctx.Data["IsBareRepo"] = true - ctx.HTML(200, "repo/setting") - return - } - var title string if t, ok := ctx.Data["Title"].(string); ok { title = t |