Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pagination to commit graph page #8360

Merged
merged 4 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion models/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type GraphItem struct {
type GraphItems []GraphItem

// GetCommitGraph return a list of commit (GraphItems) from all branches
func GetCommitGraph(r *git.Repository) (GraphItems, error) {
func GetCommitGraph(r *git.Repository, page int) (GraphItems, error) {

var CommitGraph []GraphItem

Expand All @@ -43,6 +43,7 @@ func GetCommitGraph(r *git.Repository) (GraphItems, error) {
"-C",
"-M",
fmt.Sprintf("-n %d", setting.UI.GraphMaxCommitNum),
fmt.Sprintf("--skip=%d", setting.UI.GraphMaxCommitNum*(page-1)),
"--date=iso",
fmt.Sprintf("--pretty=format:%s", format),
)
Expand Down
2 changes: 1 addition & 1 deletion models/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func BenchmarkGetCommitGraph(b *testing.B) {
}

for i := 0; i < b.N; i++ {
graph, err := GetCommitGraph(currentRepo)
graph, err := GetCommitGraph(currentRepo, 1)
if err != nil {
b.Error("Could get commit graph")
}
Expand Down
6 changes: 4 additions & 2 deletions routers/repo/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ func Graph(ctx *context.Context) {
return
}

graph, err := models.GetCommitGraph(ctx.Repo.GitRepo)
page := ctx.QueryInt("page")

graph, err := models.GetCommitGraph(ctx.Repo.GitRepo, page)
if err != nil {
ctx.ServerError("GetCommitGraph", err)
return
Expand All @@ -103,8 +105,8 @@ func Graph(ctx *context.Context) {
ctx.Data["CommitCount"] = commitsCount
ctx.Data["Branch"] = ctx.Repo.BranchName
ctx.Data["RequireGitGraph"] = true
ctx.Data["Page"] = context.NewPagination(int(commitsCount), setting.UI.GraphMaxCommitNum, page, 5)
ctx.HTML(200, tplGraph)

}

// SearchCommits render commits filtered by keyword
Expand Down
1 change: 1 addition & 0 deletions templates/repo/graph.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@
</div>
</div>
</div>
{{template "base/paginate" .}}
{{template "base/footer" .}}