]> source.dussan.org Git - gitea.git/commitdiff
Fix #166
authorUnknown <joe2010xtmf@163.com>
Tue, 13 May 2014 00:22:35 +0000 (20:22 -0400)
committerUnknown <joe2010xtmf@163.com>
Tue, 13 May 2014 00:22:35 +0000 (20:22 -0400)
cmd/web.go
routers/repo/commit.go
routers/repo/repo.go
templates/repo/commits.tmpl
templates/repo/single_file.tmpl

index b8cfc5a4f5e13b396005ee140f467da1c6235d45..c343566d70bea4d430e6f48b343620de404da04a 100644 (file)
@@ -210,6 +210,7 @@ func runWeb(*cli.Context) {
                r.Get("/raw/:branchname/**", repo.SingleDownload)
                r.Get("/commits/:branchname", repo.Commits)
                r.Get("/commits/:branchname/search", repo.SearchCommits)
+               r.Get("/commits/:branchname/**", repo.FileHistory)
                r.Get("/commit/:branchname", repo.Diff)
                r.Get("/commit/:branchname/**", repo.Diff)
                r.Get("/releases", repo.Releases)
index bc33fe44739a6520a98fdbe0dc9ced3085a54d6c..88b6593e76f2da355610580db81152a8d1433b24 100644 (file)
@@ -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")
+}
index 19c9dddc6ee58220e042f8670f053715b598eba7..7769d22774efd010e710bd6e093bd6d66f02e94c 100644 (file)
@@ -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
index 74b03074bc8f728a3c1da35943beac276260b7a7..385f9d5bae93f4a7f1e5506552c157ed9364d1fb 100644 (file)
@@ -41,8 +41,8 @@
             </table>
         </div>
         {{if not .IsSearchPage}}<ul class="pagination" id="commits-pager">
-            {{if .LastPageNum}}<li><a href="{{.RepoLink}}/commits/{{.BranchName}}?p={{.LastPageNum}}" rel="nofollow">&laquo; Newer</a></li>{{end}}
-            {{if .NextPageNum}}<li><a href="{{.RepoLink}}/commits/{{.BranchName}}?p={{.NextPageNum}}" rel="nofollow">&raquo; Older</a></li>{{end}}
+            {{if .LastPageNum}}<li><a href="{{.RepoLink}}/commits/{{.BranchName}}{{if .FileName}}/{{.FileName}}{{end}}?p={{.LastPageNum}}" rel="nofollow">&laquo; Newer</a></li>{{end}}
+            {{if .NextPageNum}}<li><a href="{{.RepoLink}}/commits/{{.BranchName}}{{if .FileName}}/{{.FileName}}{{end}}?p={{.NextPageNum}}" rel="nofollow">&raquo; Older</a></li>{{end}}
         </ul>{{end}}
     </div>
 </div>
index 95c41b7017948fe055d2c6011de8ff1d22192453..8c09f3ec1c6923c16fce0284c276d1dc999f2b6d 100644 (file)
@@ -16,7 +16,7 @@
             <a class="btn btn-default hidden" href="#">Edit</a>
             <a class="btn btn-default" href="{{.FileLink}}" rel="nofollow">Raw</a>
             <a class="btn btn-default hidden" href="#">Blame</a>
-            <a class="btn btn-default hidden" href="#">History</a>
+            <a class="btn btn-default" href="{{.RepoLink}}/commits/{{.BranchName}}/{{.TreeName}}">History</a>
             <a class="btn btn-danger hidden" href="#">Delete</a>
         </div>
         {{end}}