From 21f2e41b7ed9f042d5efaf870d92bd4d33967f33 Mon Sep 17 00:00:00 2001 From: jaqra Date: Tue, 5 Nov 2019 20:28:28 +0300 Subject: [PATCH 1/5] Fix count for commit graph last page --- modules/git/commit.go | 16 ++++++++++++++++ routers/repo/commit.go | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/git/commit.go b/modules/git/commit.go index 45b943e79eef6..52e1eb89af8d6 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -248,6 +248,22 @@ func CommitChanges(repoPath string, opts CommitChangesOptions) error { return err } +func allCommitsCount(repoPath string) (int64, error) { + cmd := NewCommand("rev-list", "--all", "--count") + + stdout, err := cmd.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) +} + func commitsCount(repoPath, revision, relpath string) (int64, error) { cmd := NewCommand("rev-list", "--count") cmd.AddArguments(revision) diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 550e4c3a9cd6d..de1b7660a3361 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -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) @@ -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) } From 22871a6bbff56a393162ca96a2c38bd6f6f69564 Mon Sep 17 00:00:00 2001 From: jaqra Date: Tue, 5 Nov 2019 22:19:41 +0300 Subject: [PATCH 2/5] Remove used once variable --- modules/git/commit.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/git/commit.go b/modules/git/commit.go index 52e1eb89af8d6..42a415383720a 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -249,9 +249,7 @@ func CommitChanges(repoPath string, opts CommitChangesOptions) error { } func allCommitsCount(repoPath string) (int64, error) { - cmd := NewCommand("rev-list", "--all", "--count") - - stdout, err := cmd.RunInDir(repoPath) + stdout, err := NewCommand("rev-list", "--all", "--count").RunInDir(repoPath) if err != nil { return 0, err } From ddbc8843cbf16d653c4928a408205ecd1e2089c1 Mon Sep 17 00:00:00 2001 From: jaqra Date: Wed, 6 Nov 2019 20:28:03 +0300 Subject: [PATCH 3/5] Move func to model --- modules/git/commit.go | 5 ----- modules/git/repo.go | 5 +++++ routers/repo/commit.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/git/commit.go b/modules/git/commit.go index 42a415383720a..1f603ce24dcd3 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -257,11 +257,6 @@ func allCommitsCount(repoPath string) (int64, error) { 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) -} - func commitsCount(repoPath, revision, relpath string) (int64, error) { cmd := NewCommand("rev-list", "--count") cmd.AddArguments(revision) diff --git a/modules/git/repo.go b/modules/git/repo.go index e1d75ca4aaa52..7640a465cdee2 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -46,6 +46,11 @@ type GPGSettings struct { const prettyLogFormat = `--pretty=format:%H` +// GetAllCommitsCount returns count of all commits in repository +func (repo *Repository) GetAllCommitsCount() (int64, error) { + return allCommitsCount(repo.Path) +} + func (repo *Repository) parsePrettyFormatLogToList(logs []byte) (*list.List, error) { l := list.New() if len(logs) == 0 { diff --git a/routers/repo/commit.go b/routers/repo/commit.go index de1b7660a3361..b3176e4801041 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -91,7 +91,7 @@ func Graph(ctx *context.Context) { return } - allCommitsCount, err := git.AllCommitsCount(ctx.Repo.GitRepo.Path) + allCommitsCount, err := ctx.Repo.GitRepo.GetAllCommitsCount() if err != nil { ctx.ServerError("AllCommitsCount", err) return From b719174d01815ecf2d668d4d2032f88196e0036e Mon Sep 17 00:00:00 2001 From: jaqra Date: Wed, 6 Nov 2019 20:47:12 +0300 Subject: [PATCH 4/5] capitalize method name --- modules/git/commit.go | 3 ++- modules/git/repo.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/git/commit.go b/modules/git/commit.go index 1f603ce24dcd3..ce55dd55f633a 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -248,7 +248,8 @@ func CommitChanges(repoPath string, opts CommitChangesOptions) error { return err } -func allCommitsCount(repoPath string) (int64, error) { +// AllCommitsCount returns count of all commits in repository +func AllCommitsCount(repoPath string) (int64, error) { stdout, err := NewCommand("rev-list", "--all", "--count").RunInDir(repoPath) if err != nil { return 0, err diff --git a/modules/git/repo.go b/modules/git/repo.go index 7640a465cdee2..4c6690b9133e5 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -48,7 +48,7 @@ const prettyLogFormat = `--pretty=format:%H` // GetAllCommitsCount returns count of all commits in repository func (repo *Repository) GetAllCommitsCount() (int64, error) { - return allCommitsCount(repo.Path) + return AllCommitsCount(repo.Path) } func (repo *Repository) parsePrettyFormatLogToList(logs []byte) (*list.List, error) { From d25710a9010598bee53c78220c4073b7feb6e51b Mon Sep 17 00:00:00 2001 From: jaqra Date: Wed, 6 Nov 2019 22:25:43 +0300 Subject: [PATCH 5/5] fix error message --- routers/repo/commit.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/repo/commit.go b/routers/repo/commit.go index b3176e4801041..f067729ca94de 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -93,7 +93,7 @@ func Graph(ctx *context.Context) { allCommitsCount, err := ctx.Repo.GitRepo.GetAllCommitsCount() if err != nil { - ctx.ServerError("AllCommitsCount", err) + ctx.ServerError("GetAllCommitsCount", err) return }