aboutsummaryrefslogtreecommitdiff
path: root/routers/repo/commit.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/repo/commit.go')
-rw-r--r--routers/repo/commit.go61
1 files changed, 51 insertions, 10 deletions
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index 3d00f8d7..afc1ffda 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -5,13 +5,22 @@
package repo
import (
+ "container/list"
+ "path"
+
"github.com/codegangsta/martini"
+
"github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/modules/base"
"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,38 +29,70 @@ 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)
+ ctx.Handle(404, "repo.Commits", err)
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) {
- commit, err := models.GetCommit(params["username"], params["reponame"], params["branchname"], params["commitid"])
+ userName := params["username"]
+ repoName := params["reponame"]
+ branchName := params["branchname"]
+ commitId := params["commitid"]
+
+ commit, err := models.GetCommit(userName, repoName, branchName, commitId)
if err != nil {
ctx.Handle(404, "repo.Diff", err)
return
}
- diff, err := models.GetDiff(models.RepoPath(params["username"], params["reponame"]), params["commitid"])
+ diff, err := models.GetDiff(models.RepoPath(userName, repoName), commitId)
if err != nil {
ctx.Handle(404, "repo.Diff", err)
return
}
- shortSha := params["commitid"][:7]
+ isImageFile := func(name string) bool {
+ repoFile, err := models.GetTargetFile(userName, repoName,
+ branchName, commitId, name)
+
+ if err != nil {
+ return false
+ }
+
+ blob, err := repoFile.LookupBlob()
+ if err != nil {
+ return false
+ }
+
+ data := blob.Contents()
+ _, isImage := base.IsImageFile(data)
+ return isImage
+ }
+
+ shortSha := params["commitid"][:10]
+ ctx.Data["IsImageFile"] = isImageFile
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(userName, repoName, "src", commitId)
+ ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", commitId)
ctx.HTML(200, "repo/diff")
}