Skip to content

Commit 086bfb8

Browse files
jaqrazeripath
jaqra
authored andcommitted
Add pagination to commit graph page (#8360)
Fixes #8308
1 parent 3083522 commit 086bfb8

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

models/graph.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type GraphItem struct {
3030
type GraphItems []GraphItem
3131

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

3535
var CommitGraph []GraphItem
3636

@@ -43,6 +43,7 @@ func GetCommitGraph(r *git.Repository) (GraphItems, error) {
4343
"-C",
4444
"-M",
4545
fmt.Sprintf("-n %d", setting.UI.GraphMaxCommitNum),
46+
fmt.Sprintf("--skip=%d", setting.UI.GraphMaxCommitNum*(page-1)),
4647
"--date=iso",
4748
fmt.Sprintf("--pretty=format:%s", format),
4849
)

models/graph_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func BenchmarkGetCommitGraph(b *testing.B) {
1919
}
2020

2121
for i := 0; i < b.N; i++ {
22-
graph, err := GetCommitGraph(currentRepo)
22+
graph, err := GetCommitGraph(currentRepo, 1)
2323
if err != nil {
2424
b.Error("Could get commit graph")
2525
}

routers/repo/commit.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ func Graph(ctx *context.Context) {
9191
return
9292
}
9393

94-
graph, err := models.GetCommitGraph(ctx.Repo.GitRepo)
94+
page := ctx.QueryInt("page")
95+
96+
graph, err := models.GetCommitGraph(ctx.Repo.GitRepo, page)
9597
if err != nil {
9698
ctx.ServerError("GetCommitGraph", err)
9799
return
@@ -103,8 +105,8 @@ func Graph(ctx *context.Context) {
103105
ctx.Data["CommitCount"] = commitsCount
104106
ctx.Data["Branch"] = ctx.Repo.BranchName
105107
ctx.Data["RequireGitGraph"] = true
108+
ctx.Data["Page"] = context.NewPagination(int(commitsCount), setting.UI.GraphMaxCommitNum, page, 5)
106109
ctx.HTML(200, tplGraph)
107-
108110
}
109111

110112
// SearchCommits render commits filtered by keyword

templates/repo/graph.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@
3737
</div>
3838
</div>
3939
</div>
40+
{{template "base/paginate" .}}
4041
{{template "base/footer" .}}

0 commit comments

Comments
 (0)