fix #1572 fix file histrory paging issue
This commit is contained in:
parent
2db785b3ed
commit
3b62a0fe0e
6 changed files with 23 additions and 69 deletions
|
@ -5,7 +5,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
|
||||||
|
|
||||||
![](public/img/gogs-large-resize.png)
|
![](public/img/gogs-large-resize.png)
|
||||||
|
|
||||||
##### Current version: 0.7.2 Beta
|
##### Current version: 0.7.4 Beta
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.7.2.1109 Beta"
|
const APP_VER = "0.7.4.1110 Beta"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
|
@ -107,7 +107,6 @@ func (options *CustomRender) Image(out *bytes.Buffer, link []byte, title []byte,
|
||||||
}
|
}
|
||||||
link = []byte(prefix + string(link))
|
link = []byte(prefix + string(link))
|
||||||
}
|
}
|
||||||
fmt.Println(2, string(link))
|
|
||||||
|
|
||||||
out.WriteString(`<a href="`)
|
out.WriteString(`<a href="`)
|
||||||
out.Write(link)
|
out.Write(link)
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"container/list"
|
"container/list"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
|
||||||
"github.com/Unknwon/paginater"
|
"github.com/Unknwon/paginater"
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
|
@ -46,18 +45,6 @@ func RenderIssueLinks(oldCommits *list.List, repoLink string) *list.List {
|
||||||
func Commits(ctx *middleware.Context) {
|
func Commits(ctx *middleware.Context) {
|
||||||
ctx.Data["PageIsCommits"] = true
|
ctx.Data["PageIsCommits"] = true
|
||||||
|
|
||||||
userName := ctx.Repo.Owner.Name
|
|
||||||
repoName := ctx.Repo.Repository.Name
|
|
||||||
|
|
||||||
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.Commit.CommitsCount()
|
commitsCount, err := ctx.Repo.Commit.CommitsCount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "GetCommitsCount", err)
|
ctx.Handle(500, "GetCommitsCount", err)
|
||||||
|
@ -78,11 +65,12 @@ func Commits(ctx *middleware.Context) {
|
||||||
}
|
}
|
||||||
commits = RenderIssueLinks(commits, ctx.Repo.RepoLink)
|
commits = RenderIssueLinks(commits, ctx.Repo.RepoLink)
|
||||||
commits = models.ValidateCommitsWithEmails(commits)
|
commits = models.ValidateCommitsWithEmails(commits)
|
||||||
|
|
||||||
ctx.Data["Commits"] = commits
|
ctx.Data["Commits"] = commits
|
||||||
ctx.Data["Username"] = userName
|
|
||||||
ctx.Data["Reponame"] = repoName
|
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
||||||
|
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
|
||||||
ctx.Data["CommitCount"] = commitsCount
|
ctx.Data["CommitCount"] = commitsCount
|
||||||
|
ctx.Data["Branch"] = ctx.Repo.BranchName
|
||||||
ctx.HTML(200, COMMITS)
|
ctx.HTML(200, COMMITS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,18 +83,6 @@ func SearchCommits(ctx *middleware.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userName := ctx.Params(":username")
|
|
||||||
repoName := ctx.Params(":reponame")
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
commits, err := ctx.Repo.Commit.SearchCommits(keyword)
|
commits, err := ctx.Repo.Commit.SearchCommits(keyword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "SearchCommits", err)
|
ctx.Handle(500, "SearchCommits", err)
|
||||||
|
@ -114,12 +90,13 @@ func SearchCommits(ctx *middleware.Context) {
|
||||||
}
|
}
|
||||||
commits = RenderIssueLinks(commits, ctx.Repo.RepoLink)
|
commits = RenderIssueLinks(commits, ctx.Repo.RepoLink)
|
||||||
commits = models.ValidateCommitsWithEmails(commits)
|
commits = models.ValidateCommitsWithEmails(commits)
|
||||||
|
ctx.Data["Commits"] = commits
|
||||||
|
|
||||||
ctx.Data["Keyword"] = keyword
|
ctx.Data["Keyword"] = keyword
|
||||||
ctx.Data["Username"] = userName
|
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
||||||
ctx.Data["Reponame"] = repoName
|
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
|
||||||
ctx.Data["CommitCount"] = commits.Len()
|
ctx.Data["CommitCount"] = commits.Len()
|
||||||
ctx.Data["Commits"] = commits
|
ctx.Data["Branch"] = ctx.Repo.BranchName
|
||||||
ctx.HTML(200, COMMITS)
|
ctx.HTML(200, COMMITS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,58 +109,36 @@ func FileHistory(ctx *middleware.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userName := ctx.Repo.Owner.Name
|
|
||||||
repoName := ctx.Repo.Repository.Name
|
|
||||||
branchName := ctx.Repo.BranchName
|
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)
|
commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "repo.FileHistory(GetCommitsCount)", err)
|
ctx.Handle(500, "FileCommitsCount", err)
|
||||||
return
|
return
|
||||||
} else if commitsCount == 0 {
|
} else if commitsCount == 0 {
|
||||||
ctx.Handle(404, "repo.FileHistory", nil)
|
ctx.Handle(404, "FileCommitsCount", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate and validate page number.
|
page := ctx.QueryInt("page")
|
||||||
page := com.StrTo(ctx.Query("p")).MustInt()
|
if page <= 1 {
|
||||||
if page < 1 {
|
|
||||||
page = 1
|
page = 1
|
||||||
}
|
}
|
||||||
lastPage := page - 1
|
ctx.Data["Page"] = paginater.New(commitsCount, git.CommitsRangeSize, page, 5)
|
||||||
if lastPage < 0 {
|
|
||||||
lastPage = 0
|
|
||||||
}
|
|
||||||
nextPage := page + 1
|
|
||||||
if nextPage*50 > commitsCount {
|
|
||||||
nextPage = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(
|
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page)
|
||||||
branchName, fileName, page)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "repo.FileHistory(CommitsByRange)", err)
|
ctx.Handle(500, "CommitsByFileAndRange", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
commits = RenderIssueLinks(commits, ctx.Repo.RepoLink)
|
commits = RenderIssueLinks(commits, ctx.Repo.RepoLink)
|
||||||
commits = models.ValidateCommitsWithEmails(commits)
|
commits = models.ValidateCommitsWithEmails(commits)
|
||||||
|
|
||||||
ctx.Data["Commits"] = commits
|
ctx.Data["Commits"] = commits
|
||||||
ctx.Data["Username"] = userName
|
|
||||||
ctx.Data["Reponame"] = repoName
|
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
||||||
|
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
|
||||||
ctx.Data["FileName"] = fileName
|
ctx.Data["FileName"] = fileName
|
||||||
ctx.Data["CommitCount"] = commitsCount
|
ctx.Data["CommitCount"] = commitsCount
|
||||||
ctx.Data["LastPageNum"] = lastPage
|
ctx.Data["Branch"] = branchName
|
||||||
ctx.Data["NextPageNum"] = nextPage
|
|
||||||
ctx.HTML(200, COMMITS)
|
ctx.HTML(200, COMMITS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.7.2.1109 Beta
|
0.7.4.1110 Beta
|
|
@ -1,5 +1,5 @@
|
||||||
<h4 class="ui top attached header">
|
<h4 class="ui top attached header">
|
||||||
{{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}}
|
{{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}} {{if .Branch}}({{.Branch}}){{end}}
|
||||||
{{if .PageIsCommits}}
|
{{if .PageIsCommits}}
|
||||||
<div class="ui right">
|
<div class="ui right">
|
||||||
<form action="{{.RepoLink}}/commits/{{.BranchName}}/search">
|
<form action="{{.RepoLink}}/commits/{{.BranchName}}/search">
|
||||||
|
|
Loading…
Reference in a new issue