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

Fix count for commit graph last page #8843

Merged
merged 6 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
14 changes: 14 additions & 0 deletions modules/git/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,20 @@ func CommitChanges(repoPath string, opts CommitChangesOptions) error {
return err
}

func allCommitsCount(repoPath string) (int64, error) {
stdout, err := NewCommand("rev-list", "--all", "--count").RunInDir(repoPath)
if err != nil {
return 0, err
}

return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
}

// AllCommitsCount returns count of all commits in repository
func AllCommitsCount(repoPath string) (int64, error) {
return allCommitsCount(repoPath)
lafriks marked this conversation as resolved.
Show resolved Hide resolved
}

func commitsCount(repoPath, revision, relpath string) (int64, error) {
cmd := NewCommand("rev-list", "--count")
cmd.AddArguments(revision)
Expand Down
8 changes: 7 additions & 1 deletion routers/repo/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ func Graph(ctx *context.Context) {
return
}

allCommitsCount, err := git.AllCommitsCount(ctx.Repo.GitRepo.Path)
if err != nil {
ctx.ServerError("AllCommitsCount", err)
return
}

page := ctx.QueryInt("page")

graph, err := models.GetCommitGraph(ctx.Repo.GitRepo, page)
Expand All @@ -105,7 +111,7 @@ 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.Data["Page"] = context.NewPagination(int(allCommitsCount), setting.UI.GraphMaxCommitNum, page, 5)
ctx.HTML(200, tplGraph)
}

Expand Down