diff options
author | Matthew Walowski <mattwalowski@gmail.com> | 2023-05-08 00:10:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-08 07:10:53 +0000 |
commit | ff5629268c5c01d3f460570baa571baef3f896cd (patch) | |
tree | d0e85b7ca946b93bc7d74d30436aabcebb59dc27 /routers | |
parent | e962ade99cfd0471273f3dcf956c7cd222472758 (diff) | |
download | gitea-ff5629268c5c01d3f460570baa571baef3f896cd.tar.gz gitea-ff5629268c5c01d3f460570baa571baef3f896cd.zip |
Pass 'not' to commit count (#24473)
Due to #24409 , we can now specify '--not' when getting all commits from
a repo to exclude commits from a different branch.
When I wrote that PR, I forgot to also update the code that counts the
number of commits in the repo. So now, if the --not option is used, it
may return too many commits, which can indicate that another page of
data is available when it is not.
This PR passes --not to the commands that count the number of commits in
a repo
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/commits.go | 27 | ||||
-rw-r--r-- | routers/api/v1/repo/wiki.go | 7 | ||||
-rw-r--r-- | routers/web/feed/file.go | 8 | ||||
-rw-r--r-- | routers/web/repo/commit.go | 7 | ||||
-rw-r--r-- | routers/web/repo/wiki.go | 7 |
5 files changed, 48 insertions, 8 deletions
diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go index 401403c83d..a5e2e7baef 100644 --- a/routers/api/v1/repo/commits.go +++ b/routers/api/v1/repo/commits.go @@ -146,6 +146,7 @@ func GetAllCommits(ctx *context.APIContext) { sha := ctx.FormString("sha") path := ctx.FormString("path") + not := ctx.FormString("not") var ( commitsCountTotal int64 @@ -178,14 +179,18 @@ func GetAllCommits(ctx *context.APIContext) { } // Total commit count - commitsCountTotal, err = baseCommit.CommitsCount() + commitsCountTotal, err = git.CommitsCount(ctx.Repo.GitRepo.Ctx, git.CommitsCountOptions{ + RepoPath: ctx.Repo.GitRepo.Path, + Not: not, + Revision: []string{baseCommit.ID.String()}, + }) + if err != nil { ctx.Error(http.StatusInternalServerError, "GetCommitsCount", err) return } // Query commits - not := ctx.FormString("not") commits, err = baseCommit.CommitsByRange(listOptions.Page, listOptions.PageSize, not) if err != nil { ctx.Error(http.StatusInternalServerError, "CommitsByRange", err) @@ -196,7 +201,14 @@ func GetAllCommits(ctx *context.APIContext) { sha = ctx.Repo.Repository.DefaultBranch } - commitsCountTotal, err = ctx.Repo.GitRepo.FileCommitsCount(sha, path) + commitsCountTotal, err = git.CommitsCount(ctx, + git.CommitsCountOptions{ + RepoPath: ctx.Repo.GitRepo.Path, + Not: not, + Revision: []string{sha}, + RelPath: []string{path}, + }) + if err != nil { ctx.Error(http.StatusInternalServerError, "FileCommitsCount", err) return @@ -205,7 +217,14 @@ func GetAllCommits(ctx *context.APIContext) { return } - commits, err = ctx.Repo.GitRepo.CommitsByFileAndRange(sha, path, listOptions.Page) + commits, err = ctx.Repo.GitRepo.CommitsByFileAndRange( + git.CommitsByFileAndRangeOptions{ + Revision: sha, + File: path, + Not: not, + Page: listOptions.Page, + }) + if err != nil { ctx.Error(http.StatusInternalServerError, "CommitsByFileAndRange", err) return diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go index 0b9a36ec47..e33790a378 100644 --- a/routers/api/v1/repo/wiki.go +++ b/routers/api/v1/repo/wiki.go @@ -429,7 +429,12 @@ func ListPageRevisions(ctx *context.APIContext) { } // get Commit Count - commitsHistory, err := wikiRepo.CommitsByFileAndRange("master", pageFilename, page) + commitsHistory, err := wikiRepo.CommitsByFileAndRange( + git.CommitsByFileAndRangeOptions{ + Revision: "master", + File: pageFilename, + Page: page, + }) if err != nil { ctx.Error(http.StatusInternalServerError, "CommitsByFileAndRange", err) return diff --git a/routers/web/feed/file.go b/routers/web/feed/file.go index 6a8d0c454d..56a9c54ddc 100644 --- a/routers/web/feed/file.go +++ b/routers/web/feed/file.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/util" "github.com/gorilla/feeds" @@ -21,7 +22,12 @@ func ShowFileFeed(ctx *context.Context, repo *repo.Repository, formatType string if len(fileName) == 0 { return } - commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(ctx.Repo.RefName, fileName, 1) + commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange( + git.CommitsByFileAndRangeOptions{ + Revision: ctx.Repo.RefName, + File: fileName, + Page: 1, + }) if err != nil { ctx.ServerError("ShowBranchFeed", err) return diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index 93294f8ddd..e88f1139f8 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -230,7 +230,12 @@ func FileHistory(ctx *context.Context) { page = 1 } - commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(ctx.Repo.RefName, fileName, page) + commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange( + git.CommitsByFileAndRangeOptions{ + Revision: ctx.Repo.RefName, + File: fileName, + Page: page, + }) if err != nil { ctx.ServerError("CommitsByFileAndRange", err) return diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go index 374d1bf2e0..a335c114be 100644 --- a/routers/web/repo/wiki.go +++ b/routers/web/repo/wiki.go @@ -376,7 +376,12 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) } // get Commit Count - commitsHistory, err := wikiRepo.CommitsByFileAndRange(wiki_service.DefaultBranch, pageFilename, page) + commitsHistory, err := wikiRepo.CommitsByFileAndRange( + git.CommitsByFileAndRangeOptions{ + Revision: wiki_service.DefaultBranch, + File: pageFilename, + Page: page, + }) if err != nil { if wikiRepo != nil { wikiRepo.Close() |