summaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-12 20:22:35 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-12 20:22:35 -0400
commitc117f9e73f148468c624f31be237af7a691533a0 (patch)
treebf1188d2f6f2df4d58f410d9e52ca33c9dfee302 /routers/repo
parentf979d0d6b9ae2c4b5c553df13dfe49b81d8396c1 (diff)
downloadgitea-c117f9e73f148468c624f31be237af7a691533a0.tar.gz
gitea-c117f9e73f148468c624f31be237af7a691533a0.zip
Fix #166
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/commit.go66
-rw-r--r--routers/repo/repo.go1
2 files changed, 65 insertions, 2 deletions
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index bc33fe4473..88b6593e76 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -47,10 +47,10 @@ func Commits(ctx *middleware.Context, params martini.Params) {
nextPage = 0
}
- //both `git log branchName` and `git log commitId` work
+ //both `git log branchName` and `git log commitId` work
commits, err := ctx.Repo.Commit.CommitsByRange(page)
if err != nil {
- ctx.Handle(500, "repo.Commits(get commits)", err)
+ ctx.Handle(500, "repo.Commits(CommitsByRange)", err)
return
}
@@ -149,3 +149,65 @@ func SearchCommits(ctx *middleware.Context, params martini.Params) {
ctx.Data["IsRepoToolbarCommits"] = true
ctx.HTML(200, "repo/commits")
}
+
+func FileHistory(ctx *middleware.Context, params martini.Params) {
+ fileName := params["_1"]
+ if len(fileName) == 0 {
+ Commits(ctx, params)
+ return
+ }
+
+ userName := ctx.Repo.Owner.Name
+ repoName := ctx.Repo.Repository.Name
+ branchName := params["branchname"]
+
+ brs, err := ctx.Repo.GitRepo.GetBranches()
+ if err != nil {
+ ctx.Handle(500, "repo.FileHistory", err)
+ return
+ } else if len(brs) == 0 {
+ ctx.Handle(404, "repo.FileHistory", nil)
+ return
+ }
+
+ commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName)
+ if err != nil {
+ ctx.Handle(500, "repo.FileHistory(GetCommitsCount)", err)
+ return
+ }
+ if commitsCount == 0 {
+ ctx.Handle(404, "repo.FileHistory", nil)
+ return
+ }
+
+ // Calculate and validate page number.
+ page, _ := base.StrTo(ctx.Query("p")).Int()
+ if page < 1 {
+ page = 1
+ }
+ lastPage := page - 1
+ if lastPage < 0 {
+ lastPage = 0
+ }
+ nextPage := page + 1
+ if nextPage*50 > commitsCount {
+ nextPage = 0
+ }
+
+ //both `git log branchName` and `git log commitId` work
+ commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page)
+ if err != nil {
+ ctx.Handle(500, "repo.FileHistory(CommitsByRange)", err)
+ return
+ }
+
+ ctx.Data["Username"] = userName
+ ctx.Data["Reponame"] = repoName
+ ctx.Data["FileName"] = fileName
+ ctx.Data["CommitCount"] = commitsCount
+ ctx.Data["Commits"] = commits
+ ctx.Data["LastPageNum"] = lastPage
+ ctx.Data["NextPageNum"] = nextPage
+ ctx.Data["IsRepoToolbarCommits"] = true
+ ctx.HTML(200, "repo/commits")
+}
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index 19c9dddc6e..7769d22774 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -254,6 +254,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
ctx.Data["LastCommit"] = ctx.Repo.Commit
ctx.Data["Paths"] = Paths
+ ctx.Data["TreeName"] = treename
ctx.Data["Treenames"] = treenames
ctx.Data["TreePath"] = treePath
ctx.Data["BranchLink"] = branchLink