aboutsummaryrefslogtreecommitdiff
path: root/routers/repo/commit.go
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-11-06 22:06:41 -0500
committerUnknwon <joe2010xtmf@163.com>2014-11-06 22:06:41 -0500
commit23eec252748c3ac7af2ae310aeac4ee4c9061fe9 (patch)
tree9f9d8834ef94451da2fb1d43ba63d0f130d61f79 /routers/repo/commit.go
parent4e7eb5be9d3e9c9ba7238769d2b5f2f471d51b67 (diff)
Fix #605, fix #255, fix #101
Diffstat (limited to 'routers/repo/commit.go')
1 files changed, 74 insertions, 63 deletions
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index b2c2e0f9..f060133a 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -20,6 +20,17 @@ const (
DIFF base.TplName = "repo/diff"
)
+func RefCommits(ctx *middleware.Context) {
+ switch {
+ case len(ctx.Repo.TreeName) == 0:
+ Commits(ctx)
+ case ctx.Repo.TreeName == "search":
+ SearchCommits(ctx)
+ default:
+ FileHistory(ctx)
+ }
+}
+
func Commits(ctx *middleware.Context) {
ctx.Data["IsRepoToolbarCommits"] = true
@@ -109,6 +120,69 @@ func SearchCommits(ctx *middleware.Context) {
ctx.HTML(200, COMMITS)
}
+func FileHistory(ctx *middleware.Context) {
+ ctx.Data["IsRepoToolbarCommits"] = true
+
+ fileName := ctx.Repo.TreeName
+ if len(fileName) == 0 {
+ Commits(ctx)
+ return
+ }
+
+ userName := ctx.Repo.Owner.Name
+ repoName := ctx.Repo.Repository.Name
+ branchName := ctx.Repo.BranchName
+
+ brs, err := ctx.Repo.GitRepo.GetBranches()
+ if err != nil {
+ ctx.Handle(500, "GetBranches", err)
+ return
+ } else if len(brs) == 0 {
+ ctx.Handle(404, "GetBranches", nil)
+ return
+ }
+
+ commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName)
+ if err != nil {
+ ctx.Handle(500, "repo.FileHistory(GetCommitsCount)", err)
+ return
+ } else if commitsCount == 0 {
+ ctx.Handle(404, "repo.FileHistory", nil)
+ return
+ }
+
+ // Calculate and validate page number.
+ page := com.StrTo(ctx.Query("p")).MustInt()
+ if page < 1 {
+ page = 1
+ }
+ lastPage := page - 1
+ if lastPage < 0 {
+ lastPage = 0
+ }
+ nextPage := page + 1
+ if nextPage*50 > commitsCount {
+ nextPage = 0
+ }
+
+ commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(
+ branchName, fileName, page)
+ if err != nil {
+ ctx.Handle(500, "repo.FileHistory(CommitsByRange)", err)
+ return
+ }
+ commits = models.ValidateCommitsWithEmails(commits)
+
+ ctx.Data["Commits"] = commits
+ ctx.Data["Username"] = userName
+ ctx.Data["Reponame"] = repoName
+ ctx.Data["FileName"] = fileName
+ ctx.Data["CommitCount"] = commitsCount
+ ctx.Data["LastPageNum"] = lastPage
+ ctx.Data["NextPageNum"] = nextPage
+ ctx.HTML(200, COMMITS)
+}
+
func Diff(ctx *middleware.Context) {
ctx.Data["IsRepoToolbarCommits"] = true
@@ -230,66 +304,3 @@ func CompareDiff(ctx *middleware.Context) {
ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", afterCommitId)
ctx.HTML(200, DIFF)
}
-
-func FileHistory(ctx *middleware.Context) {
- ctx.Data["IsRepoToolbarCommits"] = true
-
- fileName := ctx.Params("*")
- if len(fileName) == 0 {
- Commits(ctx)
- return
- }
-
- userName := ctx.Repo.Owner.Name
- repoName := ctx.Repo.Repository.Name
- branchName := ctx.Params(":branchname")
-
- brs, err := ctx.Repo.GitRepo.GetBranches()
- if err != nil {
- ctx.Handle(500, "GetBranches", err)
- return
- } else if len(brs) == 0 {
- ctx.Handle(404, "GetBranches", nil)
- return
- }
-
- commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName)
- if err != nil {
- ctx.Handle(500, "repo.FileHistory(GetCommitsCount)", err)
- return
- } else if commitsCount == 0 {
- ctx.Handle(404, "repo.FileHistory", nil)
- return
- }
-
- // Calculate and validate page number.
- page := com.StrTo(ctx.Query("p")).MustInt()
- if page < 1 {
- page = 1
- }
- lastPage := page - 1
- if lastPage < 0 {
- lastPage = 0
- }
- nextPage := page + 1
- if nextPage*50 > commitsCount {
- nextPage = 0
- }
-
- commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(
- branchName, fileName, page)
- if err != nil {
- ctx.Handle(500, "repo.FileHistory(CommitsByRange)", err)
- return
- }
- commits = models.ValidateCommitsWithEmails(commits)
-
- ctx.Data["Commits"] = commits
- ctx.Data["Username"] = userName
- ctx.Data["Reponame"] = repoName
- ctx.Data["FileName"] = fileName
- ctx.Data["CommitCount"] = commitsCount
- ctx.Data["LastPageNum"] = lastPage
- ctx.Data["NextPageNum"] = nextPage
- ctx.HTML(200, COMMITS)
-}