Pages in commits list page

tokarchuk/v1.17
Unknown 11 years ago
parent 47aa53bd36
commit d6dac160df
  1. 2
      README.md
  2. 2
      README_ZH.md
  3. 2
      gogs.go
  4. 23
      models/git.go
  5. 31
      routers/repo/commit.go
  6. 13
      templates/repo/commits.tmpl

@ -5,7 +5,7 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language
![Demo](http://gowalker.org/public/gogs_demo.gif) ![Demo](http://gowalker.org/public/gogs_demo.gif)
##### Current version: 0.2.5 Alpha ##### Current version: 0.2.6 Alpha
#### Due to testing purpose, data of [try.gogits.org](http://try.gogits.org) has been reset in April 6, 2014 and will reset multiple times after. Please do NOT put your important data on the site. #### Due to testing purpose, data of [try.gogits.org](http://try.gogits.org) has been reset in April 6, 2014 and will reset multiple times after. Please do NOT put your important data on the site.

@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个由 Go 语言编写的自助 Git 托管服务。
![Demo](http://gowalker.org/public/gogs_demo.gif) ![Demo](http://gowalker.org/public/gogs_demo.gif)
##### 当前版本:0.2.5 Alpha ##### 当前版本:0.2.6 Alpha
## 开发目的 ## 开发目的

@ -19,7 +19,7 @@ import (
// Test that go1.2 tag above is included in builds. main.go refers to this definition. // Test that go1.2 tag above is included in builds. main.go refers to this definition.
const go12tag = true const go12tag = true
const APP_VER = "0.2.5.0410 Alpha" const APP_VER = "0.2.6.0411 Alpha"
func init() { func init() {
base.AppVer = APP_VER base.AppVer = APP_VER

@ -470,3 +470,26 @@ func SearchCommits(repoPath, branch, keyword string) (*list.List, error) {
} }
return parsePrettyFormatLog(stdout) return parsePrettyFormatLog(stdout)
} }
// GetCommitsByRange returns certain number of commits with given page of repository.
func GetCommitsByRange(repoPath, branch string, page int) (*list.List, error) {
stdout, stderr, err := com.ExecCmdDirBytes(repoPath, "git", "log", branch,
"--skip="+base.ToStr((page-1)*50), "--max-count=50", prettyLogFormat)
if err != nil {
return nil, err
} else if len(stderr) > 0 {
return nil, errors.New(string(stderr))
}
return parsePrettyFormatLog(stdout)
}
// GetCommitsCount returns the commits count of given branch of repository.
func GetCommitsCount(repoPath, branch string) (int, error) {
stdout, stderr, err := com.ExecCmdDir(repoPath, "git", "rev-list", "--count", branch)
if err != nil {
return 0, err
} else if len(stderr) > 0 {
return 0, errors.New(stderr)
}
return base.StrTo(strings.TrimSpace(stdout)).Int()
}

@ -29,22 +29,46 @@ func Commits(ctx *middleware.Context, params martini.Params) {
return return
} }
repoPath := models.RepoPath(userName, repoName)
commitsCount, err := models.GetCommitsCount(repoPath, branchName)
if err != nil {
ctx.Handle(500, "repo.Commits(GetCommitsCount)", err)
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
}
var commits *list.List var commits *list.List
if models.IsBranchExist(userName, repoName, branchName) { if models.IsBranchExist(userName, repoName, branchName) {
commits, err = models.GetCommitsByBranch(userName, repoName, branchName) // commits, err = models.GetCommitsByBranch(userName, repoName, branchName)
commits, err = models.GetCommitsByRange(repoPath, branchName, page)
} else { } else {
commits, err = models.GetCommitsByCommitId(userName, repoName, branchName) commits, err = models.GetCommitsByCommitId(userName, repoName, branchName)
} }
if err != nil { if err != nil {
ctx.Handle(404, "repo.Commits", err) ctx.Handle(404, "repo.Commits(get commits)", err)
return return
} }
ctx.Data["Username"] = userName ctx.Data["Username"] = userName
ctx.Data["Reponame"] = repoName ctx.Data["Reponame"] = repoName
ctx.Data["CommitCount"] = commits.Len() ctx.Data["CommitCount"] = commitsCount
ctx.Data["Commits"] = commits ctx.Data["Commits"] = commits
ctx.Data["LastPageNum"] = lastPage
ctx.Data["NextPageNum"] = nextPage
ctx.Data["IsRepoToolbarCommits"] = true ctx.Data["IsRepoToolbarCommits"] = true
ctx.HTML(200, "repo/commits") ctx.HTML(200, "repo/commits")
} }
@ -125,6 +149,7 @@ func SearchCommits(ctx *middleware.Context, params martini.Params) {
ctx.Data["Reponame"] = repoName ctx.Data["Reponame"] = repoName
ctx.Data["CommitCount"] = commits.Len() ctx.Data["CommitCount"] = commits.Len()
ctx.Data["Commits"] = commits ctx.Data["Commits"] = commits
ctx.Data["IsSearchPage"] = true
ctx.Data["IsRepoToolbarCommits"] = true ctx.Data["IsRepoToolbarCommits"] = true
ctx.HTML(200, "repo/commits") ctx.HTML(200, "repo/commits")
} }

@ -40,15 +40,10 @@
</tbody> </tbody>
</table> </table>
</div> </div>
<ul class="pagination" id="commits-pager"> {{if not .IsSearchPage}}<ul class="pagination" id="commits-pager">
<li><a href="#">&laquo;</a></li> {{if .LastPageNum}}<li><a href="{{.RepoLink}}/commits/{{.BranchName}}?p={{.LastPageNum}}">&laquo; Newer</a></li>{{end}}
<li><a href="#">1</a></li> {{if .NextPageNum}}<li><a href="{{.RepoLink}}/commits/{{.BranchName}}?p={{.NextPageNum}}">&raquo; Older</a></li>{{end}}
<li><a href="#">2</a></li> </ul>{{end}}
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">&raquo;</a></li>
</ul>
</div> </div>
</div> </div>
{{template "base/footer" .}} {{template "base/footer" .}}

Loading…
Cancel
Save