aboutsummaryrefslogtreecommitdiff
path: root/routers/repo
diff options
context:
space:
mode:
authorslene <vslene@gmail.com>2014-03-28 00:07:22 +0800
committerslene <vslene@gmail.com>2014-03-28 00:07:22 +0800
commit677643b812cdc3bce3b7ef7839239b3059376684 (patch)
tree92c72eb18513b972a0037172891c415c54b7614d /routers/repo
parentc796ed3849e3cd5b28cc8234edc71bbedafbc7da (diff)
fix read commit source
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/commit.go31
-rw-r--r--routers/repo/repo.go35
2 files changed, 47 insertions, 19 deletions
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index 3d00f8d7..11aab67c 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -5,13 +5,22 @@
package repo
import (
+ "container/list"
+ "fmt"
+ "path"
+
"github.com/codegangsta/martini"
+
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware"
)
func Commits(ctx *middleware.Context, params martini.Params) {
- brs, err := models.GetBranches(params["username"], params["reponame"])
+ userName := params["username"]
+ repoName := params["reponame"]
+ branchName := params["branchname"]
+
+ brs, err := models.GetBranches(userName, repoName)
if err != nil {
ctx.Handle(200, "repo.Commits", err)
return
@@ -20,21 +29,28 @@ func Commits(ctx *middleware.Context, params martini.Params) {
return
}
- ctx.Data["IsRepoToolbarCommits"] = true
- commits, err := models.GetCommits(params["username"],
- params["reponame"], params["branchname"])
+ var commits *list.List
+ if models.IsBranchExist(userName, repoName, branchName) {
+ commits, err = models.GetCommitsByBranch(userName, repoName, branchName)
+ } else {
+ commits, err = models.GetCommitsByCommitId(userName, repoName, branchName)
+ }
+
if err != nil {
ctx.Handle(404, "repo.Commits", nil)
return
}
- ctx.Data["Username"] = params["username"]
- ctx.Data["Reponame"] = params["reponame"]
+
+ ctx.Data["Username"] = userName
+ ctx.Data["Reponame"] = repoName
ctx.Data["CommitCount"] = commits.Len()
ctx.Data["Commits"] = commits
+ ctx.Data["IsRepoToolbarCommits"] = true
ctx.HTML(200, "repo/commits")
}
func Diff(ctx *middleware.Context, params martini.Params) {
+ fmt.Println(params["branchname"])
commit, err := models.GetCommit(params["username"], params["reponame"], params["branchname"], params["commitid"])
if err != nil {
ctx.Handle(404, "repo.Diff", err)
@@ -47,11 +63,12 @@ func Diff(ctx *middleware.Context, params martini.Params) {
return
}
- shortSha := params["commitid"][:7]
+ shortSha := params["commitid"][:10]
ctx.Data["Title"] = commit.Message() + " ยท " + shortSha
ctx.Data["Commit"] = commit
ctx.Data["ShortSha"] = shortSha
ctx.Data["Diff"] = diff
ctx.Data["IsRepoToolbarCommits"] = true
+ ctx.Data["SourcePath"] = "/" + path.Join(params["username"], params["reponame"], "src", params["commitid"])
ctx.HTML(200, "repo/diff")
}
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index 43558747..3c8d24a6 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -57,19 +57,23 @@ func Single(ctx *middleware.Context, params martini.Params) {
return
}
+ branchName := params["branchname"]
+ userName := params["username"]
+ repoName := params["reponame"]
+
// 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/" + params["branchname"] + "/" + treename[:len(treename)-1])
+ ctx.Repo.Repository.Name + "/src/" + branchName + "/" + treename[:len(treename)-1])
return
}
ctx.Data["IsRepoToolbarSource"] = true
// Branches.
- brs, err := models.GetBranches(params["username"], params["reponame"])
+ brs, err := models.GetBranches(userName, repoName)
if err != nil {
ctx.Handle(404, "repo.Single(GetBranches)", err)
return
@@ -80,15 +84,20 @@ func Single(ctx *middleware.Context, params martini.Params) {
}
ctx.Data["Branches"] = brs
- repoFile, err := models.GetTargetFile(params["username"], params["reponame"],
- params["branchname"], params["commitid"], treename)
+ var commitId string
+ if !models.IsBranchExist(userName, repoName, branchName) {
+ commitId = branchName
+ }
+
+ 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/" + params["branchname"]
- rawLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/raw/" + params["branchname"]
+ 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)
@@ -126,8 +135,8 @@ func Single(ctx *middleware.Context, params martini.Params) {
} else {
// Directory and file list.
- files, err := models.GetReposFiles(params["username"], params["reponame"],
- params["branchname"], params["commitid"], treename)
+ files, err := models.GetReposFiles(userName, repoName,
+ branchName, commitId, treename)
if err != nil {
ctx.Handle(404, "repo.Single(GetReposFiles)", err)
return
@@ -166,8 +175,8 @@ func Single(ctx *middleware.Context, params martini.Params) {
}
}
- ctx.Data["Username"] = params["username"]
- ctx.Data["Reponame"] = params["reponame"]
+ ctx.Data["Username"] = userName
+ ctx.Data["Reponame"] = repoName
var treenames []string
Paths := make([]string, 0)
@@ -185,8 +194,8 @@ func Single(ctx *middleware.Context, params martini.Params) {
}
// Get latest commit according username and repo name.
- commit, err := models.GetCommit(params["username"], params["reponame"],
- params["branchname"], params["commitid"])
+ 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)
@@ -194,6 +203,8 @@ func Single(ctx *middleware.Context, params martini.Params) {
}
ctx.Data["LastCommit"] = commit
+ ctx.Data["CommitId"] = commitId
+
ctx.Data["Paths"] = Paths
ctx.Data["Treenames"] = treenames
ctx.Data["BranchLink"] = branchLink